/// <summary> /// Open form for given plugin /// </summary> /// <param name="rccm">Reference to RCCM object</param> /// <param name="plugin">Plugin to be started from this form</param> public PluginInitializationForm(RCCMSystem rccm, IRCCMPlugin plugin) { this.rccm = rccm; this.plugin = plugin; InitializeComponent(); // Add rows for each input and give them a fixed size this.tableLayoutPanelParams = new TableLayoutPanel(); this.tableLayoutPanelParams.Dock = DockStyle.Fill; this.tableLayoutPanelParams.ColumnCount = 2; this.tableLayoutPanelParams.RowCount = plugin.Params.Length; this.tableLayoutPanelGrid.Controls.Add(this.tableLayoutPanelParams, 0, 0); this.parameterControls = new Dictionary <string, TextBox>(); for (int i = 0; i < plugin.Params.Length; i++) { this.tableLayoutPanelParams.RowStyles.Add(new RowStyle(SizeType.Absolute, 30)); // Add label Label paramLabel = new Label(); paramLabel.Text = plugin.Params[i]; this.tableLayoutPanelParams.Controls.Add(paramLabel, 0, i); // Add control TextBox paramTextBox = new TextBox(); paramTextBox.Dock = DockStyle.Fill; this.tableLayoutPanelParams.Controls.Add(paramTextBox, 1, i); // Add textbox to dictionary of parameter controls parameterControls[plugin.Params[i]] = paramTextBox; } this.Text = plugin.Name; this.buttonStop.Enabled = false; this.Height = 80 + 32 * this.plugin.Params.Length; this.tableLayoutPanelGrid.RowStyles[0].Height = 32 * this.plugin.Params.Length; }
/// <summary> /// Load plugin dlls from specified path /// </summary> /// <param name="path">Path where program should search for plugin dlls</param> /// <returns>List of plugin interfaces</returns> public static ICollection <IRCCMPlugin> LoadPlugins(string path) { string[] dllFileNames = null; if (Directory.Exists(path + "\\")) { dllFileNames = Directory.GetFiles(path, "*.dll"); ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length); foreach (string dllFile in dllFileNames) { AssemblyName an = AssemblyName.GetAssemblyName(dllFile); Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } Type pluginType = typeof(IRCCMPlugin); ICollection <Type> pluginTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { if (type.GetInterface(pluginType.FullName) != null) { pluginTypes.Add(type); } } } } } ICollection <IRCCMPlugin> plugins = new List <IRCCMPlugin>(pluginTypes.Count); foreach (Type type in pluginTypes) { IRCCMPlugin plugin = (IRCCMPlugin)Activator.CreateInstance(type); plugins.Add(plugin); Console.WriteLine("Loaded plugin " + plugin.Name); Logger.Out("Loaded plugin " + plugin.Name); } return(plugins); } return(null); }
/// <summary> /// Open a form for initializing the specified plugin /// </summary> /// <param name="plugin">Plugin to initialize</param> private void PluginToolStripClick(IRCCMPlugin plugin) { PluginInitializationForm form = new PluginInitializationForm(this.rccm, plugin); form.Show(); }