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 IPluginRunContext GetContext(AppDomain appDomain) { if (!ContextList.ContainsKey(ConfigItem.Url)) { PluginRunContext obj = appDomain.CreateInstanceAndUnwrap( Assembly.GetExecutingAssembly().GetName().Name, typeof(PluginRunContext).FullName.Split(',')[0]) as PluginRunContext; obj.ConfigItem = this.ConfigItem; obj.Context = this.Context; ContextList[ConfigItem.Url] = obj; } return(ContextList[ConfigItem.Url]); }
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]); }
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); } }