private void btnOK_Click(object sender, EventArgs e) { try { if ((txtPort.Text != string.Empty) && !DataValidation.IsNaturalNumber(txtPort.Text)) { MessageBox.Show("端口必须为整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); txtPort.Select(); return; } ProxyInfo proxy = new ProxyInfo(); proxy.Enable = chkProxy.Checked; proxy.Server = txtSever.Text; if (txtPort.Text != string.Empty) proxy.Port = DataConvert.GetInt32(txtPort.Text); else proxy.Port = null; proxy.UserName = txtUserName.Text; proxy.Password = txtPassword.Text; if (!ConfigCtrl.SetProxy(proxy)) { MessageBox.Show("保存失败!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { Program.ShowMessageBox("DlgProxySetting", ex); } }
public static ProxyInfo GetProxy() { try { XmlDocument objXmlDoc = GetAssistantConfigFile(); if (objXmlDoc == null) return null; ProxyInfo proxy = new ProxyInfo(); XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.PROXY_PROXY); if (objNode == null) return null; if (objNode.Attributes[Constants.PROXY_ENABLE] != null) proxy.Enable = DataConvert.GetBool(objNode.Attributes[Constants.PROXY_ENABLE].Value); else proxy.Enable = false; proxy.Server = objNode.SelectSingleNode(Constants.PROXY_SERVER).InnerText; 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 = objNode.SelectSingleNode(Constants.PROXY_USER).InnerText; proxy.Password = objNode.SelectSingleNode(Constants.PROXY_PASS).InnerText; return proxy; } catch (Exception ex) { LogHelper.Write("读取代理设置", ex); throw; } }
public static bool SetProxy(ProxyInfo proxy) { try { XmlDocument objXmlDoc = GetAssistantConfigFile(); if (objXmlDoc == null) return false; XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.PROXY_PROXY); if (objNode == null) return false; if (objNode.Attributes[Constants.PROXY_ENABLE] == null) objNode.Attributes.Append(objXmlDoc.CreateAttribute(Constants.PROXY_ENABLE)); objNode.Attributes[Constants.PROXY_ENABLE].InnerText = proxy.Enable.ToString(); objNode.SelectSingleNode(Constants.PROXY_SERVER).InnerText = proxy.Server; objNode.SelectSingleNode(Constants.PROXY_PORT).InnerText = proxy.Port.ToString(); objNode.SelectSingleNode(Constants.PROXY_USER).InnerText = proxy.UserName; objNode.SelectSingleNode(Constants.PROXY_PASS).InnerText = proxy.Password; return SetAssistantConfigFile(objXmlDoc); } catch (Exception ex) { LogHelper.Write("保存代理设置", ex); return false; } }
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); } }