private static Setting.Setting.ProxyStruct ReadProxyNode(XmlNode child) { Setting.Setting.ProxyStruct proxy = new Setting.Setting.ProxyStruct(); foreach (XmlNode c in child.ChildNodes) { if (c.Name == "type") { int tmp; string type = c.InnerText; switch (type) { case "1": tmp = 1; break; case "2": tmp = 2; break; default: tmp = 0; break; } proxy.IsNoOrIeOrCustomProxy = tmp; } else if (c.Name == "customProxy") { //判断属性是否存在 if (c.Attributes["address"] == null || c.Attributes["port"] == null || c.Attributes["user"] == null || c.Attributes["password"] == null || c.Attributes["domain"] == null) { continue; } string address = c.Attributes["address"].Value; string port = c.Attributes["port"].Value; string user = c.Attributes["user"].Value; string password = c.Attributes["password"].Value; string domain = c.Attributes["domain"].Value; proxy.ProxyAddr = address; proxy.ProxyPort = port; proxy.ProxyUser = user; proxy.ProxyPassword = password; proxy.ProxyDomain = domain; } } return(proxy); }
public Setting.Setting.ProxyStruct SaveProxySetting() { //获取当前窗口配置 GetProxySetting(); //组合为ProxyStruct Setting.Setting.ProxyStruct proxy = new Setting.Setting.ProxyStruct(); proxy.IsNoOrIeOrCustomProxy = _isProxy; proxy.ProxyAddr = _proxyAddr; proxy.ProxyPort = _proxyPort; proxy.ProxyUser = _proxyUser; proxy.ProxyPassword = _proxyPasswd; proxy.ProxyDomain = _proxyDomain; return(proxy); }
/// <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); } }
/// <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; }
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(); }
public void LoadProxySetting(Setting.Setting.ProxyStruct proxy) { if (proxy.IsNoOrIeOrCustomProxy == 0) { radioButton_noProxy.Checked = true; } else if (proxy.IsNoOrIeOrCustomProxy == 1) { radioButton_ieProxy.Checked = true; } else if (proxy.IsNoOrIeOrCustomProxy == 2) { radioButton_customProxy.Checked = true; } else { radioButton_noProxy.Checked = true; } textBox_proxyAddr.Text = proxy.ProxyAddr; textBox_proxyPort.Text = proxy.ProxyPort; textBox_proxyUser.Text = proxy.ProxyUser; textBox_proxyPasswd.Text = proxy.ProxyPassword; textBox_proxyDomain.Text = proxy.ProxyDomain; }
private static Setting.Setting.ProxyStruct ReadProxyNode(XmlNode child) { Setting.Setting.ProxyStruct proxy = new Setting.Setting.ProxyStruct(); foreach (XmlNode c in child.ChildNodes) { if (c.Name == "type") { int tmp; string type = c.InnerText; switch (type) { case "1": tmp = 1; break; case "2": tmp = 2; break; default: tmp = 0; break; } proxy.IsNoOrIeOrCustomProxy = tmp; } else if (c.Name == "customProxy") { //判断属性是否存在 if (c.Attributes["address"] == null ||c.Attributes["port"] == null ||c.Attributes["user"] == null ||c.Attributes["password"] == null ||c.Attributes["domain"] == null) continue; string address = c.Attributes["address"].Value; string port = c.Attributes["port"].Value; string user = c.Attributes["user"].Value; string password = c.Attributes["password"].Value; string domain = c.Attributes["domain"].Value; proxy.ProxyAddr = address; proxy.ProxyPort = port; proxy.ProxyUser = user; proxy.ProxyPassword = password; proxy.ProxyDomain = domain; } } return proxy; }