예제 #1
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);
            }
        }
예제 #2
0
        /// <summary>
        /// 搜索插件的Key
        /// </summary>
        /// <returns></returns>
        private string FindPluginKey()
        {
            try
            {
                int i = 1;
                while (true)
                {
                    StackFrame sf = new StackFrame(i);
                    if (sf == null)
                    {
                        return("");
                    }
                    if (sf.GetMethod() == null)
                    {
                        return("");
                    }
                    if (sf.GetMethod().Module == null)
                    {
                        return("");
                    }
                    if (sf.GetMethod().Module.FullyQualifiedName.ToLower().Contains("plugins"))
                    {
                        PluginInfo info = new PluginInfo();
                        if (info.Init(sf.GetMethod().Module.FullyQualifiedName, typeof(Interfaces.IPlugin).GUID) && info.Key != "")
                        {
                            return(info.Key);
                        }
                        //兼容最新接口
                        //else if (info.Init(sf.GetMethod().Module.FullyQualifiedName, typeof(MapWinGIS.PluginInterfaces.IBasePlugin).GUID) && info.Key != "")
                        //{
                        //    return info.Key;
                        //}
                    }
                    i++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return("");
        }
예제 #3
0
        /// <summary>
        /// 从指定包含文件名的路径添加一个插件到m_Pluginlist中
        /// 实现Plugins.AddFromFile接口
        /// </summary>
        /// <param name="path">包含文件名的路径</param>
        /// <returns></returns>
        public bool AddFromFile(string path)
        {
            if (m_Locked)
            {
                return(false);
            }

            PluginInfo info = new PluginInfo();
            bool       retval; //指示插件是否加载成功

            try
            {
                retval = info.Init(path, typeof(MapWinGIS.Interfaces.IPlugin).GUID);
                if (retval == true)                                  //插件加载成功
                {
                    if (m_PluginList.ContainsKey(info.Key) == false) //没有相同插件
                    {
                        m_PluginList.Add(info.Key, info);
                        Program.frmMain.SynchPluginMenu();
                    }
                    else //有相同的插件
                    {
                        string dupfile = (m_PluginList[info.Key]).FileName;//插件路径
                        if (dupfile.ToLower() != path.ToLower())
                        {
                            MapWinGIS.Utility.Logger.Msg("警告: 检测到插件重复."
                                                         + "\r\n" + "\r\n" + "加载的插件是: " + dupfile + "\r\n"
                                                         + "重复的插件被忽略: "
                                                         + path, "插件重复", System.Windows.Forms.MessageBoxIcon.Information);
                        }
                    }
                }
                return(retval);
            }
            catch (Exception ex)
            {
                Program.g_error = ex.ToString();
                Program.ShowError(ex);
                return(false);
            }
        }
예제 #4
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());
            }
        }
예제 #5
0
        /// <summary>
        /// 从可用插件列表移除一个插件,若已加载,卸载
        /// 实现Menus.Remove接口
        /// </summary>
        /// <param name="menuName"></param>
        /// <returns></returns>
        public bool Remove(string menuName)
        {
            System.Windows.Forms.ToolStripItem m;
            string key = MenuTableKey(menuName);

            System.Windows.Forms.MenuStrip parentMenu  = null;
            System.Windows.Forms.ToolStrip parentStrip = null;
            try
            {
                if (m_MenuTable.ContainsKey(key))
                {
                    m = (System.Windows.Forms.ToolStripItem)(m_MenuTable[key]);
                    if (m.GetType().Name == "ToolStripMenuItem")//是Form.ToolStripMenuItem类型,则从m_MenuTable移除该菜单项 的子项
                    {
                        RemoveSubMenusFromMenuTable((System.Windows.Forms.ToolStripMenuItem)m);
                    }
                    m_MenuTable.Remove(key);//移除该项

                    try
                    {
                        object o = m.GetCurrentParent();//ToolStripItem的父对象ToolStrip
                        if (o is System.Windows.Forms.MenuStrip)
                        {
                            parentMenu = (System.Windows.Forms.MenuStrip)o;
                        }
                        if (o is System.Windows.Forms.ToolStrip)
                        {
                            parentStrip = (System.Windows.Forms.ToolStrip)o;
                        }
                        if (parentMenu != null)//是MenuStrip类型,从窗体中移除该菜单项
                        {
                            parentMenu.Items.Remove(m);
                        }
                        else if (parentStrip != null)//是ToolStrip类型,从窗体中移除该菜单项
                        {
                            parentStrip.Items.Remove(m);
                        }
                        else //既不是MenuStrip也不是Toolstrip,是上级菜单项,则直接移除
                        {
                            Program.frmMain.menuStrip1.Items.Remove(m);
                        }
                    }
                    catch (Exception e)
                    {
                        Program.CustomExceptionHandler.OnThreadException(e);
                        return(false);
                    }

                    System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1);
                    string pluginfile = stackFrame.GetMethod().Module.FullyQualifiedName;
                    if (!pluginfile.ToLower().EndsWith("mapwingis.exe"))//不是以mapwingis.exe结尾,则表示是插件菜单
                    {
                        //获取插件Key
                        string     pluginkey = "";
                        PluginInfo info      = new PluginInfo();
                        if (info.Init(pluginfile, typeof(Interfaces.IPlugin).GUID) && info.Key != "")
                        {
                            pluginkey = info.Key;
                        }
                        //如果获取插件Key成功,则移除该插件
                        if (pluginkey != "")
                        {
                            MenuTrackerRemove(menuName, pluginkey);
                        }
                    }

                    // 当菜单栏所有项都移除了,则移除菜单栏(menuStrip1)
                    if (Program.frmMain.menuStrip1.Items.Count == 0)
                    {
                        //修改,menuStrip1不是在TopToolStripPanel中
                        Program.frmMain.Controls.Remove(Program.frmMain.menuStrip1);
                        //Program.frmMain.StripDocker.TopToolStripPanel.Controls.Remove(Program.frmMain.menuStrip1);
                        //如果所有的控件都移除了,就隐藏工具条(TopToolStripPanel)
                        if (Program.frmMain.StripDocker.TopToolStripPanel.Controls.Count == 0)
                        {
                            Program.frmMain.StripDocker.TopToolStripPanel.Hide();
                        }
                    }
                    return(true);
                }
                //菜单中不包含该名字的菜单,则移除失败
                return(false);
            }
            catch (Exception ex)
            {
                Program.g_error = ex.ToString();
                Program.ShowError(ex);
                return(false);
            }
        }