public IPlugin this[string pluginNameOrPath]
 {
     get
     {
         AvailablePlugin plugin = AvailablePlugins.Find(pluginNameOrPath);
         return(plugin == null ? null : plugin.Instance);
     }
 }
        private void AddPlugin(string fileName, Process.Process process)
        {
            //Create a new assembly from the plugin file we're adding..
            Assembly pluginAssembly = Assembly.LoadFrom(fileName);

            //Next we'll loop through all the Types found in the assembly
            foreach (Type pluginType in pluginAssembly.GetTypes())
            {
                if (pluginType.IsPublic)        //Only look at public types
                {
                    if (!pluginType.IsAbstract) //Only look at non-abstract types
                    {
                        //Gets a type object of the interface we need the plugins to match
                        Type typeInterface = pluginType.GetInterface("Sharpcms.Library.Plugin.IPlugin", 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
                                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
                                Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()))
                            };

                            //Set the Plugin's host to this class which inherited IPluginHost
                            newPlugin.Instance.Host = this;

                            //Set the Plugin's process
                            newPlugin.Instance.Process = process;

                            //Call the initialization sub of the plugin
                            newPlugin.Instance.Initialize();

                            // Do not add the BasePlugin
                            if (!newPlugin.Instance.Name.StartsWith("BasePlugin"))
                            {
                                //Add the new plugin to our collection here
                                _colAvailablePlugins.Add(newPlugin);
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Finds a plugin in the available Plugins
        /// </summary>
        /// <param name="pluginNameOrPath">The name or File path of the plugin to find</param>
        /// <returns>Available Plugin, or null if the plugin is not found</returns>
        public AvailablePlugin Find(string pluginNameOrPath)
        {
            AvailablePlugin toReturn = null;

            //Loop through all the plugins
            foreach (AvailablePlugin pluginOn in List)
            {
                //Find the one with the matching name or filename
                if ((pluginOn.Instance.Name.Equals(pluginNameOrPath)) || pluginOn.AssemblyPath.Equals(pluginNameOrPath))
                {
                    toReturn = pluginOn;
                    break;
                }
            }

            return(toReturn);
        }
Beispiel #4
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)
 {
     List.Remove(pluginToRemove);
 }
Beispiel #5
0
        //A Simple Home-brew 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)
        {
            List.Add(pluginToAdd);
        }