public async Task ExecuteCommand(AppGetOption option) { var commandDic = option.ToDictionary(); foreach (var pair in commandDic) { SentryTarget.AddTag(pair.Key, pair.Value); } if (option.Verbose) { LogConfigurator.EnableVerboseLogging(); } var commandHandler = _handlers.Single(c => c.Key == option.GetType()).Value.Value; if (commandHandler == null) { throw new UnknownCommandException(option); } _logger.Debug("Starting command [{0}]", option.CommandName); var stopwatch = Stopwatch.StartNew(); await commandHandler.Execute(option); stopwatch.Stop(); Console.WriteLine(); _logger.Debug("Completed command [{0}]. took: {1:N}s", option.CommandName, stopwatch.Elapsed.TotalSeconds); }
public async Task UpdateAllPackages(InstallInteractivityLevel interactivityLevel) { if (!_envInfo.IsAdministrator) { Console.WriteLine(); _logger.Warn("Running as administrator is recommended to allow uninterrupted batch updates."); Console.WriteLine(); } var updates = await GetUpdates(); var toInstall = updates.Where(c => c.Status == UpdateStatus.Available).ToList(); var updated = 0; var failed = 0; var restartRequired = false; for (var index = 0; index < toInstall.Count; index++) { var update = toInstall[index]; SentryTarget.AddTag("packageid", update.PackageId); try { _logger.Info("Installing update {0} of {1}", index + 1, toInstall.Count); Console.WriteLine(); await UpdatePackage(update.PackageId, PackageManifest.LATEST_TAG, interactivityLevel); updated++; } catch (InstallerException e) when(e.ExitReason?.Category == ExitCodeTypes.RestartRequired) { restartRequired = true; } catch (Exception e) { _logger.Fatal(e, "An error occurred while updating {0}", update.PackageId); failed++; } finally { SentryTarget.AddTag("packageid", null); } } Console.WriteLine(); _logger.Info("Updates Applied Successfully: {0:n0} Updates failed to apply: {1:n0}", updated, failed); if (restartRequired) { _logger.Warn("One or more installers have requested a system restart to complete the installation."); } }