コード例 #1
0
        public void AddPlugin(PluginInfo plugin)
        {
            try
            {
                this._plugins.Add(plugin);

                if (plugin.Type == PluginType.BackgroundThread)
                {
                    BackgroundThreadPluginManager.Instance.Register(plugin);
                }
                else if (plugin.Type == PluginType.ServerMethod)
                {
                    ServerMethodManager.Register(InstanceId, plugin);
                }
            }
            catch (Exception ex)
            {
                SessionLog.Exception(ex);
            }
        }
コード例 #2
0
        public CommonReturnValue UpdatePluginList(dynamic pluginList)
        {
            var oldList = this.Plugins;

            if (oldList == null)
            {
                oldList = new List <string>();
            }

            this.Plugins = new List <string>();

            if (pluginList == null)
            {
                return(CommonReturnValue.Success());
            }

            foreach (Newtonsoft.Json.Linq.JObject p in pluginList)
            {
                bool included = (bool)p["Included"];
                Guid g        = (Guid)p["Guid"];

                if (included)
                {
                    this.Plugins.Add(g.ToString());
                }
            }
            ;

            var newlyEnabled = this.Plugins.Where(p => oldList.FirstOrDefault(x => x.Equals(p, StringComparison.OrdinalIgnoreCase)) == null).Select(g => g.ToLower());
            var disabled     = oldList.Where(p => this.Plugins.FirstOrDefault(x => x.Equals(p, StringComparison.OrdinalIgnoreCase)) == null).Select(g => g.ToLower());

            var ret = PluginLoader.Instance.PluginAssemblies
                      .SelectMany(a => a.Plugins, (pa, plugin) => new
            {
                PluginAssembly = pa,
                PluginInfo     = plugin
            })
                      .Where(p => p.PluginInfo.Type == PluginType.BackgroundThread || p.PluginInfo.Type == PluginType.ServerMethod)
                      .ToList();

            var startList = ret.Where(p => newlyEnabled.Contains(p.PluginInfo.Guid.ToString().ToLower()));
            var stopList  = ret.Where(p => disabled.Contains(p.PluginInfo.Guid.ToString().ToLower()));

            // START
            {
                foreach (var item in startList)
                {
                    if (item.PluginInfo.Type == PluginType.BackgroundThread)
                    {
                        BackgroundThreadPluginManager.Instance.Register(item.PluginInfo);
                    }
                    else if (item.PluginInfo.Type == PluginType.ServerMethod)
                    {
                        ServerMethodManager.Register(item.PluginAssembly.InstanceId, item.PluginInfo);
                    }
                }
            }

            // STOP
            {
                foreach (var item in stopList)
                {
                    if (item.PluginInfo.Type == PluginType.BackgroundThread)
                    {
                        // TODO: Implement a stop and call for specific EP!
                        BackgroundThreadPluginManager.Instance.StopForApp(this, item.PluginInfo);
                        //BackgroundThreadPluginManager.Instance.Register(item.PluginInfo);
                    }
                    else if (item.PluginInfo.Type == PluginType.ServerMethod)
                    {
                        //ServerMethodManager.Register(item.PluginAssembly.InstanceId, item.PluginInfo);
                    }
                }
            }

            return(CommonReturnValue.Success());
        }