public async void InstallUpdates() { try { updateInstaller = updateSession.CreateUpdateInstaller(); updateInstaller.Updates = updateCollection; updateInstaller.AllowSourcePrompts = false; DebugLog("Starting update installation: " + Dump(updateInstaller)); //var result = updateInstaller.RunWizard("F*****g hell!!!"); //OnInstallationComplete(result); installationJob_ = updateInstaller.BeginInstall(this, this, null); } catch (Exception ex) { VMManagementTool.Log.Error("WinUpdatesManager::InstallUpdates", ex.ToString()); //this will allow the caller UI method to finish and //the event will be handled like expected asyncronously await Task.Yield(); InstallationCompleted?.Invoke(false, false); } }
void OnInstallationComplete(IInstallationResult installResult) { //todo can there be partial success, and we miss some results? if (installResult.ResultCode != OperationResultCode.orcSucceeded && installResult.ResultCode != OperationResultCode.orcSucceededWithErrors) { DebugLog($"Installation failed with code: {installResult.ResultCode}"); InstallationCompleted?.Invoke(false, false); return; } for (int i = 0; i < updateInstaller.Updates.Count; i++) { var resultCode = installResult.GetUpdateResult(i).ResultCode; var title = updateInstaller.Updates[i].Title; if (resultCode != OperationResultCode.orcSucceeded) { //the title must be there //but if it is not for some reason we will detect this (via dict. exception) updateResults[title].Error = resultCode.ToString(); updateResults[title].IsInstalled = false; } else { updateResults[title].IsInstalled = true; } DebugLog($"Installation status for update {title}: {resultCode}"); } DebugLog($"Is reboot required? : {installResult.RebootRequired}"); InstallationCompleted?.Invoke(true, installResult.RebootRequired); }
internal async void InstallUpdates() { stage = 3; try { await SimualteProgress("Installing:"); } catch (Exception) { return; } //dummy update install states for (int i = 0; i < 3; i++) { if (i == 2) { continue; } string title = $"A dummy update number {i}"; updateResults[title].IsInstalled = true; } bool reboot = false; InstallationCompleted?.Invoke(true, reboot); }
private void Download() { // TODO: this isn't thread-safe if (InstallInProgress) { return; } InstallInProgress = true; this.logger.WriteLine(Strings.Daemon_Downloading); Uri uri = new Uri(DownloadUrl); using (var client = new WebClient()) { client.DownloadProgressChanged += (sender, args) => InstallationProgressChanged?.Invoke(sender, new InstallationProgressChangedEventArgs(args.BytesReceived, args.TotalBytesToReceive)); client.DownloadFileCompleted += Unzip; client.DownloadFileCompleted += (sender, args) => { this.logger.WriteLine(Strings.Daemon_Downloaded); InstallationCompleted?.Invoke(sender, args); }; client.DownloadFileAsync(uri, ZipFilePath); } }
/// <summary> /// Makes a backup of the current EXE, then overwrites it with the new EXE. /// </summary> /// <returns>Awaitable Task</returns> /// <exception cref="NullReferenceException">Thrown when the Repository is null</exception> public void InstallUpdate() { InstallationStarted?.Invoke(this, EventArgs.Empty); State = UpdaterState.Installing; if (repository == null) { throw new NullReferenceException("Could not retrieve Repository"); } try { string tempPath = Path.GetTempPath() + backupFileName; if (File.Exists(tempPath)) { File.Delete(tempPath); } // Move current exe to backup. File.Move(originalInstallPath, tempPath); // Move downloaded exe to the correct folder. File.Move(downloadedAssetPath, originalInstallPath); } catch (Exception ex) { InstallationFailed?.Invoke(this, new ExceptionEventArgs <Exception>(ex, ex.Message)); return; } State = UpdaterState.Idle; InstallationCompleted?.Invoke(this, EventArgs.Empty); }
//Installation Complete callback void IInstallationCompletedCallback.Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs callbackArgs) { try { var installResult = updateInstaller.EndInstall(installationJob); OnInstallationComplete(installResult); } catch (Exception ex) { InstallationCompleted?.Invoke(false, false); Log.Error("IInstallationCompletedCallback.Invoke", ex.ToString()); } }
internal async void AbortAll() { //simulate long running abort await Task.Delay(10000); switch (stage) { case 1: CheckCompleted?.Invoke(false); break; case 2: DownloadCompleted?.Invoke(false); break; case 3: InstallationCompleted?.Invoke(false, false); break; } cts?.Cancel(); cts?.Dispose(); }