private void insertNode(LACTreeNode rootnode) { int index = (int)rootnode.Tag; if (index == _pluginStandalonePage.pluginCombobox_selectedIndex) { //find the correct node to insert the added plug-ins if (_addedplugins.Count > 0) { foreach (LACTreeNode lacnode in _addedplugins) { Type t = lacnode.Plugin.GetType(); Assembly pluginDll = Assembly.GetAssembly(t); LACTreeNodeList nodesInAssembly = _controlManage.LoadPlugInsFromAssembly(pluginDll); foreach (LACTreeNode node in nodesInAssembly) { if (node.t.Namespace.Equals("Likewise.LMC.Plugins.GPOEPlugin", StringComparison.InvariantCultureIgnoreCase)) { node.Text = lacnode.Text; node.Tag = lacnode.Tag; } node.SetContext(lacnode.Plugin.GetContext()); node.Plugin.SetContext(lacnode.Plugin.GetContext()); //node.Plugin.SetContext(rootnode.Plugin.GetContext()); rootnode.Nodes.Add(node); rootnode.Plugin.AddExtPlugin(node.Plugin); if (_removedplugings.Contains(lacnode)) { _removedplugings.Remove(lacnode); _removedplugings.Add(node); } } } } return; } foreach (LACTreeNode n in rootnode.Nodes) { if (n.IsPluginNode) { insertNode(n); } } }
public AddPluginsDlg(AddRemovePluginDlg grandparentDlg, Manage controlManage, LACTreeNode rootNode, PluginStandalonePage standalonePage, ListView listView) { InitializeComponent(); this.Text = "Add Stand-Alone Plug-In"; _controlManage = controlManage; _rootNode = rootNode; _standalonePage = standalonePage; _grandParent = grandparentDlg; this.PluginslistView = listView; //fill in PluginListview with existing plug-ins Logger.Log("AddPluginsDlg constructor", Logger.manageLogLevel); string[] dllPathList = Directory.GetFiles(Application.StartupPath, "*.dll"); List <ListViewItem> liItems = new List <ListViewItem>(); ImageList il = new ImageList(); foreach (string dllPath in dllPathList) { if (Path.GetFileName(dllPath) == sRootPluginName) { continue; } try { Assembly pluginDll = Assembly.LoadFile(dllPath); LACTreeNodeList nodesInAssembly = _controlManage.LoadPlugInsFromAssembly(pluginDll); foreach (LACTreeNode node in nodesInAssembly) { ListViewItem lvi = new ListViewItem(node.Text); lvi.Tag = node; lvi.ImageIndex = node.ImageIndex; liItems.Add(lvi); } } catch (BadImageFormatException) { // // Ignore DLLs that are not managed code. // } catch (Exception e) { Debugger.Log(9, "Exception", e.ToString()); } } // sort the items liItems.Sort(this); // add to the list view ListViewItem[] lvItems = new ListViewItem[liItems.Count]; liItems.CopyTo(lvItems); PluginlistView.Items.AddRange(lvItems); if (PluginlistView.Items.Count > 0) { PluginlistView.Items[0].Selected = true; } }
public LACTreeNodeList LoadPlugInsFromAssembly(Assembly a) { Logger.Log(String.Format("Manage.LoadPlugInsFromAssembly(assembly: {0})", a == null ? "null" : a.FullName), Logger.manageLogLevel); LACTreeNodeList nodeList = new LACTreeNodeList(); try { Type[] atyp = a.GetTypes(); foreach (Type t in atyp) { if (t.GetInterface("Likewise.LMC.ServerControl.IPlugIn") != null) { IPlugIn pi = (IPlugIn)Activator.CreateInstance(t); // get its name pi.Initialize(this); if (pi.GetContextType() == IContextType.DbConninfo) { pi.SetContext(new DbConnInfo()); } else if (pi.GetContextType() == IContextType.Hostinfo) { pi.SetContext(new Hostinfo()); } LACTreeNode pluginNode = pi.GetPlugInNode(); if (pluginNode != null) { pluginNode.Text = pi.GetName(); pluginNode.Name = pi.GetName(); pluginNode.sc = this.sc; nodeList.Add(pluginNode); Logger.Log(String.Format("Manage.LoadPlugInsFromAssembly (plugin: {0}, iconID: {1})", pluginNode.Name, pluginNode.ImageIndex), Logger.manageLogLevel); } else { Logger.Log(String.Format("Manage.LoadPlugInsFromAssembly FAILED! (pluginNode == null) (plugin: {0})", pi.GetName()), Logger.manageLogLevel); } } } } catch (Exception e) { Debugger.Log(9, "Exception", e.ToString()); } return nodeList; }