public static void TestAutoUpdate() { try { var service = TCSoftServiceBus.Current; service.Stop(); int count = 0; //优先保障服务正常结束 while (count < 10 && service.Status != ServiceStatus.Stoped) { if (service.Status == ServiceStatus.Running) { service.Stop(); } Thread.Sleep(1000); count++; } AutoUpdaterInfo info = AutoUpdaterInfo.Current; AppUnitity.RunAutoUpdaterProcess(info.ExcuteFileName); AppUnitity.KillOrStop(info.ExcuteFileName, info.IsWindowService, true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void BtnUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(_autoUpdaterInfo.DownloadUrl)) { _logger.Error("FrmUpdateCheck.BtnUpdate_Click.待下载文件无效"); MessageBox.Show("待下载文件无效"); if (_autoUpdaterInfo.IsWindowService) { AppUnitity.Restart(_autoUpdaterInfo.ExcuteFileName, _autoUpdaterInfo.IsWindowService); } return; } if (MessageBox.Show("升级系统要求先关闭程序,你是否确定升级系统?", "拓创自动升级程序", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } AppUnitity.KillOrStop(_autoUpdaterInfo.ExcuteFileName, _autoUpdaterInfo.IsWindowService); FrmDownloadProgress progress = new FrmDownloadProgress(_autoUpdaterInfo); var result = progress.ShowDialog(this); if (result == DialogResult.OK || result == DialogResult.Yes) { AppUnitity.Restart(_autoUpdaterInfo.ExcuteFileName, _autoUpdaterInfo.IsWindowService); } else { if (_autoUpdaterInfo.IsWindowService) { AppUnitity.Restart(_autoUpdaterInfo.ExcuteFileName, _autoUpdaterInfo.IsWindowService); } this.Close(); } }
private void UpdateListener(AutoUpdaterInfo info, MqAutoUpdateInfo data) { if (data.ForceUpdate) { info.Version = string.Empty; } info.NewVersion = data.Version; if (!info.HasNewVersion()) { _listenerService.UpdateStatus(data.AppId, AppStatus.Running); _logger.Error("本地已经是最新版本包"); //已经处理 return; } if (string.IsNullOrEmpty(info.ExcuteFileName)) { info.ExcuteFileName = "TCSoft.MqListener.exe"; } if (string.IsNullOrEmpty(info.AppName)) { info.AppName = "拓创消息调度程序"; } info.AppType = (int)AppType.MqListener; info.LastUpdateTime = data.PublishTime; info.DownloadUrl = data.Url; info.Save(); _listenerService.Deploy(data.AppId); AppUnitity.RunAutoUpdaterProcess(info.ExcuteFileName); }
public static void RunAutoUpdate() { var updateInfo = AutoUpdaterInfo.Current; if (!updateInfo.HasNewVersion() || string.IsNullOrWhiteSpace(updateInfo.DownloadUrl)) { LoggerFactory.GetLog().Error("下载文件无效或当前版本已经是最新版本!"); return; } AppUnitity.KillOrStop(updateInfo.ExcuteFileName, updateInfo.IsWindowService); AutoUpdateBackgroupService service = new AutoUpdateBackgroupService(updateInfo); service.Run(); while (!service.HasCompleted) { Thread.Sleep(1000); } LoggerFactory.GetLog().Error("重启应用程序!"); AppUnitity.Restart(updateInfo.ExcuteFileName, updateInfo.IsWindowService); }
private void ShowErrorAndRestartApplication(string message) { MessageBox.Show(message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); _logger.Error(message + ".ShowErrorAndRestartApplication"); AppUnitity.Restart(_updaterInfo.ExcuteFileName, _updaterInfo.IsWindowService); }