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 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); } }
public void Vistor(TopicName topicName, MqCommandInfo commandInfo) { if (topicName != TopicName.PushMessage && commandInfo.MessageType != NMSMessageType.AutoUpdateInfo) { return; } var data = JsonUtils.Deserialize <MqAutoUpdateInfo>(commandInfo.Body); if (data == null) { _logger.Error("自动更新数据包无效 Body:" + commandInfo.Body); return; } if (data.AppType != AppType.MqListener) { _logger.Error("自动更新AppType无效:" + data.AppType.ToString() + " Body:" + commandInfo.Body); return; } var clientId = ProcessLockHelper.GetProcessLockId(); if (!string.Equals(clientId, data.AppId, StringComparison.OrdinalIgnoreCase)) { _logger.Error("自动更新数据包客户ID不匹配" + data.AppId + " Body:" + commandInfo.Body); return; } AutoUpdaterInfo info = AutoUpdaterInfo.Current; UpdateListener(info, data); }
public AutoUpdateBackgroupService(AutoUpdaterInfo updaterInfo) { _updaterInfo = updaterInfo; _autoUpdaterService = new AutoUpdaterService(); _autoUpdaterService.CompletedCallBack += AutoUpdaterServiceOnCompletedCallBack; _autoUpdaterService.DownloadProgressChanged += AutoUpdaterServiceOnDownloadProgressChanged; _autoUpdaterService.DownloadCompleted += AutoUpdaterServiceOnDownloadCompleted; _logger = LoggerFactory.GetLog(RunConfig.Current.LoggerType); }
public void Excute(AutoUpdaterInfo info, bool redownLoad = false) { try { DownLoad(info, redownLoad); } catch (Exception ex) { OnCompletedCallBack(ex.Message, false); } }
private void BtnCheckVersion_Click(object sender, EventArgs e) { try { var url = string.Format("{0}/api/CheckUpdate", CommonUnitity.ApiDomainUrl); var result = ApiHttpClient.GetByApiResult <ApiResult <MqAutoUpdateInfo> >(url); var info = AutoUpdaterInfo.Current; if (result != null && result.Data != null && !string.IsNullOrEmpty(result.Data.Url)) { var data = result.Data; info.NewVersion = data.Version; info.LastUpdateTime = data.PublishTime; if (!info.HasNewVersion()) { //已经处理 this.BtnUpdate.Visible = false; _logger.Information(string.Format("BtnCheckVersion_Click.暂无更新 result.Data.Url={0}", result.Data.Url)); MessageBox.Show("暂无更新"); return; } if (string.IsNullOrEmpty(info.ExcuteFileName)) { info.ExcuteFileName = "TCSoft.MqListener.exe"; } if (string.IsNullOrEmpty(info.AppName)) { info.AppName = "拓创消息调度程序"; } info.AppType = data.AppType; info.LastUpdateTime = data.PublishTime; info.DownloadUrl = data.Url; info.Save( ); this.BtnUpdate.Visible = true; MessageBox.Show("有新版本更新"); _logger.Information("BtnCheckVersion_Click.有新版本更新"); } else { MessageBox.Show("暂无更新"); _logger.Information("BtnCheckVersion_Click.暂无更新 result.Data.Url=null"); } this.lbAppName.Text = info.AppName; this.lbNewVersion.Text = info.NewVersion; this.lbVersion.Text = info.Version; _autoUpdaterInfo = info; } catch (Exception exception) { _logger.Error(exception, "BtnCheckVersion_Click"); MessageBox.Show(exception.Message); } }
private void DownLoad(AutoUpdaterInfo info, bool redownLoad = false) { if (string.IsNullOrEmpty(info.DownloadUrl)) { OnCompletedCallBack("下载文件无效", false); return; } var filename = Path.GetFileName(info.DownloadUrl); var downloadFolder = CommonUnitity.GetDownLoadFolder(); var fullname = Path.Combine(downloadFolder, filename); var subFolderList = Directory.EnumerateDirectories(downloadFolder); foreach (var tempFolder in subFolderList) { Directory.Delete(tempFolder, true); } if (File.Exists(fullname)) { //如果已经存在该文件,且文件版本号和新文件版本号一致,那么直接跳过 if (redownLoad) { //要求重新下载 File.Delete(fullname); CommonUnitity.ClearFolder(downloadFolder); } else { //如果文件已经存在 if (DownloadProgressChanged != null) { DownloadProgressChanged(1, 1, 100); } Do(new DownloadUserToken() { Client = _webClient, FileName = fullname, ExcuteFileName = info.ExcuteFileName }); return; } } _webClient.DownloadFileCompleted += OnDownloadFileCompleted; _webClient.DownloadProgressChanged += OnDownloadProgressChanged; DownloadUserToken userToken = new DownloadUserToken() { Client = _webClient, FileName = fullname, ExcuteFileName = info.ExcuteFileName }; _webClient.DownloadFileAsync(new Uri(info.DownloadUrl), fullname, userToken); }
private void FrmUpdateCheck_Load(object sender, EventArgs e) { try { var info = AutoUpdaterInfo.Current; this.lbAppName.Text = info.AppName; this.lbNewVersion.Text = info.NewVersion; this.lbVersion.Text = info.Version; this.BtnUpdate.Visible = info.HasNewVersion(); _autoUpdaterInfo = info; } catch (Exception exception) { MessageBox.Show(exception.Message); } }
void ShowFrame(Frame frameNum) { frameOn = frameNum; switch (frameNum) { case Frame.Checking: //Update checking screen panelDisplaying.ChangePanel(FrameType.Update, clientLang.Checking.Title, clientLang.Checking.SubTitle, clientLang.Checking.Content, String.Empty); btnNext.Enabled = false; if (!isAutoUpdateMode) { CheckForUpdate(); } break; case Frame.UpdateInfo: //Update Info Screen panelDisplaying.ChangePanel(FrameType.TextInfo, clientLang.UpdateInfo.Title, clientLang.UpdateInfo.SubTitle, clientLang.UpdateInfo.Content, clientLang.UpdateBottom); // check if elevation is needed needElevation = NeedElevationToUpdate(); btnNext.Enabled = true; btnNext.Text = clientLang.UpdateButton; if (QuickCheck) { // return 2 if we're just checking if (QuickCheckJustCheck) { if (OutputInfo == string.Empty) { // output the changelog Console.WriteLine(ServerFile.NewVersion); Console.WriteLine(panelDisplaying.GetChanges(false)); } else if (OutputInfo != null) { try { using (StreamWriter outfile = new StreamWriter(OutputInfo)) { outfile.WriteLine(ServerFile.NewVersion); outfile.WriteLine(panelDisplaying.GetChanges(false)); } } catch { } } ReturnCode = 2; Close(); return; } ShowInTaskbar = true; WindowState = FormWindowState.Normal; TopMost = true; TopMost = false; QuickCheck = false; } else if (isAutoUpdateMode) { // save the automatic updater file SaveAutoUpdateData(UpdateStepOn.UpdateAvailable); updateHelper.SendSuccess(ServerFile.NewVersion, panelDisplaying.GetChanges(true), true); } break; case Frame.InstallUpdates: //Download and Install Updates panelDisplaying.ShowChecklist = true; panelDisplaying.ChangePanel(FrameType.Update, clientLang.DownInstall.Title, clientLang.DownInstall.SubTitle, clientLang.DownInstall.Content, String.Empty); if (SelfUpdateState == SelfUpdateState.FullUpdate) { //show status for downloading self SetStepStatus(0, clientLang.DownloadingSelfUpdate); } else { //show status for the downloading update SetStepStatus(0, clientLang.Download); } if (!isAutoUpdateMode) { DownloadUpdate(); } btnNext.Enabled = false; break; case Frame.UpdatedSuccessfully: //Display Congrats Window panelDisplaying.ChangePanel(FrameType.WelcomeFinish, clientLang.SuccessUpdate.Title, clientLang.SuccessUpdate.Content, String.Empty, clientLang.FinishBottom); btnNext.Enabled = true; btnCancel.Visible = false; btnNext.Text = clientLang.FinishButton; break; case Frame.AlreadyUpToDate: //Your Product is already up to date screen panelDisplaying.ChangePanel(FrameType.WelcomeFinish, clientLang.AlreadyLatest.Title, clientLang.AlreadyLatest.Content, String.Empty, clientLang.FinishBottom); btnNext.Enabled = true; btnCancel.Visible = false; btnNext.Text = clientLang.FinishButton; break; case Frame.NoUpdatePathAvailable: //No update to the latest version is available if (!string.IsNullOrEmpty(ServerFile.NoUpdateToLatestLinkText)) { panelDisplaying.SetNoUpdateAvailableLink(ServerFile.NoUpdateToLatestLinkText, ServerFile.NoUpdateToLatestLinkURL); } panelDisplaying.ChangePanel(FrameType.WelcomeFinish, clientLang.NoUpdateToLatest.Title, clientLang.NoUpdateToLatest.Content, String.Empty, clientLang.FinishBottom); btnNext.Enabled = true; btnCancel.Visible = false; btnNext.Text = clientLang.FinishButton; break; case Frame.Uninstall: //Uninstall screen panelDisplaying.ShowChecklist = true; panelDisplaying.ChangePanel(FrameType.Update, clientLang.Uninstall.Title, clientLang.Uninstall.SubTitle, clientLang.Uninstall.Content, String.Empty); //Show uninstalling status SetStepStatus(0, clientLang.UninstallFiles); btnNext.Enabled = false; InstallUpdates(UpdateOn.Uninstalling); break; case Frame.Error: //Display error screen //TODO: make the return codes error specific ReturnCode = 1; // show details button to hide all the complex crap from users panelDisplaying.ErrorDetails = errorDetails; panelDisplaying.SetUpErrorDetails(clientLang.ShowDetails); panelDisplaying.ChangePanel(FrameType.WelcomeFinish, clientLang.UpdateError.Title, error, "", clientLang.FinishBottom); btnNext.Enabled = true; btnCancel.Visible = false; btnNext.Text = clientLang.FinishButton; // show wyUpdate if if (QuickCheck && !QuickCheckNoErr) { ShowInTaskbar = true; WindowState = FormWindowState.Normal; TopMost = true; TopMost = false; QuickCheck = false; } break; } // handle all success / error cases if (FrameIs.ErrorFinish(frameNum)) { // allow the user to forcefuly exit BlockLogOff(false); EnableCancel(); // allow the user to exit by pressing ESC CancelButton = btnNext; // set the error return code (1) or success (0) ReturnCode = frameNum == Frame.Error ? 1 : 0; if (QuickCheck) { if (frameNum == Frame.Error && !QuickCheckNoErr) { Visible = true; TopMost = true; TopMost = false; } else { if (frameNum == Frame.Error) { if (OutputInfo == string.Empty) { // output the error Console.WriteLine(error + "\r\n"); Console.WriteLine(errorDetails); } else if (OutputInfo != null) { try { using (StreamWriter outfile = new StreamWriter(OutputInfo)) { outfile.WriteLine(error); outfile.WriteLine(errorDetails); } } catch { } } // If we're starting a process on error, then start it if (StartOnErr != null) { try { LimitedProcess.Start(StartOnErr, StartOnErrArgs); } catch { } } } WindowState = FormWindowState.Minimized; ShowInTaskbar = false; Visible = true; Close(); return; } } else if (isAutoUpdateMode) { // if it's reasonable to expect a client to be waiting for an error // that is, if we haven't already started the update process // then send all waiting processes the error message if (update.CurrentlyUpdating < UpdateOn.ClosingProcesses) { // wait for any clients to connect if (!updateHelper.RunningServer) { StartQuickAndDirtyAutoUpdateMode(); } // send the error to any running "client" processes updateHelper.SendFailed(error, errorDetails, autoUpdateStepProcessing); } if (frameNum == Frame.UpdatedSuccessfully || frameNum == Frame.Error) { // save whether an update succeeded or failed AutoUpdaterInfo auInfo; if (frameNum == Frame.Error) { auInfo = new AutoUpdaterInfo(updateHelper.AutoUpdateID, oldAUTempFolder) { AutoUpdaterStatus = AutoUpdaterStatus.UpdateFailed, ErrorTitle = error, ErrorMessage = errorDetails }; } else { auInfo = new AutoUpdaterInfo(updateHelper.AutoUpdateID, oldAUTempFolder) { AutoUpdaterStatus = AutoUpdaterStatus.UpdateSucceeded, UpdateVersion = ServerFile.NewVersion, ChangesInLatestVersion = panelDisplaying.GetChanges(true), ChangesIsRTF = true }; } auInfo.Save(); try { if (updateHelper.IsAService) { using (ServiceController srvc = new ServiceController(updateHelper.FileOrServiceToExecuteAfterUpdate)) { if (updateHelper.ExecutionArguments != null) { string[] args = CmdLineToArgvW.SplitArgs(updateHelper.ExecutionArguments); // start the windows service srvc.Start(args); } else // start the windows service (without args) { srvc.Start(); } } } else { // start the updated program as a limited user LimitedProcess.Start(updateHelper.FileOrServiceToExecuteAfterUpdate, updateHelper.ExecutionArguments); } } catch { } //TODO: if the service fails to start then log the error -- if the app fails to start, no big deal } // we're no longer in autoupdate mode - cleanup temp files on close isAutoUpdateMode = false; Close(); return; } else if (UpdatingFromService || (update.CloseOnSuccess && frameNum == Frame.UpdatedSuccessfully) || (StartOnErr != null && frameNum == Frame.Error)) { // If we're updating from a service (i.e. no-ui), then close on *either* success or failure. // If we're in normal mode but the user has specified they want "CloseOnSuccess", then do it. if (log != null) { if (frameNum == Frame.UpdatedSuccessfully) { log.Write("Updated successfully."); } else { log.Write(error + " - " + errorDetails); } } // If we're starting a process on error, then start it if (StartOnErr != null && frameNum == Frame.Error) { // if the "failure" process fails to start then show // the error screen. try { LimitedProcess.Start(StartOnErr, StartOnErrArgs); } catch { return; } } Close(); return; } } try { // so the user doesn't accidentally cancel update. btnNext.Focus(); } catch { } // if silent & if on one of the user interaction screens, then click next if (isSilent && (FrameIs.Interaction(frameOn))) { btnNext_Click(null, EventArgs.Empty); return; } }