public void LoadHttpHeaderSetting(Setting.Setting.HttpHeaderStruct header) { if (header.HttpHeaderList != null) { foreach (var i in header.HttpHeaderList) { ListViewItem item = new ListViewItem(new string[] { i.Key, i.Value }); lv_header.Items.Add(item); } } }
public Setting.Setting.HttpHeaderStruct SaveHttpHeaderSetting() { Setting.Setting.HttpHeaderStruct httpHeader = new Setting.Setting.HttpHeaderStruct(); httpHeader.HttpHeaderList = new Dictionary <string, string>(); foreach (ListViewItem item in lv_header.Items) { string key = item.SubItems[0].Text; string value = item.SubItems[1].Text; if (!httpHeader.HttpHeaderList.ContainsKey(key)) { httpHeader.HttpHeaderList.Add(key, value); } } return(httpHeader); }
/// <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(); }
private static Setting.Setting.HttpHeaderStruct ReadHttpHeaderNode(XmlNode child) { Setting.Setting.HttpHeaderStruct httpHeader = new Setting.Setting.HttpHeaderStruct(); httpHeader.HttpHeaderList = new Dictionary <string, string>(); foreach (XmlNode c in child.ChildNodes) { if (c.Name == "key") { //判断name属性是否存在 if (c.Attributes["name"] == null) { continue; } string name = c.Attributes["name"].Value; string value = c.InnerText; if (!string.IsNullOrWhiteSpace(name) && !httpHeader.HttpHeaderList.ContainsKey(name)) { httpHeader.HttpHeaderList.Add(name, value); } } } return(httpHeader); }
private static Setting.Setting.HttpHeaderStruct ReadHttpHeaderNode(XmlNode child) { Setting.Setting.HttpHeaderStruct httpHeader = new Setting.Setting.HttpHeaderStruct(); httpHeader.HttpHeaderList = new Dictionary<string, string>(); foreach (XmlNode c in child.ChildNodes) { if (c.Name == "key") { //判断name属性是否存在 if (c.Attributes["name"] == null) continue; string name = c.Attributes["name"].Value; string value = c.InnerText; if (!string.IsNullOrWhiteSpace(name) && !httpHeader.HttpHeaderList.ContainsKey(name)) { httpHeader.HttpHeaderList.Add(name, value); } } } return httpHeader; }