Пример #1
0
        /// <summary>
        /// 从指定目录添加目录中的插件到m_Pluginlist中
        /// 实现Plugins.AddFromDir接口
        /// </summary>
        /// <param name="path">目录路径</param>
        /// <returns></returns>
        public bool AddFromDir(string path)
        {
            if (m_Locked)
            {
                return(false);
            }
            int       count = 0;
            ArrayList ar    = PluginManagementTools.FindPluginDLLs(path);

            foreach (string s in ar)
            {
                if (AddFromFile(s))
                {
                    count++;
                }
            }
            if (count > 0 && count <= ar.Count)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 从默认目录(Plugins)将插件添加到m_Pluginlist中
        /// </summary>
        /// <returns></returns>
        internal bool LoadPlugins()
        {
            if (m_Locked)
            {
                return(false);
            }

            int count = 0;

            PluginFolder = App.Path + "\\Plugins";                                           //bin目录下的Plugins文件夹
            ArrayList PotentialPlugins = PluginManagementTools.FindPluginDLLs(PluginFolder); //包含完整路径的文件名

            for (int i = 0; i < PotentialPlugins.Count; i++)
            {
                PluginInfo info = new PluginInfo();
                try
                {
                    if (PotentialPlugins.IndexOf("RemoveMe-Script") > 0) //删除用RemoveMe-Script标识的插件
                    {
                        System.IO.File.Delete(PotentialPlugins[i].ToString());
                    }
                    else if (info.Init(PotentialPlugins[i].ToString(), typeof(MapWinGIS.Interfaces.IPlugin).GUID)) //存在
                    {
                        if (m_PluginList.ContainsKey(info.Key) == false)
                        {
                            m_PluginList.Add(info.Key, info);
                            count++;
                        }
                        else
                        {
                            //插件重复
                            string dupfile = m_PluginList[info.Key].FileName;
                            if (!(dupfile.ToLower() == PotentialPlugins[i].ToString().ToLower()))
                            {
                                MapWinGIS.Utility.Logger.Msg("警告: 检测到插件重复."
                                                             + "\r\n" + "\r\n" + "加载的插件是: " + dupfile + "\r\n"
                                                             + "重复的插件被忽略: "
                                                             + PotentialPlugins[i].ToString(), "插件重复", System.Windows.Forms.MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MapWinGIS.Utility.Logger.Dbg(ex.ToString());
                }
            }
            //确保有插件记录添加到m_PluginList中
            if (count > 0 && count <= PotentialPlugins.Count)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// 从ApplicationPlugins文件夹中加载内部插件
        /// </summary>
        /// <param name="applicationPluginPath"></param>
        internal void LoadApplicationPlugins(string applicationPluginPath)
        {
            if (applicationPluginPath == "" || !System.IO.Directory.Exists(applicationPluginPath))
            {
                return;
            }

            ArrayList arr = new ArrayList();

            try
            {
                ArrayList  potentialPlugins = PluginManagementTools.FindPluginDLLs(applicationPluginPath);
                PluginInfo info;
                IPlugin    plugin;

                foreach (string pluginName in potentialPlugins)
                {
                    info = new PluginInfo();
                    if (info.Init(pluginName, typeof(IPlugin).GUID))
                    {
                        if (info.Key != null && !m_ApplicationPlugins.ContainsKey(info.Key))
                        {
                            plugin = (IPlugin)PluginManagementTools.CreatePluginObject(pluginName, info.CreateString);
                            if (plugin != null)
                            {
                                m_ApplicationPlugins.Add(info.Key, plugin);
                                plugin.Initialize(Program.frmMain, Program.frmMain.Handle.ToInt32());
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MapWinGIS.Utility.Logger.Dbg(e.ToString());
            }
        }