public Result InstallOrUpgrade(string version, IMessagePresenter presenter) { if (!_installer.IsStaged(version)) { var errorMessage = $"Could not install {_name} {version} because it is not yet staged. Stage it first, then install it."; presenter.ShowMessage(errorMessage); return(Result.Failure(errorMessage)); } var productInstallerMetaData = FindProductInstallationMetaData(); bool isInstalled = productInstallerMetaData != null; if (isInstalled) { if (VersionMatcher.DoVersionsMatch(version, InstalledVersion.ToString())) { presenter.ShowMessage($"Since {productInstallerMetaData.DisplayName} is already installed at the same version, we won't install it"); return(Result.Successful()); } presenter.ShowMessage( $"Since {productInstallerMetaData.DisplayName} is already installed, uninstalling it"); var uninstallResult = _installer.Uninstall(ProductCode); if (uninstallResult.IsFailed) { presenter.ShowMessage($"Uninstall failed, so {_name} cannot be installed on this machine"); return(uninstallResult); } if (IsInstalled) { presenter.ShowMessage( $"{_name} is still installed on this machine after the uninstall, so we cannot install"); return(Result.Failure($"Uninstall of {_name} failed")); } } else { presenter.ShowMessage($"{_name} is not installed, so installing it for the first time"); } presenter.ShowMessage($"Installing {_name} {version}"); var result = _installer.Install(version); if (result.IsFailed) { Logger.Info($"Could not install {_name} {version} because of an error: {result}"); presenter.ShowMessage($"Could not install {_name} {version}. Make sure your server is running as an administrator"); } else if (!IsInstalled) { presenter.ShowMessage($"Installer for {_name} {version} ran successfully, but it is still not installed. Make sure your server has rights to install {_name} for all users (Administrator rights)."); return(Result.Failure( $"Expecting {_name} to be installed after running the installer, but it is not installed")); } Logger.Info($"Result of install {_name} {version} is {result}"); return(result); }
protected override JobRunStatus RetrieveCurrentStatus() { if (_jobServer == null) { Logger.Debug("Creating rest api client for scheduler"); _jobServer = _jobServerProvider(); } var taskId = _originalStatus.Id; JobRunStatus currentStatus; try { Logger.Debug($"Fetching current status for task {taskId} with previous index of {_previousMessageIndex}"); currentStatus = _jobServer.GetJobRunStatus(taskId, _previousMessageIndex).Result; _previousMessageIndex = currentStatus.CurrentMessageIndex; Logger.Debug($"Task {taskId} has status of {currentStatus}"); Logger.Debug($"Showing all {currentStatus.Messages.Length} messages"); foreach (var statusMessage in currentStatus.Messages) { Logger.Debug($"Message: {statusMessage}"); _messagePresenter.ShowMessage(statusMessage); } } catch (Exception ex) { Logger.Error(ex, $"While waiting for the task to finish, an exception was thrown: {ex.Message} Stack Trace: {ex.StackTrace}"); currentStatus = _originalStatus.Copy(); currentStatus.Result = Result.Failure( "Lost connection to the server, and so couldn't finish processing this task"); currentStatus.State = JobRunState.Finished; currentStatus.FinishTime = DateTime.Now; } return(currentStatus); }
public Result Run(IMessagePresenter presenter, IChefBootstrapper chefBootstrapper) { presenter.ShowMessage($"Running chef {chefBootstrapper}"); chefBootstrapper.PrepareEnvironmentForChefRun(); var process = _processCreator(); process.LogEntryReceived += (sender, entry) => { presenter.ShowMessage(entry.Entry); entry.Log(); }; var argumentsForChefRun = chefBootstrapper.ArgumentsForChefRun(); var result = process.Run(argumentsForChefRun); presenter.ShowMessage($"Finished running chef with result: {result}"); return(result); }
public Result Run(IMessagePresenter presenter, IRunChefPolicy runChefPolicy) { presenter.ShowMessage($"Running chef {runChefPolicy}"); runChefPolicy.PrepareEnvironmentForChefRun(); var process = _processCreator(); process.LogEntryReceived += (sender, entry) => { Logger.Debug($"Received log message from chef run: {entry.Entry}"); presenter.ShowMessage(entry.Entry); entry.Log(); }; var argumentsForChefRun = runChefPolicy.ArgumentsForChefRun(); var result = process.Run(argumentsForChefRun); presenter.ShowMessage($"Finished running chef with result: {result}"); return(result); }
public void PresentAnyChangesTo(JobRunStatus status) { if (status == null) { return; } if (_lastStatus == null) { throw new InvalidOperationException("Expecting last status to be populated"); } if (_lastStatus.IsNotRun && status.IsRunning) { _messagePresenter.ShowMessage($"Server started running {status.Description} at {status.StartTime}"); } if (!string.Equals(_lastStatus.CurrentMessage, status.CurrentMessage)) { _messagePresenter.ShowMessage($"Latest: {status.CurrentMessage}"); } _lastStatus = status; }
public Result Download(string version, IMessagePresenter messagePresenter) { messagePresenter.ShowMessage("Ensuring staging directory exists"); _fileSystem.EnsureDirectoryExists(StagingDirectory); var destination = FullPathToStagedInstaller(version, _prefix); if (_fileSystem.FileExists(destination)) { messagePresenter.ShowMessage($"Download msi already exists, so not downloading again"); return(Result.Successful()); } var downloadLink = DownloadUriFor(version, _product, _prefix, _target); messagePresenter.ShowMessage($"Downloading {_product} {version} from {downloadLink}"); var result = _fileDownloader.Download(downloadLink, destination); messagePresenter.ShowMessage($"Finished downloading {_product} {version} from {downloadLink}"); Logger.Info(result); return(result.TranslateIfFailed($"Installer for {_product} {version} could not be found at {downloadLink}")); }