Exemplo n.º 1
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.º 2
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.º 3
0
        public bool LoadPlugin(string pluginName)
        {
            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)
                    {
                        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[pluginName] = instance;
                        result = true;
                        break;
                    }
                }
                if (!result)
                {
                    application.WriteMessage(string.Format("未找到插件{0}!", pluginName));
                }
            }
            catch (Exception e)
            {
                application.WriteMessage(string.Format("出现错误:{0}", e.Message));
                result = false;
            }
            return(result);
        }
Exemplo n.º 4
0
        public void LoadAllPlugin()
        {
            PluginConfigurationElement pe = new PluginConfigurationElement();

            config = (PluginConfigurationSection)ConfigurationManager.GetSection("PluginSection");
            if (config == null)
            {
                application.WriteMessage("未配置插件文件!");
                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;
                    }
                    else
                    {
                        application.WriteMessage(string.Format("服务器端插件文件{0}不存在!", pe.Assembly));
                    }
                }
            }
            catch (Exception e)
            {
                application.WriteMessage(string.Format("出现错误:{0}", e.Message));
            }
        }