public static PluginRunContext Parse(PluginConfigItem configItem, IPluginContext context) { string runContext = configItem.RunContext; if (string.IsNullOrEmpty(runContext)) runContext = MainThread; // on the same current thread if (runContext == MainThread) { if (!Contexts.ContainsKey(runContext)) Contexts[runContext] = new PluginRunContext(configItem, context); } else if (runContext == NewThread) { if (!Contexts.ContainsKey(runContext)) // get a new thread Contexts[runContext] = new MultiThreadPluginRunContext(configItem, context); } else if (runContext == NewProcess) { if (!Contexts.ContainsKey(runContext)) // get a new process Contexts[runContext] = new MultiProcessPluginRunContext(configItem, context); } else if (runContext == NewAppDomain) { if (!Contexts.ContainsKey(runContext)) // get a new AppDomain Contexts[runContext] = new MultiAppDomainPuginRunContext(configItem, context); } Contexts[runContext].ConfigItem = configItem; Contexts[runContext].Context = context; configItem.PluginRunContext = Contexts[runContext]; return Contexts[runContext]; }
private void LoadIntoNavigation(List <PluginConfigItem> plugins) { for (int i = 0; i < plugins.Count; i++) { PluginConfigItem theItem = plugins[i]; try { if (theItem.Status == PluginConfigItemStatus.OK) { this._pluginContext.PluginContainer.AddConnectionPointItem(theItem, ExecutePlugin ); } else { LogUtils.LogError(new Exception(theItem.Status.ToString())); } } catch (Exception ex) { LogUtils.LogError(ex); theItem.Status = PluginConfigItemStatus.LoadPluginIntoNavigationFailure; } } }
public PluginClosingEventArgs(IPlugin thePlugin, PluginConfigItem thePluginConfig, string closingReason, bool cancel) { Plugin = thePlugin; PluginConfig = thePluginConfig; ClosingReason = closingReason; Cancel = cancel; }
public void ParsePluginByContainer(ConnectionPointContainer container) { XmlNodeList pluginNodeList = GetPluginNodeList(container); if (pluginNodeList == null || pluginNodeList.Count == 0) { return; } if (!PluginList.ContainsKey(container.Name)) { PluginList.Add(container.Name, new List <PluginConfigItem>()); } List <PluginConfigItem> containerPluginList = PluginList[container.Name]; foreach (XmlNode node in pluginNodeList) { PluginConfigItem foundItem = null; string url = ParsePluginUrl(node); foundItem = GetPluginByUrl(containerPluginList, url); if (foundItem == null) { containerPluginList.Add( ParsePluginConfigItem(node) ); } } }
public ThreadRun(PluginConfigItem ConfigItem, IPluginContext Context, AutoResetEvent theSignal, Dictionary <string, IPlugin> plugins, MultiThreadPluginRunContext parent) { this.ConfigItem = ConfigItem; this.Context = Context; this.theSignal = theSignal; this.thePlugins = plugins; this.parent = parent; }
public override void AddIntoMenu(ConnectionPointContainer container, PluginConfigItem theItem, PluginMenuPath thePath, ExecutePluginCallback callback) { if (container.Navigations != null && container.Navigations.Count > 0) { TreeView theTree = SelectNavigation(container, thePath); if (theTree != null) { AddTreeNodeIntoTree(container, theTree.Nodes, theItem, thePath, thePath.MenuPathParts, callback); } } }
public override void AddIntoMenu(ConnectionPointContainer container, PluginConfigItem theItem, PluginMenuPath thePath, ExecutePluginCallback callback) { if (container.ToolStrips != null && container.ToolStrips.Count > 0) { ToolBar theToolbar = SelectToolStrip(container, thePath); if (theToolbar != null) { AddMenuItemIntoMenu(container, theToolbar.Items, theItem, thePath, thePath.MenuPathParts, callback); } } }
public override void AddIntoMenu(ConnectionPointContainer container, PluginConfigItem theItem, PluginMenuPath thePath, ExecutePluginCallback callback) { if (container.ToolStrips != null && container.ToolStrips.Count > 0) { ToolStrip theToolbar = SelectToolStrip(container, thePath); if (theToolbar != null) { AddMenuItemIntoMenu(container, theToolbar.Items, theItem, thePath, thePath.MenuPathParts, callback); } } }
public static PluginConfigItem GetPluginConfigItem(IPluginContext context, string url) { PluginConfigItem theItem = PluginConfigParser.GetPluginByUrl( PluginConfigParser.GetCachePluginList()[context.PluginContainer.Name], url ); if (theItem != null) { return(theItem); } throw new ArgumentOutOfRangeException(); }
public void ExecutePlugin(string pluginUrl) { Debug.Assert(pluginUrl != null); PluginConfigItem configItem = PluginConfigParser.GetPluginByUrl( PluginList[this._pluginContext.PluginContainer.Name], pluginUrl ); if (configItem == null) { LogUtils.LogError("GetPluginByUrl Error." + pluginUrl, new ArgumentOutOfRangeException()); return; } ExecutePlugin(configItem); }
public static PluginConfigItem GetPluginByUrl(List <PluginConfigItem> containerPluginList, string url) { PluginConfigItem foundItem = null; foreach (PluginConfigItem theItem in containerPluginList) { if (theItem.Url == url) { foundItem = theItem; break; } } return(foundItem); }
public override void AddIntoMenu(ConnectionPointContainer container, PluginConfigItem theItem, PluginMenuPath thePath, ExecutePluginCallback callback) { if (null != container.Menus && container.Menus.Count > 0) { Menu menu = SelectMenu(container, thePath); if (null != menu) { AddMenuItemIntoMenu(container, menu.Items, theItem, thePath, thePath.MenuPathParts, callback); } } }
public void AddConnectionPointItem(PluginConfigItem theItem, ExecutePluginCallback callback) { if (_proxy != null) { _proxy.AddConnectionPointItem(theItem, callback); return; } foreach (PluginMenuPath thePath in theItem.MenuPaths) { PluginMenuBuilder.MakeBuilder(thePath.LocateType).AddIntoMenu( this, theItem, thePath, callback ); } }
public static PluginRunContext Parse(PluginConfigItem configItem, IPluginContext context) { string runContext = configItem.RunContext; if (string.IsNullOrEmpty(runContext)) { runContext = MainThread; } // on the same current thread if (runContext == MainThread) { if (!Contexts.ContainsKey(runContext)) { Contexts[runContext] = new PluginRunContext(configItem, context); } } else if (runContext == NewThread) { if (!Contexts.ContainsKey(runContext)) { // get a new thread Contexts[runContext] = new MultiThreadPluginRunContext(configItem, context); } } else if (runContext == NewProcess) { if (!Contexts.ContainsKey(runContext)) { // get a new process Contexts[runContext] = new MultiProcessPluginRunContext(configItem, context); } } else if (runContext == NewAppDomain) { if (!Contexts.ContainsKey(runContext)) { // get a new AppDomain Contexts[runContext] = new MultiAppDomainPuginRunContext(configItem, context); } } Contexts[runContext].ConfigItem = configItem; Contexts[runContext].Context = context; configItem.PluginRunContext = Contexts[runContext]; return(Contexts[runContext]); }
protected void AddTreeNodeIntoTree(ConnectionPointContainer container, TreeNodeCollection nodes, PluginConfigItem theItem, PluginMenuPath thePath, IList<PluginMenuItemPart> thePaths, ExecutePluginCallback callback) { if (thePaths.Count < 1) return; PluginMenuItemPart firstPart = thePaths[0]; PluginMenuPartStruct menuStruct = GetMenuItemIndex(firstPart, nodes); IList<PluginMenuItemPart> otherParts = GetLeavesMenuItemParts(thePaths); if (!menuStruct.IsCreate) { AddTreeNodeIntoTree(container, nodes[menuStruct.Index].Nodes, theItem, thePath, otherParts, callback); } else { TreeNode theMenuItem = new TreeNode(firstPart.TextStyle.Text); CreateMenuEndItem(firstPart, theMenuItem, GetImageList(container, thePath.MenuImageIndex)); nodes.Insert( menuStruct.Index, theMenuItem ); if (thePaths.Count > 1) { AddTreeNodeIntoTree(container, theMenuItem.Nodes, theItem, thePath, otherParts, callback); } else { theMenuItem.Name = theItem.Url; theMenuItem.Tag = new object[] { theItem, callback }; theMenuItem.TreeView.NodeMouseClick -= new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick); theMenuItem.TreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick); return; } } }
public static IDictionary<string, string> GetCategoryUrlList(string category) { Debug.Assert(category != null); IDictionary<string, string> result = new Dictionary<string, string>(); foreach (XmlNode pluginNode in GetPluginXmlDoc().SelectNodes("Plugins/Plugin")) { PluginConfigItem item = new PluginConfigItem(); item.Url = ParsePluginUrl(pluginNode); item.MenuPaths = ParsePluginMenuPaths(pluginNode); if (category == item.GetCategory()) { string key = item.GetId(); if (item.MenuPaths != null && item.MenuPaths.Count > 0) { key = item.MenuPaths[0].MenuPathParts[item.MenuPaths[0].MenuPathParts.Count - 1].TextStyle.Text; } result[key] = item.Url; } } return result; }
private void LoadPluginDll(PluginConfigItem configItem) { IPluginLocator theLocator = PluginLocatorFactory.GetLocator(configItem.QualifiedName.LoadProtocol); IList <PluginDll> expandingDlls = new List <PluginDll>(); IList <PluginDll> _changedList = new List <PluginDll>(); for (int i = 0; i < configItem.PluginDlls.Count; i++) { PluginDll theDll = configItem.PluginDlls[i]; if (theDll.NewVersion) { bool loaded = theLocator.LoadDll(this._pluginContext.PluginContainer.Name, theDll, expandingDlls); if (!loaded) { configItem.Status = PluginConfigItemStatus.LoadPluginDllFailure; break; } else { theDll.NewVersion = false; _changedList.Add(theDll); } } } if (_changedList.Count > 0) { PluginLocatorBase.SavePluginDllVersion(_changedList); } foreach (PluginDll expandingDll in expandingDlls) { if (!PluginLocatorBase.IsInPluginDlls(expandingDll, configItem.PluginDlls)) { configItem.PluginDlls.Add(expandingDll); } } }
public static IDictionary <string, string> GetCategoryUrlList(string category) { Debug.Assert(category != null); IDictionary <string, string> result = new Dictionary <string, string>(); foreach (XmlNode pluginNode in GetPluginXmlDoc().SelectNodes("Plugins/Plugin")) { PluginConfigItem item = new PluginConfigItem(); item.Url = ParsePluginUrl(pluginNode); item.MenuPaths = ParsePluginMenuPaths(pluginNode); if (category == item.GetCategory()) { string key = item.GetId(); if (item.MenuPaths != null && item.MenuPaths.Count > 0) { key = item.MenuPaths[0].MenuPathParts[item.MenuPaths[0].MenuPathParts.Count - 1].TextStyle.Text; } result[key] = item.Url; } } return(result); }
private PluginConfigItem ParsePluginConfigItem(XmlNode node) { PluginConfigItem theItem = new PluginConfigItem(); theItem.Status = PluginConfigItemStatus.OK; try { theItem.Url = ParsePluginUrl(node); theItem.PluginInitArgs = ParsePluginInitArgs(node); theItem.QualifiedName = ParsePluginLocate(node); theItem.Behavior = ParsePluginBehavior(node); theItem.RequireFeatureAccess = ParsePluginPermission(node); theItem.RunContext = ParsePluginRunContext(node); theItem.MenuPaths = ParsePluginMenuPaths(node); theItem.PluginDlls = ParsePluginDlls(node); } catch (Exception ex) { LogUtils.LogError(ex); theItem.Status = PluginConfigItemStatus.ParsePluginConfigFailure; } return(theItem); }
public void ExecutePlugin(PluginConfigItem configItem) { Debug.Assert(configItem.Url != null); try { LoadPluginDll(configItem); PluginRunContext runContext = PluginRunContext.Parse(configItem, _pluginContext); bool dllLoaded = runContext.LoadPluginDlls(); if (!dllLoaded) { configItem.Status = PluginConfigItemStatus.CreatePluginDllFailure; } configItem.PluginRunContext = runContext; runContext.ExecutePlugin(); } catch (Exception ex) { LogUtils.LogError(ex); } }
public virtual void AddIntoMenu(ConnectionPointContainer container, PluginConfigItem theItem, PluginMenuPath thePath, ExecutePluginCallback callback) { }
public ThreadRun(PluginConfigItem ConfigItem, IPluginContext Context, AutoResetEvent theSignal, Dictionary<string, IPlugin> plugins, MultiThreadPluginRunContext parent) { this.ConfigItem = ConfigItem; this.Context = Context; this.theSignal = theSignal; this.thePlugins = plugins; this.parent = parent; }
public PluginRunContext(PluginConfigItem configItem, IPluginContext context) { _theItem = configItem; _context = context; configItem.PluginRunContext = this; }
public MultiThreadPluginRunContext(PluginConfigItem ConfigItem, IPluginContext Context) : base(ConfigItem, Context) { }
public MultiProcessPluginRunContext(PluginConfigItem theItem, IPluginContext context) : base(theItem, context) { }
protected void AddTreeNodeIntoTree(ConnectionPointContainer container, TreeNodeCollection nodes, PluginConfigItem theItem, PluginMenuPath thePath, IList <PluginMenuItemPart> thePaths, ExecutePluginCallback callback) { if (thePaths.Count < 1) { return; } PluginMenuItemPart firstPart = thePaths[0]; PluginMenuPartStruct menuStruct = GetMenuItemIndex(firstPart, nodes); IList <PluginMenuItemPart> otherParts = GetLeavesMenuItemParts(thePaths); if (!menuStruct.IsCreate) { AddTreeNodeIntoTree(container, nodes[menuStruct.Index].Nodes, theItem, thePath, otherParts, callback); } else { TreeNode theMenuItem = new TreeNode(firstPart.TextStyle.Text); CreateMenuEndItem(firstPart, theMenuItem, GetImageList(container, thePath.MenuImageIndex)); nodes.Insert( menuStruct.Index, theMenuItem ); if (thePaths.Count > 1) { AddTreeNodeIntoTree(container, theMenuItem.Nodes, theItem, thePath, otherParts, callback); } else { theMenuItem.Name = theItem.Url; theMenuItem.Tag = new object[] { theItem, callback }; theMenuItem.TreeView.NodeMouseClick -= new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick); theMenuItem.TreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick); return; } } }
public MultiAppDomainPuginRunContext(PluginConfigItem theItem, IPluginContext context) : base(theItem, context) { }
protected void AddMenuItemIntoMenu(ConnectionPointContainer container, ToolStripItemCollection toolStripItemCollection, PluginConfigItem theItem, PluginMenuPath thePath, IList<PluginMenuItemPart> thePaths, ExecutePluginCallback callback) { if (thePaths.Count < 1) return; PluginMenuItemPart firstPart = thePaths[0]; PluginMenuPartStruct menuStruct = GetMenuItemIndex(firstPart, toolStripItemCollection); IList<PluginMenuItemPart> otherParts = GetLeavesMenuItemParts(thePaths); if (!menuStruct.IsCreate) { AddMenuItemIntoMenu(container, (toolStripItemCollection[menuStruct.Index] as ToolStripMenuItem).DropDownItems, theItem, thePath, otherParts, callback); } else { if (firstPart.TextStyle.Text.Trim() == "-") { toolStripItemCollection.Insert( menuStruct.Index, new ToolStripSeparator() ); return; } ToolStripMenuItem theMenuItem = new ToolStripMenuItem(firstPart.TextStyle.Text); CreateMenuEndItem(firstPart, theMenuItem, GetImageList(container, thePath.MenuImageIndex)); toolStripItemCollection.Insert( menuStruct.Index, theMenuItem ); if (thePaths.Count > 1) { AddMenuItemIntoMenu(container, theMenuItem.DropDownItems, theItem, thePath, otherParts, callback); } else { theMenuItem.Name = theItem.Url; theMenuItem.Tag = new object[] { theItem, callback }; string[] behaviors = theItem.Behavior.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string action in behaviors) { PluginConfigItemBehaviorMode theBehavior = (PluginConfigItemBehaviorMode)Enum.Parse(typeof(PluginConfigItemBehaviorMode), action, true); switch (theBehavior) { case PluginConfigItemBehaviorMode.Click: theMenuItem.Click -= TheMenuItem_Click; theMenuItem.Click += TheMenuItem_Click; break; case PluginConfigItemBehaviorMode.MouseOver: theMenuItem.MouseMove -= new MouseEventHandler(TheMenuItem_MouseMove); theMenuItem.MouseMove += new MouseEventHandler(TheMenuItem_MouseMove); break; } } return; } } }
protected void AddMenuItemIntoMenu(ConnectionPointContainer container, ItemCollection menuItemCollection, PluginConfigItem theItem, PluginMenuPath thePath, IList <PluginMenuItemPart> thePaths, ExecutePluginCallback callback) { if (thePaths.Count < 1) { return; } PluginMenuItemPart firstPart = thePaths[0]; PluginMenuPartStruct menuStruct = GetMenuItemIndex(firstPart, menuItemCollection); IList <PluginMenuItemPart> otherParts = GetLeavesMenuItemParts(thePaths); if (!menuStruct.IsCreate) { AddMenuItemIntoMenu(container, (menuItemCollection[menuStruct.Index] as MenuItem).Items, theItem, thePath, otherParts, callback); } else { if (firstPart.TextStyle.Text.Trim() == "-") { menuItemCollection.Insert(menuStruct.Index, new Separator()); return; } MenuItem theMenuItem = new MenuItem() { Header = firstPart.TextStyle.Text }; CreateMenuEndItem(firstPart, theMenuItem, GetImageList(container, thePath.MenuImageIndex)); menuItemCollection.Insert(menuStruct.Index, theMenuItem); if (thePaths.Count > 1) { AddMenuItemIntoMenu(container, theMenuItem.Items, theItem, thePath, otherParts, callback); } else { theMenuItem.Name = theItem.Url; theMenuItem.Tag = new object[] { theItem, callback }; string[] behaviors = theItem.Behavior.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string action in behaviors) { PluginConfigItemBehaviorMode theBehavior = (PluginConfigItemBehaviorMode)Enum.Parse(typeof(PluginConfigItemBehaviorMode), action, true); switch (theBehavior) { case PluginConfigItemBehaviorMode.Click: theMenuItem.Click -= TheMenuItem_Click; theMenuItem.Click += TheMenuItem_Click; break; case PluginConfigItemBehaviorMode.MouseOver: theMenuItem.MouseMove -= TheMenuItem_MouseMove; theMenuItem.MouseMove += TheMenuItem_MouseMove; break; } } return; } } }
private PluginConfigItem ParsePluginConfigItem(XmlNode node) { PluginConfigItem theItem = new PluginConfigItem(); theItem.Status = PluginConfigItemStatus.OK; try { theItem.Url = ParsePluginUrl(node); theItem.PluginInitArgs = ParsePluginInitArgs(node); theItem.QualifiedName = ParsePluginLocate(node); theItem.Behavior = ParsePluginBehavior(node); theItem.RequireFeatureAccess = ParsePluginPermission(node); theItem.RunContext = ParsePluginRunContext(node); theItem.MenuPaths = ParsePluginMenuPaths(node); theItem.PluginDlls = ParsePluginDlls(node); } catch (Exception ex) { LogUtils.LogError(ex); theItem.Status = PluginConfigItemStatus.ParsePluginConfigFailure; } return theItem; }
private void LoadPluginDll(PluginConfigItem configItem) { IPluginLocator theLocator = PluginLocatorFactory.GetLocator(configItem.QualifiedName.LoadProtocol); IList<PluginDll> expandingDlls = new List<PluginDll>(); IList<PluginDll> _changedList = new List<PluginDll>(); for (int i = 0; i < configItem.PluginDlls.Count; i++) { PluginDll theDll = configItem.PluginDlls[i]; if (theDll.NewVersion) { bool loaded = theLocator.LoadDll(this._pluginContext.PluginContainer.Name, theDll, expandingDlls); if (!loaded) { configItem.Status = PluginConfigItemStatus.LoadPluginDllFailure; break; } else { theDll.NewVersion = false; _changedList.Add(theDll); } } } if (_changedList.Count > 0) { PluginLocatorBase.SavePluginDllVersion(_changedList); } foreach (PluginDll expandingDll in expandingDlls) { if (!PluginLocatorBase.IsInPluginDlls(expandingDll, configItem.PluginDlls)) configItem.PluginDlls.Add(expandingDll); } }