private static void ExamineAssembly(Assembly objDLL, string interfacename, ArrayList Plugins) { Type objInterface; AvailablePlugin Plugin; // Loop through each type in the DLL Type[] types = objDLL.GetTypes(); for (int i = 0; i < types.Length; i++) { // Only look at public types if (types[i].IsPublic) { // Ignore abstract classes if (types[i].Attributes != TypeAttributes.Abstract) { // See if this type implements our interface objInterface = types[i].GetInterface(interfacename, true); if (objInterface != null) { Plugin = new AvailablePlugin(); Plugin.AssemblyPath = objDLL.Location; Plugin.ClassName = types[i].FullName; Plugins.Add(Plugin); } } } } }
public static AvailablePlugin[] FindPlugins(string strPath, string strInterface) { ArrayList Plugins = new ArrayList(); string[] strDLLs = null; int intIndex = default(int); Assembly objDLL = default(Assembly); //Go through all DLLs in the directory, attempting to load them strDLLs = Directory.GetFileSystemEntries(strPath, "*.dll"); for (intIndex = 0; intIndex <= strDLLs.Length - 1; intIndex++) { try { objDLL = Assembly.LoadFrom(strDLLs[intIndex]); ExamineAssembly(objDLL, strInterface, Plugins); } catch (Exception) { //Error loading DLL, we don't need to do anything special } } //Return all plugins found AvailablePlugin[] Results = new AvailablePlugin[Plugins.Count - 1 + 1]; if (Plugins.Count != 0) { Plugins.CopyTo(Results); return Results; } else { return null; } }
public void PluginListSelectedIndexChanged(object sender, System.EventArgs e) { int selectedIndex = this.pluginList.SelectedIndex; AvailablePlugin plugin = (AvailablePlugin)this.plugins[selectedIndex]; this.pluginPropertyGrid.SelectedObject = plugin.Instance; }
private void OptionsChange(object sender, EventArgs e) { bool temp_checkbox1 = this.Graph1.checkbox1; this.Graph1.checkbox1 = options.general1.checkBox1.Checked; this.Graph1.checkbox2 = options.general1.checkBox2.Checked; this.Graph1.checkbox3 = options.general1.checkBox3.Checked; this.Graph1.checkbox4 = options.general1.checkBox4.Checked; this.Graph1.checkbox5 = options.general1.checkBox5.Checked; this.Graph1.timerInterval = options.general1.numericUpDown1.Value; if (temp_checkbox1 != this.Graph1.checkbox1) { if (this.Graph1.checkbox1) { this.Graph1.Radius = this.Graph1.RadiusVertex; } else { this.Graph1.Radius = this.Graph1.RadiusVertex - this.Graph1.radiusDifference; } } if (plug_name != null) { AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(pluglist.treeView1.SelectedNode.Text); if (selectedPlugin != null) { selectedPlugin.Instance.Radius = this.Graph1.Radius; selectedPlugin.Instance.pTimerInterval = this.Graph1.timerInterval; selectedPlugin.Instance.control_Initialize(); } } //Refresh(); }
public static AvailablePlugin[] FindAvailablePlugins(string directory, Type interfaceType) { var Plugins = new ArrayList(); string[] strDLLs; Assembly objDLL = null; // Go through all DLLsin the directory, attempting to load them strDLLs = Directory.GetFileSystemEntries(directory, "*.dll"); for (int i = 0; i < strDLLs.Length; i++) { try{ if (!FindAssembly(strDLLs[i], ref objDLL)) { objDLL = Assembly.LoadFrom(strDLLs[i]); } ExamineAssembly(objDLL, interfaceType.Name, Plugins); }catch (Exception ex) { // Error loading DLL } } // Return all plugins found AvailablePlugin[] Results = new AvailablePlugin[Plugins.Count]; if (Plugins.Count != 0) { Plugins.CopyTo(Results); return(Results); } else { return(null); } }
private static void ExamineAssembly(Assembly objDLL, string strInterface, List <AvailablePlugin> Plugins) { Type objInterface; AvailablePlugin Plugin; // Loop through each type in the DLL foreach (System.Type objType in objDLL.GetTypes()) { // Only look at public types if ((objType.IsPublic == true)) { // Ignore abstract classes if ((objType.Attributes & TypeAttributes.Abstract) != TypeAttributes.Abstract) { // See if this type implements our interface objInterface = objType.GetInterface(strInterface, true); if (!(objInterface == null)) { // It does Plugin = new AvailablePlugin(); Plugin.AssemblyPath = objDLL.Location; Plugin.ClassName = objType.FullName; Plugins.Add(Plugin); } } } } }
private void OnSelect(object sender, EventArgs e) { richTextBox1.Text = ""; if (checkedListBox1.SelectedItem == null) { return; } AvailablePlugin selPlugin = GlobalPlugins.Plugins.AvailablePlugins.Find(checkedListBox1.SelectedItem.ToString()); if (selPlugin == null) { return; } Font font = new Font(richTextBox1.Font.FontFamily, richTextBox1.Font.Size, FontStyle.Bold); richTextBox1.AppendText($"Name: {selPlugin.Instance.Name}\n"); richTextBox1.Select(0, 5); richTextBox1.SelectionFont = font; richTextBox1.AppendText($"Version: {selPlugin.Instance.Version}\n"); richTextBox1.Select(richTextBox1.Text.IndexOf("Version: ", StringComparison.Ordinal), 9); richTextBox1.SelectionFont = font; richTextBox1.AppendText($"Author: {selPlugin.Instance.Author}\n"); richTextBox1.Select(richTextBox1.Text.IndexOf("Author: ", StringComparison.Ordinal), 8); richTextBox1.SelectionFont = font; richTextBox1.AppendText($"Description:\n{selPlugin.Instance.Description}\n"); richTextBox1.Select(richTextBox1.Text.IndexOf("Description:", StringComparison.Ordinal), 12); richTextBox1.SelectionFont = font; }
private void tvwPlugins_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { //Make sure there's a selected Plugin if (this.tvwPlugins.SelectedNode == null) { return; } //Get the selected Plugin AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(tvwPlugins.SelectedNode.Text.ToString()); if (selectedPlugin == null) { return; } //If the plugin is found, do some work... //This part adds the plugin's info to the 'Plugin Information:' Frame this.lblPluginName.Text = selectedPlugin.Instance.Name; this.lblPluginVersion.Text = "(" + selectedPlugin.Instance.Version + ")"; this.lblPluginAuthor.Text = "By: " + selectedPlugin.Instance.Author; this.lblPluginDesc.Text = selectedPlugin.Instance.Description; //Clear the current panel of any other plugin controls... //Note: this only affects visuals.. doesn't close the instance of the plugin this.pnlPlugin.Controls.Clear(); //Set the dockstyle of the plugin to fill, to fill up the space provided selectedPlugin.Instance.MainInterface.Dock = DockStyle.Fill; //Finally, add the usercontrol to the panel... Tadah! this.pnlPlugin.Controls.Add(selectedPlugin.Instance.MainInterface); }
/// <summary> /// Pluginses the specified page. /// </summary> /// <param name="page">The page.</param> private void Plugins(Page page) { for (int i = 0; i < page.Containers.Count; i++) { for (int b = 0; b < page.Containers[i].Elements.Count; b++) { XmlNode xmlElementNode = page.Containers[i].Elements[b].Node; String plugin = CommonXml.GetNode(xmlElementNode, "plugin").InnerText; String action = CommonXml.GetNode(xmlElementNode, "action").InnerText; if (plugin != String.Empty & action != String.Empty) { String pathTrail = CommonXml.GetNode(xmlElementNode, "value").InnerText; AvailablePlugin availablePlugin = Process.Plugins.AvailablePlugins.Find(plugin); if (availablePlugin != null) { IPlugin2 plugin2 = availablePlugin.Instance as IPlugin2; if (plugin2 != null) { IPlugin2 iPlugin = availablePlugin.Instance as IPlugin2; iPlugin.Load(new ControlList(xmlElementNode), action, String.Empty, pathTrail); } else { IPlugin iPlugin = availablePlugin.Instance; iPlugin.Load(new ControlList(xmlElementNode), action, pathTrail); } } } } } }
public static AvailablePlugin[] FindPlugins(string strPath, string strInterface) { ArrayList Plugins = new ArrayList(); string[] strDLLs; int intIndex; Assembly objDLL; //Go through all DLLs in the directory, attempting to load them strDLLs = Directory.GetFileSystemEntries(strPath, "*.dll"); for (intIndex = 0; intIndex <= strDLLs.Length - 1; intIndex++) { try { objDLL = Assembly.LoadFrom(strDLLs[intIndex]); ExamineAssembly(objDLL, strInterface, Plugins); } catch (Exception e) { //Error loading DLL, we don't need to do anything special } } //Return all plugins found AvailablePlugin[] Results = new AvailablePlugin[Plugins.Count]; if (Plugins.Count != 0) { Plugins.CopyTo(Results); return(Results); } else { return(null); } }
private void AddPlugin(string fileName) { Assembly pluginAssembly = Assembly.LoadFrom(fileName); foreach (Type pluginType in pluginAssembly.GetTypes()) { if (!pluginType.IsPublic || pluginType.IsAbstract) { continue; } if (!pluginType.IsSubclassOf(typeof(PluginBase))) { continue; } AvailablePlugin newPlugin = new AvailablePlugin { AssemblyPath = fileName, Type = pluginAssembly.GetType(pluginType.ToString()) }; if (Options.PluginsToLoad.Contains(pluginType.ToString())) { newPlugin.CreateInstance(); newPlugin.Instance.Host = this; newPlugin.Instance.Initialize(); } AvailablePlugins.Add(newPlugin); //newPlugin = null; // TODO: to be removed? } //pluginAssembly = null; // TODO: to be removed? }
private void AddPlugin(string fileName) { Assembly pluginAssembly = Assembly.LoadFrom(fileName); foreach (Type pluginType in pluginAssembly.GetTypes()) { if (!pluginType.IsPublic || pluginType.IsAbstract) { continue; } if (!pluginType.IsSubclassOf(typeof(PluginBase))) { continue; } AvailablePlugin newPlugin = new AvailablePlugin { AssemblyPath = fileName, Type = pluginAssembly.GetType(pluginType.ToString()) }; if (Options.PluginsToLoad?.Contains(pluginType.ToString()) == true) { Options.Logger.Information("FindPlugins - AddPlugin of type: {type} from file: {fileName}", pluginType.ToString(), newPlugin.AssemblyPath); newPlugin.CreateInstance(); newPlugin.Instance.Host = this; newPlugin.Instance.Initialize(); } AvailablePlugins.Add(newPlugin); } }
private void treePlugins_AfterSelect(object sender, TreeViewEventArgs e) { selected = (AvailablePlugin <IIndicator>)e.Node.Tag; lblName.Text = selected.Instance.Name; txtAuthor.Text = selected.Instance.Author; txtDescription.Text = selected.Instance.Description; txtVersion.Text = selected.Instance.Version; }
private void AddPlugin(string FileName, 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("Portal.SiteSystem.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 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 = (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 this.colAvailablePlugins.Add(newPlugin); } //cleanup a bit newPlugin = null; } typeInterface = null; //Mr. Clean } } } pluginAssembly = null; //more cleanup }
private void MouseClickChange(object sender, MouseEventArgs e) { AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(plug_name); if (selectedPlugin != null) { selectedPlugin.Instance.control_MouseClick(this, e); } }
public static object CreateInstance(AvailablePlugin plugin) { Assembly objDLL; object objInstance; objDLL = Assembly.LoadFrom(plugin.AssemblyPath); objInstance = objDLL.CreateInstance(plugin.ClassName); return(objInstance); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(this.treeView1.SelectedNode.Text); if (selectedPlugin != null) { this.label1.Text = selectedPlugin.Instance.pDescription; } }
public void DoesContain() { var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); var plugins = new AvailablePluginCollection(); plugins.Add(ap); Assert.True(plugins.Contains(ap)); }
public void CanAdd() { var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); var plugins = new AvailablePluginCollection(); Assert.True(plugins.Add(ap) == 0); Assert.True(plugins.Count > 0); Assert.True(plugins.Add(ap) == -1); }
public void CanGetFromIndexer() { var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); var plugins = new AvailablePluginCollection(); plugins.Add(ap); Assert.True(plugins[0].Equals(ap)); }
public void CanGetIndex() { var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); var plugins = new AvailablePluginCollection(); plugins.Add(ap); Assert.True(plugins.IndexOf(ap) == 0); }
public void PopulatePluginsList() { this.pluginList.Items.Clear(); this.plugins = Global.Plugins.AvailablePlugins.GetAll(); for (int i = 0; i < this.plugins.Count; i++) { AvailablePlugin plugin = (AvailablePlugin)this.plugins[i]; this.pluginList.Items.Add(plugin.Instance.Name); } this.pluginList.SelectedIndex = 0; }
private void Initialize() { frmLogin login = new frmLogin(); if (login.ShowDialog() != DialogResult.OK) { this.Close(); return; } string result = ""; _userSession = login.Session; if (_appSettings == null) { _appSettings = new AppInfo(); } try { if (ConfigurationManager.AppSettings["DefaultDbConnection"] != null) { _appSettings.ActiveDbConnectionKey = ConfigurationManager.AppSettings["DefaultDbConnection"].ToString(); } _appSettings = ClientCore.Application.GetSettings(false, _appSettings.ActiveDbConnectionKey, _userSession.AuthToken); if (string.IsNullOrEmpty(_currentPlugin)) { result = LoadPlugins();//loads plugins in the treeview. } else { //if a specific plugin is passed in through command line, then only load that one. result = Global.Plugins.LoadPlugin(Application.StartupPath + @"\Plugins\" + _currentPlugin + ".dll", _userSession, _appSettings); lblStatus.Text = result; // if single plugin is loaded, pass args to plugin.. // AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(_currentPlugin); if (selectedPlugin != null) { TreeNode newNode = new TreeNode(selectedPlugin.Instance.ShortName); //show the plugin in the host list. this.tvwPlugins.Nodes.Add(newNode); } } }catch (Exception ex) { // todo add logging Debug.Assert(false, ex.Message); lblStatus.Text = ex.Message; return; } lblStatus.Text = result; }
private IPlugin GetProvider(string name) { AvailablePlugin plugin = Plugins.AvailablePlugins.Find(name); if (plugin != null) { return(plugin.Instance); } else { return(null); } }
public void CanCopyToArray() { var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); var plugins = new AvailablePluginCollection(); plugins.Add(ap); AvailablePlugin[] pluginArray = new AvailablePlugin[plugins.Count]; plugins.CopyTo(pluginArray, 0); Assert.True(pluginArray.Length == 1); }
private void mnuNewProject_Click(object sender, EventArgs e) { //TODO: GET THE name of the current selected plugin. //Then call function to display the project gui, // the plugin must have ability to clear the display etc. // this.pnlPlugin.Controls.Add( AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(tvwPlugins.SelectedNode.Text.ToString()); if (selectedPlugin != null) { //selectedPlugin.Instance.MainInterface } }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { ListViewItem lvi = listView1.SelectedItems[0]; AvailablePlugin plugin = (AvailablePlugin)lvi.Tag; this.model.Plugin = plugin.PluginType.FullName; } else { this.model.Plugin = ""; } }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPluginFramework.UI.FormPluginSettingsDialog"/> /// class with the plugin to load and the parent window. /// </summary> /// <param name="plugin"> /// The plugin to load info from. /// </param> /// <param name="parent"> /// The window that is the parent of this dialog. /// </param> public FormPluginSettingsDialog(AvailablePlugin plugin, Window parent) : base() { if (parent != null) { this.Parent = parent; } if (plugin != null) { this._name = plugin.Instance.Name; this._config = plugin.Instance.GetConfiguration(); Assembly asm = Assembly.ReflectionOnlyLoadFrom(plugin.AssemblyPath); this._asmName = asm.GetName().Name; } }
public void CanTestNullOrEmpty() { Assert.True(AvailablePluginCollection.IsNullOrEmpty(null)); var plugins = new AvailablePluginCollection(); Assert.True(AvailablePluginCollection.IsNullOrEmpty(plugins)); var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); plugins.Add(ap); Assert.False(AvailablePluginCollection.IsNullOrEmpty(plugins)); }
/// <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; foreach (AvailablePlugin pluginOn in List) { if (pluginOn.Instance.Name.Equals(pluginNameOrPath) || pluginOn.AssemblyPath.Equals(pluginNameOrPath)) { toReturn = pluginOn; break; } } return(toReturn); }
private void GraphChange(object sender, EventArgs e) { saved = 0; this.toolStripStatusLabel2.Text = "Вершин: " + dot.Count; this.toolStripStatusLabel3.Text = "Ребер: " + line.Count; AvailablePlugin selectedPlugin = Global.Plugins.AvailablePlugins.Find(plug_name); if (selectedPlugin != null) { selectedPlugin.Instance.pDot = dot; selectedPlugin.Instance.pLine = line; selectedPlugin.Instance.control_Initialize(); } }
public void CanRemove() { var tp = new TestPlugin(); var ap = new AvailablePlugin(tp, this.AssemblyPath); var plugins = new AvailablePluginCollection(); plugins.Add(ap); // So we should have 1 plugin in the collection. Assert.True(plugins.Count == 1); // Now remove it and verify that the count is zero. plugins.Remove(ap); Assert.True(plugins.Count == 0); }
public static object CreateInstance(AvailablePlugin Plugin) { Assembly objDLL; object objPlugin; try { // Load dll objDLL = Assembly.LoadFrom(Plugin.AssemblyPath); // Create and return class instance objPlugin = objDLL.CreateInstance(Plugin.ClassName); } catch { return null; } return objPlugin; }
private static void ExamineAssembly(Assembly objDLL, string strInterface, ArrayList Plugins) { Type objType = default(Type); Type objInterface = default(Type); AvailablePlugin Plugin = new AvailablePlugin(); //Loop through each type in the DLL foreach (Type tempLoopVar_objType in objDLL.GetTypes()) { objType = tempLoopVar_objType; //Only look at public types if (objType.IsPublic == true) { //Ignore abstract classes if (!(System.Convert.ToInt32((objType.Attributes & TypeAttributes.Abstract)) == (int) TypeAttributes.Abstract )) { //See if this type implements our interface objInterface = objType.GetInterface(strInterface, true); if (!(objInterface == null)) { //It does Plugin = new AvailablePlugin(); Plugin.AssemblyPath = objDLL.Location; Plugin.ClassName = objType.FullName; Plugins.Add(Plugin); } } } } }
private static void ExamineAssembly(Assembly objDLL, string strInterface, List<AvailablePlugin> Plugins) { Type objInterface; AvailablePlugin Plugin; // Loop through each type in the DLL foreach (System.Type objType in objDLL.GetTypes()) { // Only look at public types if ((objType.IsPublic == true)) { // Ignore abstract classes if ((objType.Attributes & TypeAttributes.Abstract) != TypeAttributes.Abstract) { // See if this type implements our interface objInterface = objType.GetInterface(strInterface, true); if (!(objInterface == null)) { // It does Plugin = new AvailablePlugin(); Plugin.AssemblyPath = objDLL.Location; Plugin.ClassName = objType.FullName; Plugins.Add(Plugin); } } } } }