예제 #1
0
        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];
        }
예제 #2
0
 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]);
 }
예제 #3
0
        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]);
        }
예제 #4
0
        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);
            }
        }