Exemplo n.º 1
0
        public void RemovePlugin(string pluginName)
        {
            doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            XmlNode node = doc.SelectSingleNode("/configuration/PluginSection");

            foreach (XmlNode n in node.ChildNodes)
            {
                if (n.Attributes != null)
                {
                    if (n.Attributes[0].Value == pluginName)
                    {
                        node.RemoveChild(n);
                    }
                }
            }
            doc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            ConfigurationManager.RefreshSection("PluginSection");
            var _p = from _c in CurrentPluginInfos
                     where _c.Name == pluginName
                     select _c;
            AppPluginInfo _app = _p.FirstOrDefault();

            if (_app != null)
            {
                CurrentPluginInfos.Remove(_app);
            }
        }
Exemplo n.º 2
0
        public bool LoadPlugin(string pluginName)
        {
            string  AssemblyFile;
            Boolean result = false;

            config = (PluginConfigurationSection)ConfigurationManager.GetSection("PluginSection");
            PluginConfigurationElement pe = new PluginConfigurationElement();

            String path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "";

            try
            {
                for (Int32 i = 0; i < config.PluginCollection.Count; i++)
                {
                    pe = config.PluginCollection[i];
                    if (pe.Name == pluginName)
                    {
                        if (pe.Version == "")
                        {
                            AssemblyFile = path + "\\" + pe.Assembly;
                        }
                        else
                        {
                            AssemblyFile = path + "\\Plugin\\" + pe.Version + "\\" + pe.Assembly;
                            if (!File.Exists(AssemblyFile))
                            {
                                AssemblyFile = path + "\\" + pe.Assembly;
                            }
                        }

                        Assembly      assembly = Assembly.LoadFile(AssemblyFile);
                        Type          type     = assembly.GetType(pe.Type);
                        IServerPlugin instance = (IServerPlugin)Activator.CreateInstance(type);
                        instance.ServerApplication = application;
                        instance.Load();
                        plugins[pluginName] = instance;
                        result = true;

                        AppPluginInfo _apinfo = new AppPluginInfo();
                        _apinfo.Descript        = pe.Description;
                        _apinfo.PluginType      = pe.Type;
                        _apinfo.Name            = pe.Name;
                        _apinfo.FileName        = pe.Assembly;
                        _apinfo.AssemblyVersion = assembly.GetName().Version.ToString();
                        CurrentPluginInfos.Add(_apinfo);
                        break;
                    }
                }
                if (!result)
                {
                    application.WriteMessage(string.Format("未找到插件{0}!", pluginName), EventLogEntryType.Error);
                }
            }
            catch (Exception e)
            {
                application.WriteMessage(string.Format("出现错误:{0}", e.Message), EventLogEntryType.Error);
                result = false;
            }
            return(result);
        }
Exemplo n.º 3
0
 public static string LoadAppPlugin(AppPluginInfo _api)
 {
     try
     {
         CurrentService.AddPlugin(_api.Name, _api.PluginType, _api.FileName, _api.Descript, _api.AssemblyVersion);
         CurrentService.LoadPlugin(_api.Name);
         return("TRUE");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Exemplo n.º 4
0
 public static string RemovePlugin(AppPluginInfo _api)
 {
     try
     {
         CurrentService.UnLoadPlugin(_api.Name);
         CurrentService.RemovePlugin(_api.Name);
         return("TRUE");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Exemplo n.º 5
0
        public void LoadAllPlugin()
        {
            application.WriteMessage("开始加载插件!", EventLogEntryType.Information);
            CurrentPluginInfos = new List <AppPluginInfo>();
            PluginConfigurationElement pe = new PluginConfigurationElement();

            config = (PluginConfigurationSection)ConfigurationManager.GetSection("PluginSection");
            if (config == null)
            {
                application.WriteMessage("未配置插件文件!", EventLogEntryType.Error);
                return;
            }
            String path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "";

            try
            {
                for (Int32 i = 0; i < config.PluginCollection.Count; i++)
                {
                    pe = config.PluginCollection[i];
                    if (File.Exists(path + "\\" + pe.Assembly))
                    {
                        Assembly assembly = Assembly.LoadFile(path + "\\" + pe.Assembly);

                        Type          type     = assembly.GetType(pe.Type);
                        IServerPlugin instance = (IServerPlugin)Activator.CreateInstance(type);
                        instance.ServerApplication = application;
                        instance.Load();
                        plugins[pe.Name] = instance;

                        AppPluginInfo _apinfo = new AppPluginInfo();
                        _apinfo.Descript        = pe.Description;
                        _apinfo.PluginType      = pe.Type;
                        _apinfo.Name            = pe.Name;
                        _apinfo.FileName        = pe.Assembly;
                        _apinfo.AssemblyVersion = assembly.GetName().Version.ToString();
                        CurrentPluginInfos.Add(_apinfo);
                    }
                    else
                    {
                        application.WriteMessage(string.Format("服务器端插件文件{0}不存在!", pe.Assembly), EventLogEntryType.Error);
                    }
                }
            }
            catch (Exception e)
            {
                application.WriteMessage(string.Format("出现错误:{0}", e.Message), EventLogEntryType.Error);
            }
            application.WriteMessage("加载插件结束...", EventLogEntryType.Information);
        }
Exemplo n.º 6
0
        public static void AddPluginDescript(AppPluginInfo PluginInfo)
        {
            var _a = from _c in PluginDescriptList
                     where _c.FileName == PluginInfo.FileName
                     select _c;

            if (_a.Count() > 0)
            {
                return;
            }
            PluginDescriptList.Add(PluginInfo);
            string FileName = Utils.ExeDir + "PluginInfo.txt";
            string _js      = SerializeHelper.JsonSerialize <List <AppPluginInfo> >(ServerPluginService.CurrentPluginInfos);

            File.WriteAllText(FileName, _js);
        }