Ejemplo n.º 1
0
        /// <summary>
        /// 获得插件对象
        /// </summary>
        /// <param name="pluginCol">当前插件集合</param>
        /// <param name="_type">插件类型</param>
        private static void getPluginObject(PluginCollection pluginCol, Type _type)
        {
            IPlugin plugin = null;

            try
            {
                //object aa = Activator.CreateInstance(_type);
                //创建一个插件对象实例
                plugin = Activator.CreateInstance(_type) as NBGIS.PluginEngine.IPlugin;
            }
            catch
            {
                if (AppLog.log.IsErrorEnabled)
                {
                    AppLog.log.Error(_type.FullName + "反射生成对象时发生异常");
                }
            }
            finally
            {
                if (plugin != null)
                {
                    //判断该插件是否已经存在插件集合中了,如果不是则加入该对象
                    if (!pluginCol.Contains(plugin))
                    {
                        pluginCol.Add(plugin);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void AddRange(PluginCollection value)
 {
     for (int i = 0; i < value.Capacity; i++)
     {
         this.Add((IPlugin)value.List[i]);
     }
 }
Ejemplo n.º 3
0
        private static void GetPluginObject(PluginCollection pluginCol, Type type)
        {
            IPlugin plugin = null;

            try
            {
                plugin = Activator.CreateInstance(type) as NBGIS.PluginEngine.IPlugin;
            }
            catch (Exception ex)
            {
                if (Applog.log.IsErrorEnabled)
                {
                    Applog.log.Error(type.FullName + "反射生成对象时发生异常" + "Message" + ex.Message);
                }
            }
            finally
            {
                if (plugin != null)
                {
                    if (!pluginCol.Contains(plugin))
                    {
                        pluginCol.Add(plugin);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 解析插件集合中所有的对象
 /// 将其分别装入ICommand,ITool,IToolBarDef,IMenuDefI和DockableWindowDef 5个集合
 /// </summary>
 /// <param name="pluginCol">插件集合</param>
 public void GetPluginArray(PluginCollection pluginCol)
 {
     //遍历插件集合
     foreach (NBGIS.PluginEngine.IPlugin plugin in pluginCol)
     {
         //获得Command接口并添加到Command集合中
         NBGIS.PluginEngine.ICommand cmd = plugin as NBGIS.PluginEngine.ICommand;
         if (cmd != null)
         {
             this._Commands.Add(cmd.ToString(), cmd);
             //找出该Command的Category,如果它还没有添加到Category则添加
             if (cmd.Category != null && _CommandCategory.Contains(cmd.Category) == false)
             {
                 _CommandCategory.Add(cmd.Category);
             }
             continue;
         }
         //获得ITool接口并添加到ITool集合中
         NBGIS.PluginEngine.ITool tool = plugin as NBGIS.PluginEngine.ITool;
         if (tool != null)
         {
             this._Tools.Add(tool.ToString(), tool);
             if (tool.Category != null && _CommandCategory.Contains(tool.Category) == false)
             {
                 _CommandCategory.Add(tool.Category);
             }
             continue;
         }
         //获得IToolBarDef接口并添加到IToolBarDef集合中
         NBGIS.PluginEngine.IToolBarDef toolbardef = plugin as NBGIS.PluginEngine.IToolBarDef;
         if (toolbardef != null)
         {
             this._ToolBars.Add(toolbardef.ToString(), toolbardef);
             continue;
         }
         //获得IMenuDef接口并添加到IMenuDef集合中
         NBGIS.PluginEngine.IMenuDef menudef = plugin as NBGIS.PluginEngine.IMenuDef;
         if (menudef != null)
         {
             this._Menus.Add(menudef.ToString(), menudef);
             continue;
         }
         //获得IDockableWindowDef接口并添加到IDockableWindowDef集合中
         NBGIS.PluginEngine.IDockableWindowDef dockablewindowdef = plugin as NBGIS.PluginEngine.IDockableWindowDef;
         if (dockablewindowdef != null)
         {
             this._DockableWindows.Add(dockablewindowdef.ToString(), dockablewindowdef);
             continue;
         }
     }
 }
Ejemplo n.º 5
0
        //解析插件集合中所有对象
        //将其分别装入ICommand、ITool、IToolBarDef、IMenuDef和IDockableWindows5个集合
        public static void  GetPluginArray(PluginCollection pluginCol)
        {
            foreach (NBGIS.PluginEngine.IPlugin plugin in pluginCol)
            {
                /////////////////
                NBGIS.PluginEngine.ICommand cmd = plugin as NBGIS.PluginEngine.ICommand;
                if (cmd != null)
                {
                    m_Commands.Add(cmd.ToString(), cmd);
                    //找出该Command的Category,如果它没有添加到Category中则添加
                    if (cmd.Category != null && (!m_CommandCategory.Contains(cmd.Category)))
                    {
                        m_CommandCategory.Add(cmd.Category);
                    }
                    continue;
                }
                ////////////////
                NBGIS.PluginEngine.ITool tool = plugin as NBGIS.PluginEngine.ITool;
                if (tool != null)
                {
                    m_Tools.Add(tool.ToString(), tool);
                    if (tool.Category != null && (!m_CommandCategory.Contains(tool.Category)))
                    {
                        m_CommandCategory.Add(tool.Category);
                    }
                    continue;
                }

                ////////////////
                NBGIS.PluginEngine.IToolBarDef toolbar = plugin as NBGIS.PluginEngine.IToolBarDef;
                if (toolbar != null)
                {
                    m_ToolBars.Add(toolbar.ToString(), toolbar);
                    continue;
                }
                ////////////////
                NBGIS.PluginEngine.IMenuDef menu = plugin as NBGIS.PluginEngine.IMenuDef;
                if (menu != null)
                {
                    m_Menus.Add(menu.ToString(), menu);
                    continue;
                }
                ////////////////
                NBGIS.PluginEngine.IDockableWindowDef dockableWindow = plugin as NBGIS.PluginEngine.IDockableWindowDef;
                if (dockableWindow != null)
                {
                    m_DockableWindows.Add(dockableWindow.ToString(), dockableWindow);
                    continue;
                }
            }
        }
Ejemplo n.º 6
0
        //主窗体Load事件
        private void MainGIS_Load(object sender, EventArgs e)
        {
            //从插件文件夹中获得实现了插件接口的对象
            NBGIS.PluginEngine.PluginCollection pluginCol = NBGIS.PluginEngine.PluginHandle.GetPluginsFromDll();


            //NBGIS.PluginEngine.ParsePluginCollection parsePluginCol = new NBGIS.PluginEngine.ParsePluginCollection();

            //解析这些插件对象,获得不同类型的插件集合
            //把插件集合解析成五种不同的类型存储在ParsePluginCollection对象属性中
            ParsePluginCollection.GetPluginArray(pluginCol);

            //从ParsePluginCollection提取出各种插件对象集合
            m_CommandCol = ParsePluginCollection.GetCommands;
            m_ToolCol    = ParsePluginCollection.GetTools;
            m_ToolBarCol = ParsePluginCollection.GetToolBars;
            m_MenuCol    = ParsePluginCollection.GetMenus;
            //m_DockableWindowCol = ParsePluginCollection.GetDockableWindows;

            //获得Command和Tool在UI层面上的Category属性
            foreach (string categoryName in ParsePluginCollection.GetCommandsCategorys)
            {
                this.uiCommandManager.Categories.Add(new Janus.Windows.UI.CommandBars.UICommandCategory(categoryName));
            }
            //创建插件的UI对象
            this.CreateUICommandAndTool(this.m_CommandCol, this.m_ToolCol);
            this.CreateUIToolBars(this.m_ToolBarCol);
            this.CreateUIMenus(this.m_MenuCol);


            // this.CreateUIDockableWindow(this.m_DockableWindowCol);

            //经过改进,动态创建DockableWindow
            //---------------------------------------------------------------
            NBGIS.PluginEngine.CreateUI.Application    = m_Application;
            NBGIS.PluginEngine.CreateUI.UIPanelManager = uiPanelManager;
            //-------------------------------------------------------------------



            this.m_MapControl.CurrentTool        = null;
            this.m_PageLayoutControl.CurrentTool = null;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 从DLL中获得插件对象并加入到插件容器
        /// </summary>
        /// <returns></returns>
        public static PluginCollection GetPluginsFromDll()
        {
            //存储插件的容器
            PluginCollection _PluginCol = new PluginCollection();

            //判断是否存在该文件夹,如果不存在则自动创建一个,避免异常
            if (!Directory.Exists(pluginFolder))
            {
                Directory.CreateDirectory(pluginFolder);
                if (AppLog.log.IsDebugEnabled)
                {
                    AppLog.log.Debug("plugin文件夹不存在,系统自带创建一个!");
                }
            }
            //获得插件文件夹中的每一个dll文件
            string[] _files = Directory.GetFiles(pluginFolder, "*.dll");
            foreach (string _file in _files)
            {
                //根据程序集文件名加载程序集
                Assembly _assembly = Assembly.LoadFrom(_file);
                if (_assembly != null)
                {
                    Type[] _types = null;
                    try
                    {
                        //获得程序集中定义的类型
                        _types = _assembly.GetTypes();
                    }
                    catch
                    {
                        if (AppLog.log.IsErrorEnabled)
                        {
                            AppLog.log.Error("反射类型加载异常!");
                        }
                    }
                    finally
                    {
                        foreach (Type _type in _types)
                        {
                            //获得一个类型所有实现的接口
                            Type[] _interfaces = _type.GetInterfaces();
                            //遍历接口类型
                            foreach (Type theInterface in _interfaces)
                            {
                                //如果满足某种类型,则添加到插件集合对象中
                                switch (theInterface.FullName)
                                {
                                //NBGIS.PluginEngine.
                                case "NBGIS.PluginEngine.ICommand":
                                case "NBGIS.PluginEngine.ITool":
                                case "NBGIS.PluginEngine.IMenuDef":
                                case "NBGIS.PluginEngine.IToolBarDef":
                                case "NBGIS.PluginEngine.IDockableWindowDef":
                                    getPluginObject(_PluginCol, _type);
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(_PluginCol);
        }
Ejemplo n.º 8
0
        public static PluginCollection GetPluginsFromDll()
        {
            //存储插件的容器
            PluginCollection pluginCol = new PluginCollection();

            //检测 插件文件夹是否存在,如果不存在则新建一个避免出现异常
            if (!Directory.Exists(pluginFolder))
            {
                Directory.CreateDirectory(pluginFolder);
                if (Applog.log.IsDebugEnabled)
                {
                    Applog.log.Debug("plugin文件夹不存在,系统自动建立一个");
                }
            }
            //获得插件文件夹中每一个dll文件
            string[] files = Directory.GetFiles(pluginFolder, "*.dll");
            foreach (string file in files)
            {
                //从Dll文件中加载程序集
                Assembly assembly = Assembly.LoadFrom(file);
                if (assembly != null)
                {
                    Type[] types = null;
                    try
                    {
                        //获取程序集中定义的类型
                        types = assembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        if (Applog.log.IsErrorEnabled)
                        {
                            Applog.log.Error("反射类型加载异常");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (Applog.log.IsErrorEnabled)
                        {
                            Applog.log.Error(ex.Message);
                        }
                    }
                    finally
                    {
                        foreach (Type type in types)
                        {
                            //获得一个类型所有实现的接口
                            Type[] interfaces = type.GetInterfaces();
                            //遍历接口类型
                            foreach (Type theInterface in interfaces)
                            {
                                //如果满足某种类型,则添加到插件集合对象中
                                switch (theInterface.FullName)
                                {
                                case "NBGIS.PluginEngine.ICommand":
                                case "NBGIS.PluginEngine.ITool":
                                case "NBGIS.PluginEngine.IMenuDef":
                                case "NBGIS.PluginEngine.IToolBarDef":
                                case "NBGIS.PluginEngine.IDockableWindowDef":
                                    GetPluginObject(pluginCol, type);
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(pluginCol);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the PluginCollectionEnumerator class.
 /// </summary>
 /// <param name="p_temp"></param>
 /// <param name="p_Enumerator"></param>
 public PluginCollectionEnumerator(PluginCollection mappings)
 {
     m_temp       = (IEnumerable)mappings;
     m_Enumerator = m_temp.GetEnumerator();
 }
Ejemplo n.º 10
0
 public PluginCollection(PluginCollection value)
 {
     this.AddRange(value);
 }