private void InitForm() { UpdExeName = Path.GetFileNameWithoutExtension(Application.ExecutablePath); pbUpdate.Minimum = 0; pbUpdate.Value = pbUpdate.Minimum; UpdateUrl = OperatingXML.GetValue("UpdateUrl"); strTemp = System.IO.Path.GetFullPath(Path.GetTempPath() + "//Update//"); AppName = OperatingXML.GetValue("AppName"); AppService = GetAppConfigAdress(); if (string.IsNullOrEmpty(UpdateUrl)) { MessageBox.Show("更新地址配置不正确,请配置后重试!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } if (string.IsNullOrEmpty(AppName)) { MessageBox.Show("更新程序名配置不正确,请配置后重试!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } if (!string.IsNullOrEmpty(AppService) && !CompareUrl()) { if (MessageBox.Show(string.Format("更新地址【{0}】与服务地址【{1}】不在同一服务器上,是否继续更新?", UpdateUrl, AppService), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { Application.Exit(); } } }
private string GetAppConfigAdress() { try { if (string.IsNullOrEmpty(AppName)) { AppName = OperatingXML.GetValue("AppName"); } string strPath = Path.Combine(Environment.CurrentDirectory, AppName + ".config"); if (!File.Exists(strPath)) { return(string.Empty); } XmlDocument xd = new XmlDocument(); string strValue = string.Empty; xd.Load(strPath); XmlNode xn; //string s = xd.SelectSingleNode("configuration").SelectSingleNode("system.serviceModel").SelectSingleNode("client").SelectSingleNode(name).OuterXml; xn = xd.SelectSingleNode("configuration"); if (xn == null) { return(string.Empty); } xn = xn.SelectSingleNode("system.serviceModel"); if (xn == null) { return(string.Empty); } xn = xn.SelectSingleNode("client"); if (xn == null) { return(string.Empty); } xn = xn.SelectSingleNode("endpoint"); if (xn == null) { return(string.Empty); } xn = xn.Attributes.GetNamedItem("address"); if (xn == null) { return(string.Empty); } string strAddress = xn.Value; return(strAddress); } catch //(System.Exception ex) { return(string.Empty); } }