Ejemplo n.º 1
0
        /// <summary>
        /// 创建地图地图工具箱
        /// </summary>
        /// <param name="mapObject">地图控件对象</param>
        /// <returns></returns>
        private IMFToolBox CreateToolBox(object mapObject)
        {
            IMFToolBox _toolBox = null;

            #region 反射
            object      RetObj = null;
            object[]    obj    = new object[] { mapObject, this };
            LibraryInfo info   = GetLibraryInfoByName("MapTool", mapEngineType.ToString());
            if (info == null)
            {
                return(null);
            }

            try
            {
                Assembly asm = Assembly.Load(info.LibraryName);
                Type[]   tp  = asm.GetTypes();
                RetObj = (object)asm.CreateInstance(info.NameSpaceClass, true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase
                                                    , null, obj, CultureInfo.CurrentCulture, null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("通过反射创建IToolBox对象异常:{0}", ex.Message));
                return(null);
            }
            if (null == RetObj)
            {
                Debug.WriteLine("通过反射创建IToolBox对象失败!");
                return(null);
            }

            _toolBox = RetObj as IMFToolBox;
            #endregion

            return(_toolBox);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据类型和名称获取反射库的信息
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="engineType">地图类型</param>
        /// <returns></returns>
        private LibraryInfo GetLibraryInfoByName(string type, string engineType)
        {
            string xmlPath = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "MapFrame.Config.xml");

            if (!File.Exists(xmlPath))
            {
                return(null);
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlPath);

                string mapType;
                if (string.IsNullOrEmpty(engineType))
                {
                    XmlNode runNode = doc.SelectSingleNode("MapFrame/Run");
                    if (runNode == null)
                    {
                        return(null);
                    }
                    mapType = runNode.Attributes["value"].InnerXml;
                }
                else
                {
                    mapType = engineType;
                }

                LibraryInfo info = null;

                if (type == "MapEngine")
                {
                    XmlNode engineNode = doc.SelectSingleNode("MapFrame/MapEngine");
                    if (engineNode == null)
                    {
                        return(null);
                    }

                    XmlNodeList engineNodeList = engineNode.ChildNodes;
                    foreach (XmlNode n in engineNodeList)
                    {
                        if (n.Attributes["Type"].InnerXml != mapType)
                        {
                            continue;
                        }

                        info                = new LibraryInfo();
                        info.LibraryName    = n.Attributes["LibraryName"].InnerXml;
                        info.NameSpaceClass = n.Attributes["NameSpace.Class"].InnerXml;
                        break;
                    }
                }
                else if (type == "MapTool")
                {
                    XmlNode toolNode = doc.SelectSingleNode("MapFrame/MapTool");
                    if (toolNode == null)
                    {
                        return(null);
                    }

                    XmlNodeList toolNodeList = toolNode.ChildNodes;
                    foreach (XmlNode n in toolNodeList)
                    {
                        if (n.Attributes["Type"].InnerXml != mapType)
                        {
                            continue;
                        }

                        info                = new LibraryInfo();
                        info.LibraryName    = n.Attributes["LibraryName"].InnerXml;
                        info.NameSpaceClass = n.Attributes["NameSpace.Class"].InnerXml;
                        break;
                    }
                }

                return(info);
            }
            catch
            {
                throw;
            }
        }