Пример #1
0
        /// <summary>
        /// 读xml文件
        /// </summary>
        public static Setting.Setting ReadXml(string fileName, string basePathDir)
        {
            string filePath = basePathDir + fileName;

            Setting.Setting.BasicStruct      basic      = new Setting.Setting.BasicStruct();
            Setting.Setting.UserAgentStruct  userAgent  = new Setting.Setting.UserAgentStruct();
            Setting.Setting.HttpHeaderStruct httpHeader = new Setting.Setting.HttpHeaderStruct();
            Setting.Setting.PolicyStruct     policy     = new Setting.Setting.PolicyStruct();
            Setting.Setting.ProxyStruct      proxy      = new Setting.Setting.ProxyStruct();
            try
            {
                //Setting setting = new Setting();
                XmlDocument xml = new XmlDocument();                            //初始化一个xml实例
                xml.Load(filePath);                                             //导入指定xml文件
                XmlNode     root      = xml.SelectSingleNode("/AltmanSetting"); //指定一个节点
                XmlNodeList childlist = root.ChildNodes;                        //获取节点下所有直接子节点
                foreach (XmlNode child in childlist)
                {
                    if (child.Name == "Basic")
                    {
                        basic = ReadBasicNode(child);
                    }
                    else if (child.Name == "UserAgent")
                    {
                        userAgent = ReadUserAgentNode(child);
                    }
                    else if (child.Name == "HttpHeader")
                    {
                        httpHeader = ReadHttpHeaderNode(child);
                    }
                    else if (child.Name == "Policy")
                    {
                        policy = ReadPolicyNode(child);
                    }
                    else if (child.Name == "Proxy")
                    {
                        proxy = ReadProxyNode(child);
                    }
                }
                Setting.Setting setting = new Setting.Setting(basic, userAgent, httpHeader, policy, proxy);
                return(setting);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
 private static Setting.Setting.BasicStruct ReadBasicNode(XmlNode child)
 {
     //初始化一下userAgent
     Setting.Setting.BasicStruct basic = new Setting.Setting.BasicStruct();
     foreach (XmlNode c in child.ChildNodes)
     {
         if (c.Name == "language")
         {
             basic.Language = c.InnerText;
         }
         if (c.Name == "isShowDisclaimer")
         {
             basic.IsShowDisclaimer = DataConvert.StrToBool(c.InnerText);
         }
         if (c.Name == "isOpenIPythonSupport")
         {
             basic.IsOpenIPythonSupport = DataConvert.StrToBool(c.InnerText);
         }
     }
     return(basic);
 }
Пример #3
0
		private static Setting.Setting.BasicStruct ReadBasicNode(XmlNode child)
		{
			//初始化一下userAgent
			Setting.Setting.BasicStruct basic = new Setting.Setting.BasicStruct();
			foreach (XmlNode c in child.ChildNodes)
			{
				if (c.Name == "language")
				{
					basic.Language = c.InnerText;
				}
				if (c.Name == "isShowDisclaimer")
				{
					basic.IsShowDisclaimer = DataConvert.StrToBool(c.InnerText);
				}
				if (c.Name == "isOpenIPythonSupport")
				{
					basic.IsOpenIPythonSupport = DataConvert.StrToBool(c.InnerText);
				}
			}
			return basic;
		}
Пример #4
0
        /// <summary>
        /// 读xml文件
        /// </summary>
        public static Setting.Setting ReadXml(string fileName, string basePathDir)
        {
            string filePath = basePathDir + fileName;
			Setting.Setting.BasicStruct basic = new Setting.Setting.BasicStruct();
            Setting.Setting.UserAgentStruct userAgent=new Setting.Setting.UserAgentStruct();
            Setting.Setting.HttpHeaderStruct httpHeader=new Setting.Setting.HttpHeaderStruct();
            Setting.Setting.PolicyStruct policy=new Setting.Setting.PolicyStruct();
            Setting.Setting.ProxyStruct proxy=new Setting.Setting.ProxyStruct();
            try
            {
                //Setting setting = new Setting();
                XmlDocument xml = new XmlDocument(); //初始化一个xml实例
                xml.Load(filePath); //导入指定xml文件
                XmlNode root = xml.SelectSingleNode("/AltmanSetting"); //指定一个节点
                XmlNodeList childlist = root.ChildNodes; //获取节点下所有直接子节点
                foreach (XmlNode child in childlist)
                {
					if (child.Name == "Basic")
					{
						basic = ReadBasicNode(child);
					}
                    else if (child.Name == "UserAgent")
                    {
                        userAgent = ReadUserAgentNode(child);
                    }
                    else if (child.Name == "HttpHeader")
                    {
                        httpHeader = ReadHttpHeaderNode(child);
                    }
                    else if (child.Name == "Policy")
                    {
                        policy = ReadPolicyNode(child);
                    }
                    else if (child.Name == "Proxy")
                    {
                        proxy = ReadProxyNode(child);
                    }
                }
				Setting.Setting setting = new Setting.Setting(basic, userAgent, httpHeader, policy, proxy);
                return setting;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }