Пример #1
0
        public async Task RunAsync(CancellationToken token)
        {
            using var context = await _contextFactory.CreateContext(token);

            _context.Current = context;

            await _stateManager.LoadStateAsync(context, token);

            try
            {
                // Cache current steps here as defense-in-depth against the possibility
                // of a bug (or very weird upgrade step behavior) causing the current step
                // to reset state after being initialized by GetNextStepAsync
                var steps = await _upgrader.InitializeAsync(context, token);

                var step = await _upgrader.GetNextStepAsync(context, token);

                while (step is not null)
                {
                    await ShowUpgradeStepsAsync(steps, context, token, step);

                    await RunStepAsync(context, step, token);

                    step = await _upgrader.GetNextStepAsync(context, token);
                }

                _logger.LogInformation("Upgrade has completed. Please review any changes.");
            }
            finally
            {
                // Do not pass the same token as it may have been canceled and we still need to persist this.
                await _stateManager.SaveStateAsync(context, default);
            }
        }
Пример #2
0
        public async Task RunAsync(CancellationToken token)
        {
            using var context = await _contextFactory.CreateContext(token);

            await _stateManager.LoadStateAsync(context, token);

            try
            {
                // Cache current steps here as defense-in-depth against the possibility
                // of a bug (or very weird upgrade step behavior) causing the current step
                // to reset state after being initialized by GetNextStepAsync
                var steps = await _upgrader.InitializeAsync(context, token);

                var step = await _upgrader.GetNextStepAsync(context, token);

                while (step is not null)
                {
                    while (!step.IsDone)
                    {
                        token.ThrowIfCancellationRequested();

                        ShowUpgradeSteps(steps, context, step);
                        _io.Output.WriteLine();

                        var commands = _commandProvider.GetCommands(step);
                        var command  = await _input.ChooseAsync("Choose a command:", commands, token);

                        // TODO : It might be nice to allow commands to show more details by having a 'status' property
                        //        that can be shown here. Also, commands currently only return bools but, in the future,
                        //        if they return more complex objects, custom handlers could be used to respond to the different
                        //        commands' return values.
                        if (!await command.ExecuteAsync(context, token))
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            _io.Output.WriteLine($"Command ({command.CommandText}) did not succeed");
                            Console.ResetColor();
                        }
                        else if (await _input.WaitToProceedAsync(token))
                        {
                            ConsoleUtils.Clear();
                        }
                        else
                        {
                            _logger.LogWarning("Upgrade process was canceled. Quitting....");
                            return;
                        }
                    }

                    step = await _upgrader.GetNextStepAsync(context, token);
                }

                _logger.LogInformation("Upgrade has completed. Please review any changes.");
            }
            finally
            {
                // Do not pass the same token as it may have been canceled and we still need to persist this.
                await _stateManager.SaveStateAsync(context, default);
            }
        }
Пример #3
0
        public async Task RunAsync(CancellationToken token)
        {
            using var context = await _contextFactory.CreateContext(token);

            await _stateManager.LoadStateAsync(context, token);

            var analzyerContext  = new AnalyzeContext(context);
            var analyzeResultMap = new List <AnalyzeResultDefinition>();

            await foreach (var provider in _providers.ToAsyncEnumerable().WhereAwait(async i => await i.IsApplicableAsync(analzyerContext, token)))
            {
                analyzeResultMap.Add(new()
                {
                    Version         = GetProviderVersion(provider),
                    Name            = provider.Name,
                    InformationUri  = provider.InformationUri,
                    AnalysisResults = provider.AnalyzeAsync(analzyerContext, token),
                });
            }

            await _writer.WriteAsync(analyzeResultMap.ToAsyncEnumerable(), _options.Value.Format, token).ConfigureAwait(false);
        }
Пример #4
0
        public async Task RunAsync(CancellationToken token)
        {
            using var context = await _contextFactory.CreateContext(token);

            await _stateManager.LoadStateAsync(context, token);

            var analzyerContext  = new AnalyzeContext(context);
            var analyzeResultMap = new List <AnalyzeResultDefinition>();

            await foreach (var provider in _providers.ToAsyncEnumerable().WhereAwait(async i => await i.IsApplicableAsync(analzyerContext, token)))
            {
                analyzeResultMap.Add(new()
                {
                    Version         = GetProviderVersion(provider),
                    Name            = provider.Name,
                    InformationUri  = provider.InformationUri,
                    AnalysisResults = provider.AnalyzeAsync(analzyerContext, token),
                });
            }

            if (_writerProvider.TryGetWriter(_options.Value.Format, out var writer))
            {
                var output = Path.Combine(Directory.GetCurrentDirectory(), $"AnalysisReport.{_options.Value.Format}");

                _logger.LogInformation(LocalizedStrings.WritingOutputMessage, output);

                using var stream = File.Create(output);
                await writer.WriteAsync(analyzeResultMap.ToAsyncEnumerable(), stream, token).ConfigureAwait(false);

                _logger.LogInformation(LocalizedStrings.AnalysisCompleteMessage, output);
            }
            else
            {
                _logger.LogError(LocalizedStrings.RequestedFormatUnavailableMessage, _options.Value.Format);
            }
        }