Discuss the design of plug-in GIS framework and plug-in gis framework

Source: Internet
Author: User

Discuss the design of plug-in GIS framework and plug-in gis framework

Three years ago, I bought a GIS plug-in framework book from Jiang potao, as recommended by my senior brother. At that time, while reading a book, I made a complete implementation of the examples, which benefited a lot. Later, a plug-in C/S system was developed for the project, using the MEF framework provided by Microsoft. In this system, communication between plug-ins and plug-ins not involved in Jiang potao's book has been completed. However, Jiang potao's book involves a lot of underlying content of the plug-in system. The design of the plug-in engine is particularly worth learning. Recently, I have summarized my example and shared it with you.

1. Plug-in framework composition

(1). The framework is divided into two parts: Host Program and plug-in object.

(2). Two-part interaction is based on a public communication contract

(3) The host program can exist independently.

2. Reasons for using the plug-in

(1). extend the functions of the program without re-Compiling and publishing the program.

(2). New functions can be added to the program without the need for source code.

(3) flexible adaptation to the changing business logic of a program and frequent addition of new rules

3. General Implementation Technology of plug-ins

(1). Plug-In Based on Dynamic Link Library DLL

(2). COM-based plug-ins

(3) Reflection-based plug-ins

4. elaborate on the implementation of this framework. 4. 1. design all and implement some interfaces.

Interfaces are divided:

Host interface: IApplicaiton

Plug-in Interface: IPlugin (ICommand, Itool, IMenuDef, IToolBarDef, IDockableWindowDef) and IItemDef not inherited from Ipluging

In this chapter, the Application inherited from IApplication and the ItemDef class inherited from ItemDef are implemented. The class diagram is as follows:

 

 

 

 

 

4.2 create a plug-in Container

When the instantiated plug-ins are not added to the host, a host hosting these instantiated plug-ins is required.

Therefore, we have to design a plug-in container after designing the plug-in interface. This container can only store classes inherited from Iplugin.

4.2.1 design PluginCollection

First:

Inherits the abstract class CollectionBase.

CollectionBase has implemented three interfaces, including Ilist, Icolloction, and Ienumerable, to solve most of the problems.

(The main focus is to overwrite a new GetEnumerator () method, and this method returns a class that implements the IEnumerator interface. if yield has been used to implement the iteration function when rewriting this method, you can skip the Second Step ).

Then:

Write the class that inherits and implements the IEnumerator interface. (Rewrite the Current, MoveNext, and Reset functions)

4.3 design the reflection mechanism in PluginEngine

We have designed communication interfaces and interface containers. Why can't a plug-in be identified only when one of these interfaces is implemented?

Because our interface engine can only identify these interfaces.

What is an interface engine?

To put it simply, in this system, the interfaces of each TYPE obtained after reflection must be the interfaces defined above before they can be recognized and responded.

 

4.3.1 detailed dynamic loading and object generation

Reflection mechanism is the core technology of our plug-in system.

It enables these classes to be dynamically loaded and called.

(1) the system first uses the Directory. GetFiles () function to obtain all DLL files in the target folder.

(2). Use the reflection function Assemly. LoadFrom to load the file (several assemblies are obtained ). Use GetTypes () of the Assembly to obtain the Type [] array.

(3) Finally, use GetInterfaces () of the Type class to obtain the interface inherited by each class. Use switch to check whether the class inherits the custom interfaces. If so, use the Activator. CreateInstance (Type _ type) method to instantiate this class. Add it to the plug-in container PluginCollection.

 

4.4 plugin Classification

Set five interface dictionary containers, including ICommand, ITool, IToolBarDef, IMenuDef, five containers of IDockableWindowDef and one command-type container (which will store non-repeated Category that implements ICommand and ITool ).

Note: The Key values in these containers are the names of the plug-ins that implement these interfaces.

 

4.5 establish a host framework

Use the third-party control Janus WinForms Controls V3.5 to design the interface.

