/// <summary> /// Unloads and Closes pluginNameOrPath /// </summary> public void ClosePlugin(string pluginNameOrPath) { AvailablePlugin tmp = null; foreach (AvailablePlugin pluginOn in AvailablePlugins) { if (pluginOn.Instance.Name.ToLower().Equals(pluginNameOrPath.ToLower()) | pluginOn.AssemblyPath.ToLower().Equals(pluginNameOrPath.ToLower())) { pluginOn.Instance.Dispose(); pluginOn.Instance = null; tmp = pluginOn; break; // FIXED. IS CORRECT.: might not be correct. Was : Exit For } } if (tmp != null) { @remove(tmp); } }
/// <summary> /// Reads a toolbar file and returns the properties as array (Name,Author,Version,Description,DownloadURL) /// </summary> /// <returns>String array (Name,Author,Version,Description, DownloadURL)</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 = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); ret = new string[6]; ret[0] = newPlugin.Instance.Name; ret[1] = newPlugin.Instance.Author; ret[2] = newPlugin.Instance.Version; ret[3] = newPlugin.Instance.Description; ret[4] = newPlugin.Instance.DownloadURL; Hashes[FileName] = ret; newPlugin.Instance = null; newPlugin = null; } typeInterface = null; } } } pluginAssembly = null; } catch (Exception) { ret = null; } return(ret); }
/// <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; }
//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); }
private void @remove(AvailablePlugin pl) { AvailablePlugins.Remove(pl); pl = null; }
public void AddPlugin(string FileName) { try { //Create a new assembly from the plugin file we're adding.. Debug.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.PluginInterface, 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())); Debug.WriteLine(string.Format("PluginManager: Type Match: '{0}' (from {2}) Implements '{1}'. Creating Plugin...", pluginType.Name, StaticPluginInfo.PluginInterface, FileName)); pluginsfound += 1; //Add the new plugin to our collection here this.AvailablePlugins.Add(newPlugin); //Call initialization for the plugin newPlugin.Instance.Initialize(); GetControlFromString(newPlugin.Instance.MenuItemPath, newPlugin.Instance.Control); //cleanup a bit newPlugin = null; } catch (Exception ex) { newPlugin = null; Debug.WriteLine("Error: " + ex.ToString()); MessageBox.Show(string.Format("Error Loading Plugin \"{0}\": {1}", FileName, ex)); try { System.IO.File.Delete(FileName); } catch (Exception ) { } } } else { } typeInterface = null; // Clean up } } } Debug.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 } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
/// <summary> /// Reads a toolbar file and returns the properties as array (Name,Author,Version,Description,DownloadURL) /// </summary> /// <returns>String array (Name,Author,Version,Description, DownloadURL)</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 = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); ret = new string[6]; ret[0] = newPlugin.Instance.Name; ret[1] = newPlugin.Instance.Author; ret[2] = newPlugin.Instance.Version; ret[3] = newPlugin.Instance.Description; ret[4] = newPlugin.Instance.DownloadURL; Hashes[FileName] = ret; newPlugin.Instance = null; newPlugin = null; } typeInterface = null; } } } pluginAssembly = null; } catch (Exception ) { ret = null; } return ret; }
public void AddPlugin(string FileName) { try { //Create a new assembly from the plugin file we're adding.. Debug.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.PluginInterface, 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())); Debug.WriteLine(string.Format("PluginManager: Type Match: '{0}' (from {2}) Implements '{1}'. Creating Plugin...", pluginType.Name, StaticPluginInfo.PluginInterface, FileName)); pluginsfound += 1; //Add the new plugin to our collection here this.AvailablePlugins.Add(newPlugin); //Call initialization for the plugin newPlugin.Instance.Initialize(); GetControlFromString(newPlugin.Instance.MenuItemPath, newPlugin.Instance.Control); //cleanup a bit newPlugin = null; } catch (Exception ex) { newPlugin = null; Debug.WriteLine("Error: " + ex.ToString()); MessageBox.Show(string.Format("Error Loading Plugin \"{0}\": {1}", FileName, ex)); try { System.IO.File.Delete(FileName); } catch (Exception) { } } } else { } typeInterface = null; // Clean up } } } Debug.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 } catch (Exception e) { Debug.WriteLine(e.ToString()); } }