internal void CheckVersion(bool IsStartUp, bool IsManually) { try { if (IsStartUp) { Thread.Sleep(7000); } WebClientHelper webclientHelper = new WebClientHelper(); ProxyInfo 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 update.xml", REMOTE_URI + UPDATE_FILE, ex, LogSeverity.Error); return; } if (updatestream == null) { LogHelper.Write("Download update.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)) { //LogHelper.Write("Johnny.Kaixin.WinUI.AutoUpdate.CheckVersion.updateInfo:", updateInfo, LogSeverity.Info); string newVersion = JsonHelper.GetMid(updateInfo, "<Version Num = \"", "\"/>"); if (String.IsNullOrEmpty(newVersion)) { LogHelper.Write("Get Version", "newVersion is null", LogSeverity.Info); return; } if (CompareVersions(Assembly.GetExecutingAssembly().GetName().Version.ToString(), newVersion)) { // Download the auto update program to the application // path, so you always have the last version runing if (webclientHelper.DownloadFile(REMOTE_URI + "AutoUpdate.exe", Application.StartupPath + "\\AutoUpdate.exe")) { if (NewVersionFound != null) { NewVersionFound(newVersion, Application.StartupPath + "\\AutoUpdate.exe", System.Web.HttpUtility.UrlEncode(updateInfo)); } } else { LogHelper.Write("Download AutoUpdate.exe failed", REMOTE_URI + "AutoUpdate.exe", LogSeverity.Error); return; } } else if (IsManually) { if (LatestVersionConfirmed != null) { LatestVersionConfirmed(Assembly.GetExecutingAssembly().GetName().Version.ToString()); } } } } } catch (Exception ex) { LogHelper.Write("AutoUpdate.CheckVersion", ex, LogSeverity.Error); } }
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); } }
internal void CheckVersion(bool IsStartUp, bool IsManually) { try { if (IsStartUp) Thread.Sleep(7000); WebClientHelper webclientHelper = new WebClientHelper(); ProxyInfo 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 update.xml", REMOTE_URI + UPDATE_FILE, ex, LogSeverity.Error); return; } if (updatestream == null) { LogHelper.Write("Download update.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)) { //LogHelper.Write("Johnny.Kaixin.WinUI.AutoUpdate.CheckVersion.updateInfo:", updateInfo, LogSeverity.Info); string newVersion = JsonHelper.GetMid(updateInfo, "<Version Num = \"", "\"/>"); if (String.IsNullOrEmpty(newVersion)) { LogHelper.Write("Get Version", "newVersion is null", LogSeverity.Info); return; } if (CompareVersions(Assembly.GetExecutingAssembly().GetName().Version.ToString(), newVersion)) { // Download the auto update program to the application // path, so you always have the last version runing if (webclientHelper.DownloadFile(REMOTE_URI + "AutoUpdate.exe", Application.StartupPath + "\\AutoUpdate.exe")) { if (NewVersionFound != null) NewVersionFound(newVersion, Application.StartupPath + "\\AutoUpdate.exe", System.Web.HttpUtility.UrlEncode(updateInfo)); } else { LogHelper.Write("Download AutoUpdate.exe failed", REMOTE_URI + "AutoUpdate.exe", LogSeverity.Error); return; } } else if (IsManually) { if (LatestVersionConfirmed != null) LatestVersionConfirmed(Assembly.GetExecutingAssembly().GetName().Version.ToString()); } } } } catch (Exception ex) { LogHelper.Write("AutoUpdate.CheckVersion", ex, LogSeverity.Error); } }