示例#1
0
 //A Simple class to hold some info about our Available Plugins
 /// <summary>
 /// Add a Plugin to the collection of Available plugins
 /// </summary>
 /// <param name="pluginToAdd">The Plugin to Add</param>
 public void Add(AvailablePlugin pluginToAdd)
 {
     this.List.Add(pluginToAdd);
 }
示例#2
0
 /// <summary>
 /// Remove a Plugin to the collection of available plugins
 /// </summary>
 /// <param name="pluginToRemove">The Plugin to Remove</param>
 public void Remove(AvailablePlugin pluginToRemove)
 {
     this.List.Remove(pluginToRemove);
     pluginToRemove = null;
 }
示例#3
0
 private void @remove(AvailablePlugin pl)
 {
     AvailablePlugins.Remove(pl);
     pl = null;
 }
示例#4
0
        public void AddPlugin(string FileName)
        {
            //Create a new assembly from the plugin file we're adding..
            Console.WriteLine("PluginManager: Loading " + FileName);
            Assembly pluginAssembly = Assembly.LoadFrom(FileName);
            //Next we'll loop through all the Types found in the assembly
            if (pluginAssembly != null) {
                int itemcount = 0;
                int pluginsfound = 0;
                foreach (Type pluginType in pluginAssembly.GetTypes()) {
                    //Only look at public types
                    if (pluginType.IsPublic) {
                        //Only look at non-abstract types
                        if (!pluginType.IsAbstract) {
                            //Log.WriteLine(String.Format("PluginManager: Checking Type '{0}' from {1}", pluginType.Name, FileName))
                            itemcount += 1;
                            //Gets a type object of the interface we need the plugins to match
                            Type typeInterface = pluginType.GetInterface(StaticPluginInfo.IMenuPluginInterface, true);

                            //Make sure the interface we want to use actually exists
                            if ((typeInterface != null)) {
                                //Create a new available plugin since the type implements the IPlugin interface
                                AvailablePlugin newPlugin = new AvailablePlugin();

                                //Set the filename where we found it
                                newPlugin.AssemblyPath = FileName;

                                //Create a new instance and store the instance in the collection for later use
                                //We could change this later on to not load an instance.. we have 2 options
                                //1- Make one instance, and use it whenever we need it.. it's always there
                                //2- Don't make an instance, and instead make an instance whenever we use it, then close it
                                //For now we'll just make an instance of all the plugins
                                try {
                                    newPlugin.MenuItem = (IMenuPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                                    Console.WriteLine(string.Format("PluginManager: Type Match: '{0}' (from {2}) Implements '{1}'. Creating Plugin...", pluginType.Name, StaticPluginInfo.IMenuPluginInterface, FileName));
                                    pluginsfound += 1;
                                    //Add the new plugin to our collection here
                                    this.AvailablePlugins.Add(newPlugin);
                                    //Call the initialization sub of the plugin
                                    newPlugin.MenuItem.Initialize();
                                    GetMenuItemFromString(newPlugin.MenuItem.Path, newPlugin.MenuItem.Index, newPlugin.MenuItem.Item);
                                    //cleanup a bit
                                    newPlugin = null;
                                } catch (Exception ex) {
                                    newPlugin = null;
                                    Console.WriteLine("Error: " + ex.ToString());
                                    MessageBox.Show(string.Format("Error Loading Plugin \"{0}\": {1}", FileName, ex));
                                }
                            }
                            //Gets a type object of the interface we need the plugins to match
                            typeInterface = pluginType.GetInterface(StaticPluginInfo.IPluginInterface, true);

                            //Make sure the interface we want to use actually exists
                            if ((typeInterface != null)) {
                                //Create a new available plugin since the type implements the IPlugin interface
                                AvailablePlugin newPlugin = new AvailablePlugin();

                                //Set the filename where we found it
                                newPlugin.AssemblyPath = FileName;

                                //Create a new instance and store the instance in the collection for later use
                                //We could change this later on to not load an instance.. we have 2 options
                                //1- Make one instance, and use it whenever we need it.. it's always there
                                //2- Don't make an instance, and instead make an instance whenever we use it, then close it
                                //For now we'll just make an instance of all the plugins
                                try {
                                    newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                                    Console.WriteLine(string.Format("PluginManager: Type Match: '{0}' (from {2}) Implements '{1}'. Creating Plugin...", pluginType.Name, StaticPluginInfo.IMenuPluginInterface, FileName));
                                    pluginsfound += 1;
                                    //Add the new plugin to our collection here
                                    this.AvailablePlugins.Add(newPlugin);
                                    //Call the initialization sub of the plugin
                                    newPlugin.Instance.Initialize();
                                    //cleanup a bit
                                    newPlugin = null;
                                } catch (Exception ex) {
                                    newPlugin = null;
                                    Console.WriteLine("Error: " + ex.ToString());
                                    MessageBox.Show(string.Format("Error Loading Plugin \"{0}\": {1}", FileName, ex));
                                }
                            } else {
                            }
                            typeInterface = null;
                            // Clean up
                        }
                    }
                }
                Console.WriteLine(string.Format("Scanned {0} Items from {1}, {2} Plugins found.", itemcount, FileName, pluginsfound));
            }
            if (pluginAssembly == null) {
                throw new Exception("Empty Assembly!");
            }
            pluginAssembly = null;
            //more cleanup
        }
示例#5
0
 /// <summary>
 /// Reads a toolbar file and returns the properties as array (Name,Author,Version,Description,UpdateUrl)
 /// </summary>
 /// <returns>String array (Name,Author,Version,Description, UpdateUrl)</returns>
 /// <param name="FileName">Filename of the plugin</param>
 public string[] GetPluginInfo(string FileName, string InterfaceToFind)
 {
     if (Hashes.Contains(FileName)) {
         return (string[]) Hashes[FileName];
     }
     string[] ret = null;
     try {
         Assembly pluginAssembly = Assembly.LoadFrom(FileName);
         foreach (Type pluginType in pluginAssembly.GetTypes()) {
             if (pluginType.IsPublic) {
                 if (!pluginType.IsAbstract) {
                     Type typeInterface = pluginType.GetInterface(InterfaceToFind, true);
                     if ((typeInterface != null)) {
                         AvailablePlugin newPlugin = new AvailablePlugin();
                         newPlugin.AssemblyPath = FileName;
                         newPlugin.Instance = (NotepadX.Plugins.IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                         ret = new string[5];
                         ret[0] = newPlugin.Instance.Name;
                         ret[1] = newPlugin.Instance.Author;
                         ret[2] = newPlugin.Instance.Version;
                         ret[3] = newPlugin.Instance.Description;
                         ret[4] = newPlugin.Instance.UpdateUrl;
                         Hashes[FileName] = ret;
                         newPlugin.Instance = null;
                         newPlugin = null;
                     }
                     typeInterface = null;
                 }
             }
         }
         pluginAssembly = null;
     } catch (Exception) {
         ret = null;
     }
     return ret;
 }