Exemplo n.º 1
0
        /// <summary>
        /// 是否存在指定键的插件。若存在于m_Pluginlist中,则添加到m_LoadPlugins中
        /// 实现Plugins.StartPlugin接口
        /// </summary>
        /// <param name="key">插件的Key</param>
        /// <returns></returns>
        public bool StartPlugin(string key)
        {
            if (m_Locked)
            {
                return(false);
            }

            MapWinGIS.Interfaces.IPlugin plugin;
            PluginInfo info;

            if (m_LoadedPlugins.ContainsKey(key))//在m_LoadedPlugins中搜索,有 - 已经加载不再加载
            {
                return(true);
            }

            if (m_PluginList.ContainsKey(key)) //在m_PluginList中搜索,有 - 创建实例,添加到m_LoadedPlugins中
            {
                try
                {
                    info   = m_PluginList[key];
                    plugin = (IPlugin)(PluginManagementTools.CreatePluginObject(info.FileName, info.CreateString));
                    if (plugin == null)
                    {
                        return(false);
                    }

                    m_LoadedPlugins.Add(info.Key, plugin);
                    plugin.Initialize(Program.frmMain, Program.frmMain.Handle.ToInt32());//调用插件中的方法进行初始化
                    Program.frmMain.SynchPluginMenu();
                    return(true);
                }
                catch (Exception ex)
                {
                    Program.g_error = "插件出现错误:  " + ex.ToString();
                    Program.ShowError(ex);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
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());
            }
        }