The third-party control has two controls: UICommandManager and UIPanelManager, which are helpful for plug-in insertion and display.

 

When this host is instantiated, an Apllication class is first instantiated, and then an important attribute value is assigned to MapControl, PageControl, and MainPlantform in this instance.

Therefore, the interaction between the host and the plug-in is not difficult to implement through the copied instance.

4.6 plugin acquisition

This is a big aspect and also the core. That is, how can we make the host get the plug-ins that are still in the plug-in container and can be displayed in the host?

1. Because Command and Tool are of the same type on the UI, they are obtained together.

There are two points to note: one is to make the instance Create (hook), that is, to pass the relevant information class Application of the host. The second is to register a system-defined event. For example, UICommand + = new CommandEventHandler (UICommand_Click );

2. Similarly, you can obtain the objects that inherit IMenuDef, IToolBarDef, and IDockableWindowDef.

Note: floating forms are hosted by UIPanelManager. That is, add the ChildHWND (Control class) in the floating box to panelContainer. Controls in the new panel.

4.7 event handling of plug-in objects

In the previous step, we registered an undefined event handling method to the Click event through the built-in delegate.

In this section, we will write the event processing method in detail. Command is interactive, and Tool is not interactive. So there is a big difference in writing.

The two processing functions share two Key points: one is to use e. Command. Key of e (CommandEventArgs class) to obtain the objects placed in the relevant plug-in dictionary container. The second is to trigger the Click function of the object.

4.8 framework plug-in Design

 

This section is where the system can be expanded in the future.

Here we focus on the implementation of the cAddData plug-in.

This class first inherits the Icommand interface. In the create (Iapplication hook) method triggered by loading the host form to obtain various plug-ins, call the ControlsAddDataCommandClass () class that comes with Engine, and hook it to the MapControl of the passed host.

 

4.9 advanced design of the Host Program

You can perform some advanced design on the host program itself. For example, mapControl and PageControl are displayed in association. For example, you can define a floating menu of TocControl or query and display of development element data.

Note: These designs are designed for the host itself and have nothing to do with the plug-in. Is to maximize the use of the host form itself.

4.10 framework auxiliary component framework Library Design

This section is designed for a more convenient development framework or its plug-in itself.

In this section, you can write and encapsulate many methods that may be used in the future, and then call them directly after development.

This part can be called the system development kit (SDK), but this part is not necessary.

4.11 system release

When releasing a system, you must first determine which basic platforms are required to run the system on an empty machine.

When the System is running, at least the. NET 3.0 Framework redistributable package, Janus System UI V3.5, and ArcGIS Engine10 Runtime

Then, use InstallShield Express X to package.

5. Result Display

 

6. Advantages and disadvantages of this framework and its prospect: 6.1 advantages

This framework is purely developed at the underlying layer, with good portability and versatility. It has other characteristics of General plug-ins, such as scalability and decoupling. In line with the programming philosophy of interface-oriented and dependency inversion, this framework also integrates the command mode, observer mode, traversal mode, appearance mode, and Singleton mode.

6.2 weaknesses

The granularity of this framework is too small, which can easily lead to explosive growth of classes.

This framework only implements communication between the plug-in and the host, but does not implement communication between the plug-in and the plug-in.

6.3 Outlook

To resolve the communication between a plug-in and a plug-in, you can create a separate plug-in for complex communication. Other plug-ins reference this plug-in. With the observer mode, after loading the plug-in the host, you can implement event registration and communication between plug-ins.

At the same time, many frameworks have implemented plug-in programming ideas. Billy uses Spring dependency injection and all the MEF dependency injection provided by Microsoft to implement the plug-in system.


Design and Implementation of plug-in gis application framework

Sent! Please check it!

Hello, how are you? Have you read the design and implementation of plug-in gis application framework-Based on C # And ArcGIS Engine92?

You can contact Jiang potao or 3Snews on Weibo to directly contact the author.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.