Ejemplo n.º 1
0
 public Setting.Setting.PolicyStruct SavePolicySetting()
 {
     Setting.Setting.PolicyStruct policy = new Setting.Setting.PolicyStruct();
     policy.IsParamRandom    = checkBox_IsParamRandom.Checked;
     policy.IsShowDisclaimer = checkBox_IsShowDisclaimer.Checked;
     return(policy);
 }
Ejemplo n.º 2
0
 private static Setting.Setting.PolicyStruct ReadPolicyNode(XmlNode child)
 {
     Setting.Setting.PolicyStruct policy = new Setting.Setting.PolicyStruct();
     foreach (XmlNode c in child.ChildNodes)
     {
         if (c.Name == "isParamRandom")
         {
             policy.IsParamRandom = DataConvert.StrToBool(c.InnerText);
         }
     }
     return(policy);
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 读xml文件
 /// </summary>
 public static Setting.Setting ReadXml(string fileName, string basePathDir)
 {
     string filePath = basePathDir + fileName;
     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 == "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(userAgent, httpHeader,policy,proxy);
         return setting;
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return null;
 }
Ejemplo n.º 5
0
 private void SaveAllSetting()
 {
     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();
     //生成userAgent
     userAgent = _saveUserAgentSetting();
     //生成httpHeader
     httpHeader = _saveHttpHeaderSetting();
     //生成policy
     policy = _savePolicySetting();
     //生成proxy
     proxy = _saveProxySetting();
     //生成Setting
     Setting.Setting setting = new Setting.Setting(userAgent, httpHeader, policy, proxy);
     //保存Setting到xml
     InitWorker.SaveSettingToXml(setting);
     //重新初始化GlobalSetting
     InitWorker.InitGlobalSetting();
 }
Ejemplo n.º 6
0
 public void LoadPolicySetting(Setting.Setting.PolicyStruct policy)
 {
     checkBox_IsParamRandom.Checked    = policy.IsParamRandom;
     checkBox_IsShowDisclaimer.Checked = policy.IsShowDisclaimer;
 }
Ejemplo n.º 7
0
 private static Setting.Setting.PolicyStruct ReadPolicyNode(XmlNode child)
 {
     Setting.Setting.PolicyStruct policy = new Setting.Setting.PolicyStruct();
     foreach (XmlNode c in child.ChildNodes)
     {
         if (c.Name == "isParamRandom")
         {
             policy.IsParamRandom = DataConvert.StrToBool(c.InnerText);
         }
     }
     return policy;
 }