public NovelRequestHandler(ProxyInfo proxy, DelayInfo delay) { base.LogFile = Constants.FILE_LOG; base.Proxy = proxy; base.Delay = delay; base.Initial(); }
public static ProxyInfo GetProxy() { ProxyInfo proxy = new ProxyInfo(); proxy.Enable = Properties.Settings.Default.ProxyEnabled; proxy.Server = Properties.Settings.Default.ProxyServer; proxy.Port = DataConvert.GetInt32(Properties.Settings.Default.ProxyPort); proxy.UserName = Properties.Settings.Default.ProxyUser; proxy.Password = Properties.Settings.Default.ProxyPass; return proxy; }
public bool Compare(ProxyInfo newproxy) { if (this.Enable == newproxy.Enable && this.Server == newproxy.Server && this.Port == newproxy.Port && this.UserName == newproxy.UserName && this.Password == newproxy.Password) { return true; } else return false; }
public static bool SetProxy(ProxyInfo proxy) { try { Properties.Settings.Default.ProxyEnabled = proxy.Enable; Properties.Settings.Default.ProxyServer = proxy.Server; Properties.Settings.Default.ProxyPort = DataConvert.GetString(proxy.Port); Properties.Settings.Default.ProxyUser = proxy.UserName; Properties.Settings.Default.ProxyPass = proxy.Password; Properties.Settings.Default.Save(); } catch { return false; } return true; }
public static bool SetProxy(ProxyInfo proxy) { try { XmlDocument objXmlDoc = GetMainConfigFile(); if (objXmlDoc == null) return false; XmlNode nodeRoot = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT); XmlNode objNode = GetAppendNode(nodeRoot, objXmlDoc, Constants.CONFIG_PROXY, ""); if (objNode.Attributes[Constants.PROXY_ENABLE] == null) objNode.Attributes.Append(objXmlDoc.CreateAttribute(Constants.PROXY_ENABLE)); objNode.Attributes[Constants.PROXY_ENABLE].InnerText = proxy.Enable.ToString(); GetAppendNode(objNode, objXmlDoc, Constants.PROXY_SERVER, "").InnerText = DataConvert.GetString(proxy.Server); GetAppendNode(objNode, objXmlDoc, Constants.PROXY_PORT, "").InnerText = DataConvert.GetString(proxy.Port); GetAppendNode(objNode, objXmlDoc, Constants.PROXY_USER, "").InnerText = DataConvert.GetString(proxy.UserName); GetAppendNode(objNode, objXmlDoc, Constants.PROXY_PASS, "").InnerText = DataConvert.GetString(proxy.Password); return SetMainConfigFile(objXmlDoc); } catch (Exception ex) { LogHelper.Write("ConfigCtrl.SetProxy()", ex); return false; } }
public static ProxyInfo GetProxy() { try { XmlDocument objXmlDoc = GetMainConfigFile(); if (objXmlDoc == null) return null; XmlNode nodeRoot = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT); XmlNode objNode = GetAppendNode(nodeRoot, objXmlDoc, Constants.CONFIG_PROXY, ""); ProxyInfo proxy = new ProxyInfo(); if (objNode.Attributes[Constants.PROXY_ENABLE] != null) proxy.Enable = DataConvert.GetBool(objNode.Attributes[Constants.PROXY_ENABLE].Value); else proxy.Enable = false; proxy.Server = DataConvert.GetString(GetAppendNode(objNode, objXmlDoc, Constants.PROXY_SERVER, "").InnerText); GetAppendNode(objNode, objXmlDoc, Constants.PROXY_PORT, ""); if (objNode.SelectSingleNode(Constants.PROXY_PORT).InnerText == string.Empty) proxy.Port = null; else proxy.Port = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.PROXY_PORT).InnerText); proxy.UserName = DataConvert.GetString(GetAppendNode(objNode, objXmlDoc, Constants.PROXY_USER, "").InnerText); proxy.Password = DataConvert.GetString(GetAppendNode(objNode, objXmlDoc, Constants.PROXY_PASS, "").InnerText); return proxy; } catch (Exception ex) { LogHelper.Write("ConfigCtrl.GetProxy()", ex); throw; } }
internal void CheckVersion(bool IsStartUp, bool IsManually) { try { //load config info string folder = Path.Combine(Application.StartupPath, Constants.FOLDER_MASTERDATA); if (!Directory.Exists(folder)) return; string configFile = ""; string newVersion = ""; string currentVersion = ""; if (IsStartUp) Thread.Sleep(7000); _proxyinfo = ConfigCtrl.GetProxy(); _webclientHelper.SetProxy(_proxyinfo.Server, _proxyinfo.Port, _proxyinfo.UserName, _proxyinfo.Password); if (_proxyinfo.Enable) _webclientHelper.EnableProxy(); Stream updatestream = null; try { // Download the update info file to the memory, updatestream = _webclientHelper.OpenRead(REMOTE_URI + UPDATE_FILE); } catch (Exception ex) { LogHelper.Write("Download masterdata.xml", REMOTE_URI + UPDATE_FILE, ex, LogSeverity.Error); return; } if (updatestream == null) { LogHelper.Write("Download masterdata.xml", REMOTE_URI + UPDATE_FILE, LogSeverity.Error); return; } // read and close the stream using (System.IO.StreamReader streamReader = new System.IO.StreamReader(updatestream, System.Text.Encoding.GetEncoding("GB2312"))) { string updateInfo = streamReader.ReadToEnd(); // if something was read if (!string.IsNullOrEmpty(updateInfo)) { XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.LoadXml(updateInfo); DataView dv = GetData(objXmlDoc, "MasterData/UpdateFileList"); string[] arr = new string[dv.Table.Rows.Count]; for (int ix = 0; ix < dv.Table.Rows.Count; ix++) { //load config info folder = Path.Combine(Application.StartupPath, Constants.FOLDER_MASTERDATA); configFile = folder + Constants.CHAR_DOUBLEBACKSLASH + dv.Table.Rows[ix][0].ToString(); if (!File.Exists(configFile)) { arr[ix] = dv.Table.Rows[ix][0].ToString(); continue; } newVersion = dv.Table.Rows[ix][1].ToString(); if (String.IsNullOrEmpty(newVersion)) { LogHelper.Write("Get newVersion", dv.Table.Rows[ix][0].ToString(), LogSeverity.Warn); continue; } currentVersion = GetCurrentVersion(configFile); if (String.IsNullOrEmpty(currentVersion)) { arr[ix] = dv.Table.Rows[ix][0].ToString(); continue; } if (CompareVersions(currentVersion, newVersion)) { arr[ix] = dv.Table.Rows[ix][0].ToString(); } } bool needDownload = false; for (int ix = 0; ix < arr.Length; ix++) { if (!String.IsNullOrEmpty(arr[ix])) { needDownload = true; break; } } if (needDownload) { if (NewVersionFound != null) NewVersionFound(arr); } else { if (IsManually) { if (LatestVersionConfirmed != null) LatestVersionConfirmed(); } } } } } catch (Exception ex) { LogHelper.Write("MasterDataUpdate.CheckVersion", ex, LogSeverity.Error); } }