After experiencing the confused and depressed, today, I finally understood how ADIN this stuff is used. Here are the process of our research. I hope that after you have seen my document, studying what addin is no longer so painful. And you can understand how the plug-in tree is running faster. Ok, there is not much nonsense, and the following is the right.
Addin as the core components of SharpDevelop, which provide a plug-in tree to call the plugin to make up the entire application. I will separate the core code of Addin from SharpDevelop and then as a separate project.
All processes are about two parts:
1. Separate Addin code from SharpDevelop.
Second, create a new project as a main program that calls the plug-in tree.
Third, create a plugin for program calls.
The first part separates the core code of the plug-in tree
So first, how to export the Core project from SharpDevelop to 2003
1. We must export the code first, you must get its source code, the source code can be downloaded at http://www.icsharpcode.com/opxource/sd/download/opp://www.icsharpcode.com/opxource/sd/download/.
2. After downloading the program, you can find Core.prjx in the src / main / core directory (this file is the project file of SharpDevelop), open this file using SharpDevelop, this time the entire Core project is loaded into SharpDevelop (Core) For the core project of the entire SharpDevelop, including plug-in trees, services and properties). Since SharpDevelop currently does not have .Net2003, we export the program to the .NET2003 format can via SharpDevelop's File - Output Engine - "Select the folder you want to output" to export the entire project.
3. After the output is successful, use the .NET2003 to load the solution that just output, then compile, so you can find the file in the bin / debug directory in the output directory (this file is the core component of the entire plugin tree) All of the components referenced in the rear plug-in tree applications).
4. Copy the corekey.key this file to the current project directory.
After the above three steps, the entire addin code is separated from the SharpDevelop code, is it very simple, ^ _ ^.
The second part builds a new project to use the plug-in tree mechanism to load the plug-in
The first part we explained how to separate the core code of the plug-in tree, this section I will explain how to load the plugin in the application of the plug-in tree.
1. First create a new Windows application AddInmain.
2. Delete Form1 in the new project just then add a class addinsmain.
3. Reference ICSharpcode.core.dll components (see the first part to get this component).
4. When the above three steps are completed, the coding is started, and the following code is copy to the addinsmain class.
/ ************************************************** *******************
* *
* AddinsMain Runs the main program of the plugin tree *
* Vincen *
* Vincen@vip.sina.com **
2004-11-28 *
*********************************************************** ****************** /
Using system;
Using system.io;
Using system.diagnostics;
Using system.reflection;
Using system.drawing;
Using system.collections;
Using system.windows.forms;
Using System.Resources;
USING SYSTEM.XML;
Using system.threading;
Using system.runtime.remoting;
Using system.security.policy;
/ / Reference Core's namespace
Using ICsharpcode.core.properties;
Using ICSharpcode.core.Addins.codons;
Using ICSHARPCODE.CORE.ADDINS;
Using ICSHARPCODE.CORE.SERVICES;
Namespace AddInmain
{
///
/// addinsmain's summary description.
/// summary>
Public Class Addinsmain
{
Public addinsmain ()
{
//
// TODO: Add constructor logic here
//
}
///
/// Entrance point of the entire program
/// summary>
[Stathread ()]
Public static void main (string [] args)
{
/ / Find the home directory of Addin By default, the directory is the current directory ../addin/
Bool ignoredefaultpath = false;
String [] addIndirs = addinsettingshandler.getaddIndirectories (Out IgnoreDefaultPath);
AddintReesingleton.SetaddIndirectories (AddindIRS, IGNOREDEFAULTPATH);
ArrayList Commands = NULL;
Try
{
// Start the default system service
ServiceManager.Services.AddService (new resource ());
// Start the background service
ServiceManager.Services.InitializeservicesUBSystem ("/ Workspace / Services");
// Plugin loaded first when the program starts running
Commands = addintreesingleton.addintree.gettreenode ("/ Workspace / AutoStart"). BuildChildItems (NULL);
For (int i = 0; i { (ICommand) Commands [i]). Run (); } } Catch (XMLException E) { Messagebox.show ("You cannot load XML:" Environment.newline E.MESSAGE); Return; } Catch (Exception E) { Messagebox.show ("Load error:" Environment.newline E.toString ()); Return; } } } } Here is to explain this code. Bool ignoredefaultpath = false; String [] addIndirs = addinsettingshandler.getaddIndirectories (Out IgnoreDefaultPath); AddintReesingleton.SetaddIndirectories (AddindIRS, IGNOREDEFAULTPATH); This code means looking for the path to the plug-in tree profile, which first calls the addInSettingsHandler.GetDIndirectories () method (AddInSettingsHandler class in later introduction) Find this in app.config, if this does not exist in the configuration file Any null value is returned. When calling the AddINTreSingleton.SetAddIndirectories (AddIndIrs, IgnoreDefaultPath), if addINDIR is empty, the default path for the plug-in tree configuration file is ../addin/. ServiceManager.Services.AddService (new resource ()); After finding the plug-in tree configuration file path, first start a default resource service resource (the service is the default service of the system, you must start, otherwise the program will not be able to run). ServiceManager.Services.InitializeservicesUBSystem ("/ Workspace / Services"); Start the custom service after starting the default service of the program. All default services are in the configuration file / Workspace / Services extension point. Commands = addintreesingleton.addintree.gettreenode ("/ Workspace / AutoStart"). BuildChildItems (NULL); For (int i = 0; i { (ICommand) Commands [i]). Run (); } This code is to load the front desktap when the program starts, / workspace / autostart is the extension path of the system automatically run commands, defining the plugin under this path automatically runs when the system is started. 5. After the above steps, the plug-in can be loaded, but the program does not compile this time, and should be added for our Resource class and the AddInSettingShandler class. Below we first add AddSettingShandler class, which is a plug-in tree control class. code show as below: / ************************************************** ****************** * * * AddSettingShandler plugin tree control class * * Vincen ** vincen@vip.sina.com * * 2004-11-28 * * * *********************************************************** ****************** / Using system; Using system.configuration; Using system.collections; USING SYSTEM.XML; Namespace AddInmain { /// /// addinsettingshandler's summary description. /// summary> Public class addinsettingshandler: System.configuration.iconfigurationSectionHandler { Public addinsettingshandler () { } Public Object Create (Object Parent, Object ConfigContext, System.xml.xmlNode Section) { ArrayList AddIndirectories = new arraylist (); XMLNode Attr = Section.attributes.getnamedItem ("IgnoreDefaultPath); IF (attr! = null) { Try { AddIndirectories.Add (Convert.TOBOOLEAN (Attr.Value); } Catch (InvalidCastexception) { AddIndirectories.Add (False); } } Else { AddIndirectories.Add (False); } Xmlnodelist addIndirlist = section.selectnodes ("addindirectory"); Foreach (XMLnode AddIndir in AddIndirlist) { XMLnode path = addIndir.attributes.getnamedItem ("path"); IF (PATH! = NULL) { AddIndirectories.Add (path.value); } } Return AddIndindirector; } Public static string [] getaddindirectories (Out Bool IgnoreDefaultPath) { ArrayList AddIndirs = System.configuration.configurationSettingS.GetConfig ("AddIndirectories") as arraylist; if (addIndirs! = Null) { INT count = addIndirs.count; IF (count <= 1) { IgnoreDefaultPath = false; Return NULL; } IgnoreDefaultPath = (BOOL) AddIndirs [0]; String [] Directories = New String [count-1]; For (int i = 0; i { Directories [I] = addIndirs [i 1] as string; } Return Directories; } IgnoreDefaultPath = false; Return NULL; } } } After adding the AddInSettingsHandler class, we will add a resource service class. First add an AddInStingsHandler class in the project, then Copy The following code is in this class, which inherits the AbstractService class and implements the IResourceService interface. Using system; Using system.io; Using system.windows.forms; Using system.collections; Using system.threading; Using System.Resources; Using system.drawing; Using system.diagnostics; Using system.reflection; USING SYSTEM.XML; Using ICsharpcode.core.properties; Using ICSharpcode.core.Addins.codons; Using ICSHARPCODE.CORE.ADDINS; Using ICSHARPCODE.CORE.SERVICES; Namespace AddInmain { /// /// resource's summary description. /// summary> Public Class Resource: AbstractService, IResourceService { Public resource () { // // TODO: Add constructor logic here // } #Region IResourceService member Public void registerassembly (askSEMBLY Assembly) { // Todo: Add resource.registeraSsembly implementation } Public String getString (String Name) { // Todo: Add resource.getstring implementation Return NULL; } #ndregion } } After completing the above steps, how about the compiler, is it compiled? Hey! Write a tired, draw the smoke! The third part has newly built a plugin After the first part and the second part, the new plugin will be created to addMain. 1. Add a class library project HelloWorld in just now. 2. Create a new form FORM1 in the HelloWorld project. 3. Create a class HelloWorldCommand, which is used as a reflection to call the HelloWorld form, the code is as follows: use system; Using system.windows.forms; Using system.codedom.compiler; Using ICSHARPCODE.CORE.ADDINS; Using ICSharpcode.core.Addins.codons; Namespace HelloWorld { /// /// HelloFormCommand's summary description. /// summary> Public class helloformcommand: Icsharpcode.core.Addins.codons.icommand { Public HelloformCommand () { // // TODO: Add constructor logic here // } #Region iCommand member Public Object Owner { get { // Todo: Add HelloformCommand.Owner getter implementation Return NULL; } set { // Todo: Add HelloformCommand.Owner Setter implementation } } Public void Run () { // Todo: Add HelloformCommand.run implementation Application.run (New Form1 ()); } #ndregion } } This class implements the icsharpcode.core.addins.codons.icommand interface. Public void Run () { // Todo: Add HelloformCommand.run implementation Application.run (New Form1 ()); } The most important thing in this is the RUN method, running our new FORM1 form in this method. Ok, at this time, we only failed the last 100 meters from the last 100 meters, it was the configuration file of the plug-in tree. Just, we have said that the default path of the plug-in tree is ../addins/ directory, then we build a Hello. Addin file in this directory, let's explain the format of the file. Author = "simonliu" Copyright = "GPL" URL = "http://www.icsharpcode.net" Description = "Display addintree" Version = "1.0.0"> Runtime> Class = "HelloWorld.HelloformCommand" /> Extension> Addin> In the configuration file, the Runtime section specifies the specific path of the library file helloWorld.dll in the plug-in function module, specifies the extension point path / Workspace / Autostart in the Extension section (this path is automatically running the plugin when the program is running) , Then specify its ID, Command class name in Extension. Save this configuration file running program, is Form1 out, huh, it is very simple. to sum up After my "nonsense", I would like to be able to read it, but I finally got the last few words, reviewing the whole process, first we split the core code of Addin from SharpDevelop, and then build a main project to use Addin The mechanism calls the plugin, and finally we have built a plugin and then call it. For convenience, I just made a simplest sample program here, of course, everyone can expand this sample program. As for how to hang all the plug-in to a main interface like SharpDevelop, I am studying ING ..., and then puts the experience of the study immediately, so stay tuned. Vincen 2004-11-28 2004-11-28