Пример #1
0
 /// <summary>
 ///     Add a Plugin to the collection of Available plugins
 /// </summary>
 /// <param name="pluginToAdd">The Plugin to Add</param>
 public void Add(AvailableHookPlugin pluginToAdd)
 {
     var currentGuid = pluginToAdd.Instance.Guid;
     if (!_guidCache.Contains(currentGuid))
     {
         List.Add(pluginToAdd);
         _guidCache.Add(currentGuid);
     }
 }
Пример #2
0
        public void LoadPlugin(string fileName)
        {
            //Create a new assembly from the plugin file we're adding..
            var pluginAssembly = Assembly.LoadFrom(fileName);
            //Next we'll loop through all the Types found in the assembly
            foreach (var 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("FireHTTP.PluginCore.IFireHTTPPlugin", true);
                        var containsInterface = typeof(IFireHTTPPlugin).IsAssignableFrom(pluginType);
                        //Make sure the interface we want to use actually exists
                        //if (typeInterface != null)
                        if (containsInterface)
                        {
                            //Create a new available plugin since the type implements the IPlugin interface
                            var newPlugin = new AvailableHookPlugin();

                            //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
                            newPlugin.Instance =
                                (IFireHTTPPlugin)
                                    Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));

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

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

                            //Add the new plugin to our collection here
                            AvailableHookPlugins.Add(newPlugin);

                            //cleanup a bit
                            newPlugin = null;
                        }

                        //typeInterface = null; //Mr. Clean
                    }
                }
            }

            pluginAssembly = null; //more cleanup
        }
Пример #3
0
 /// <summary>
 ///     Remove a Plugin to the collection of Available plugins
 /// </summary>
 /// <param name="pluginToRemove">The Plugin to Remove</param>
 public void Remove(AvailableHookPlugin pluginToRemove)
 {
     List.Remove(pluginToRemove);
 }