Exemplo n.º 1
0
        public void LoadAllPlugin()
        {
            PluginConfigurationElement pe = new PluginConfigurationElement();

            config = (PluginConfigurationSection)ConfigurationManager.GetSection("PluginSection");
            String path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "";

            try
            {
                for (Int32 i = 0; i < config.PluginCollection.Count; i++)
                {
                    pe = config.PluginCollection[i];
                    string _fileName = path + "\\" + pe.Assembly;
                    if (File.Exists(_fileName))
                    {
                        Assembly assembly = Assembly.LoadFile(_fileName);
                        Type     type     = assembly.GetType(pe.Type);
                        IPlugin  instance = (IPlugin)Activator.CreateInstance(type);
                        instance.Application = application;
                        instance.Load();
                        plugins[pe.Name] = instance;
                    }
                    else
                    {
                        //插件文件不存在
                        application.WriteMessage(string.Format("错误: 插件文件{0}[{1}]不存在!", pe.Assembly, pe.Description));
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("调用插件配置信息出错,请检查配置文件!\n错误信息如下:{0}", e.Message));
            }
        }
Exemplo n.º 2
0
        public bool Contains(string pluginName)
        {
            config = (PluginConfigurationSection)ConfigurationManager.GetSection("PluginSection");
            PluginConfigurationElement pe = new PluginConfigurationElement();
            List <String> ps = new List <string>();

            for (Int32 i = 0; i < config.PluginCollection.Count; i++)
            {
                pe = config.PluginCollection[i];
                ps.Add(pe.Name);
            }
            return(ps.Contains(pluginName));
        }
Exemplo n.º 3
0
        public string[] GetAllPluginNames()
        {
            config = (PluginConfigurationSection)ConfigurationManager.GetSection("PluginSection");
            PluginConfigurationElement pe = new PluginConfigurationElement();
            ArrayList ps = new ArrayList();

            for (Int32 i = 0; i < config.PluginCollection.Count; i++)
            {
                pe = config.PluginCollection[i];
                ps.Add(pe.Name);
            }
            return((String[])ps.ToArray(typeof(String)));
        }
Exemplo n.º 4
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)
                    {
                        string _fileName = path + "\\" + pe.Assembly;
                        if (File.Exists(_fileName))
                        {
                            Assembly assembly = Assembly.LoadFile(_fileName);
                            Type     type     = assembly.GetType(pe.Type);
                            IPlugin  instance = (IPlugin)Activator.CreateInstance(type);
                            instance.Application = application;
                            instance.Load();
                            plugins[pluginName] = instance;
                            result = true;
                        }
                        else
                        {
                            //如果不存在插件
                        }
                        break;
                    }
                }
                if (!result)
                {
                    MessageBox.Show("Not Found the Plugin");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                result = false;
            }
            return(result);
        }