示例#1
0
 /// <summary>
 /// Renders the exception using the specified <see cref="IAnsiConsole"/>.
 /// </summary>
 /// <param name="console">The console.</param>
 public void Render(IAnsiConsole console)
 {
     if (Pretty != null)
     {
         console?.Render(Pretty);
     }
 }
示例#2
0
        public void Render(IRenderable?renderable)
        {
            if (renderable is null)
            {
                throw new System.ArgumentNullException(nameof(renderable));
            }

            _console.Render(renderable);
        }
        private void WriteInputTable()
        {
            var table = new Table()
                        .AddColumn(new TableColumn("File").Centered())
                        .AddColumn(new TableColumn("Group Title").Centered())
                        .AddColumn(new TableColumn("Test Suffix").Centered())
                        .AddColumn(new TableColumn("Exists").Centered())
                        .AddColumn(new TableColumn("Format").Centered())
                        .AddColumn(new TableColumn("Skipping").Centered());

            foreach (var input in _inputs)
            {
                table.AddRow(input.File.Name,
                             string.IsNullOrEmpty(input.GroupTitle) ? "default" : input.GroupTitle,
                             string.IsNullOrEmpty(input.TestSuffix) ? "n/a" : input.TestSuffix,
                             input.File.Exists.ToString(),
                             input.Format.ToString(),
                             (!input.File.Exists || input.Format == InputFormatType.Unknown).ToString());
            }

            _standardConsole.WriteLine();
            _standardConsole.Render(table);
        }
示例#4
0
        public override void Completed(bool clear)
        {
            lock (_lock)
            {
                if (clear)
                {
                    _console.Render(_live.RestoreCursor());
                }
                else
                {
                    _console.WriteLine();
                }

                _console.Cursor.Show();
            }
        }
示例#5
0
        public override async Task <int> ExecuteAsync(CommandContext context, ListOptions request)
        {
            var cancellationToken = CancellationToken.None;

            var pattern = request.Pattern ?? "";
            var results = await _availableArchiveParser.Get(cancellationToken);

            var table = new Table {
                Border = TableBorder.Rounded, Expand = true
            };

            table.AddColumn(new TableColumn("Short Name"));
            table.AddColumn(new TableColumn("Archive"));

            var filteredResults = results.Where(i => i.ShortName.Contains(pattern));

            if (request.IncludeMeta == false)
            {
                filteredResults = filteredResults.Where(i => !i.LongName.Contains(".meta."));
            }

            foreach (var archive in filteredResults)
            {
                var innerTable = new Table {
                    Border = TableBorder.None, ShowHeaders = false, Expand = true
                };

                innerTable.AddColumn("Uri");
                innerTable.AddColumn("Size", column =>
                {
                    column.Alignment = Justify.Right;
                    column.Width     = 7;
                });

                foreach (var archiveUri in archive.Uris)
                {
                    innerTable.AddRow(new Markup($"[link={archiveUri.Uri}]{archiveUri.Uri}[/]"),
                                      new Text(archiveUri.SizeInBytes.BytesToString()));
                }

                table.AddRow(new Markup($"[white]{archive.ShortName}[/]"), innerTable);
            }

            _console.Render(table);

            return(await Task.FromResult(0));
        }
 /// <summary>
 /// Writes the specified markup to the console.
 /// </summary>
 /// <param name="console">The console to write to.</param>
 /// <param name="provider">An object that supplies culture-specific formatting information.</param>
 /// <param name="format">A composite format string.</param>
 /// <param name="args">An array of objects to write.</param>
 public static void Markup(this IAnsiConsole console, IFormatProvider provider, string format, params object[] args)
 {
     console.Render(MarkupParser.Parse(string.Format(provider, format, args)));
 }
        public override async Task <int> ExecuteAsync(CommandContext context, ImportOptions request)
        {
            var cancellationToken = CancellationToken.None;

            var requestPath = await CheckAndFixupPath(request.Path, cancellationToken);

            var dbName = _databaseHelper.GetDbNameFromPathOption(request.DatabaseName, requestPath);
            var tasks  = new Queue <(string name, ITask task)>();

            var(masterConnectionString, databaseConnectionString) =
                _databaseHelper.GetMasterAndDbConnectionStrings(request.ConnectionString, dbName);

            ImmutableDictionary <string, long>?insertReport = null;

            var processor = _processorFactory.VerifyAndCreateProcessor(requestPath);

            if (request.DropAndRecreate)
            {
                tasks.Enqueue(("Create new database", new CreateDatabase(masterConnectionString, dbName)));
            }
            else
            {
                tasks.Enqueue(("Verify database exists", new VerifyDatabaseExists(masterConnectionString, dbName)));
            }

            tasks.Enqueue(("Create schema", new CreateSchema(databaseConnectionString, !request.SkipTags)));
            if (!request.SkipPrimaryKeys)
            {
                tasks.Enqueue(("Add constraints", new AddConstraints(databaseConnectionString)));
            }

            tasks.Enqueue(("Insert type values", new InsertTypeValues(databaseConnectionString)));
            tasks.Enqueue(("Insert data from archive",
                           new InsertData(
                               databaseConnectionString,
                               dbName,
                               processor,
                               !request.SkipTags,
                               d => insertReport = d,
                               request.BlockSize)));

            var progressBar = _console.Progress()
                              .AutoClear(false)
                              .Columns(new ProgressColumn[]
            {
                new SpinnerColumn {
                    CompletedText = Emoji.Known.CheckMark
                }, new FixedTaskDescriptionColumn(40),
                new ProgressBarColumn(), new PercentageColumn(), new RemainingTimeColumn(),
            });


            var stopWatch = Stopwatch.StartNew();

            progressBar.Start(ctx =>
            {
                foreach (var(description, task) in tasks)
                {
                    var progressTasks = new ConcurrentDictionary <string, ProgressTask>();
                    var progress      = new Progress <(string taskId, string message, double weight, double maxValue)>(i =>
                    {
                        var(taskId, message, weight, maxValue) = i;
                        var progressBarTask = progressTasks.GetOrAdd(taskId, _ => ctx.AddTask(description));

                        progressBarTask.MaxValue(maxValue);
                        progressBarTask.Increment(weight);
                        progressBarTask.Description(message);
                    });

                    task.Go(progress);

                    foreach (var progressTask in progressTasks.Values)
                    {
                        progressTask.Increment(progressTask.MaxValue - progressTask.Value);
                    }
                }
            });

            stopWatch.Stop();

            if (insertReport != null)
            {
                var counter = 1;
                var chart   = new BreakdownChart()
                              .Compact()
                              .Width(60)
                              .UseValueFormatter(d => d.ToMetric())
                              .FullSize()
                              .AddItems(insertReport,
                                        pair => new BreakdownChartItem(pair.Key, pair.Value, counter++)
                                        );

                _console.MarkupLine("[blue]Rows inserted[/]");
                _console.Render(chart);
            }

            _console.WriteLine();
            _console.MarkupLine($"Import complete in [blue]{stopWatch.Elapsed.Humanize()}[/].");

            return(0);
        }
示例#8
0
        public void WriteToConsole([NotNull] List <ProjectAnalyzerResult> results)
        {
            var resultsWithPackageToRemove    = results.Where(r => r.CanBeRemoved.Count > 0).ToList();
            var resultsWithPackageMayBeRemove = results.Where(r => r.MightBeRemoved.Count > 0).ToList();

            if (results.All(x => x.NoPackagesToRemove))
            {
                // Output the result.
                _console.WriteLine();
                _console.MarkupLine("[green]Everything looks good![/]");
                _console.WriteLine();
                return;
            }

            var report = new Grid();

            report.AddColumn();

            if (resultsWithPackageToRemove.Count > 0)
            {
                foreach (var(_, _, last, result) in resultsWithPackageToRemove.Enumerate())
                {
                    var table = new Table().BorderColor(Color.Grey).Expand();
                    table.AddColumns("[grey]Package[/]", "[grey]Referenced by[/]");
                    foreach (var item in result.CanBeRemoved)
                    {
                        table.AddRow(
                            $"[green]{item.Package.Name}[/]",
                            $"[aqua]{item.Original.Project.Name}[/]");
                    }

                    report.AddRow($" [yellow]Packages that can be removed from[/] [aqua]{result.Project}[/]:");
                    report.AddRow(table);

                    if (!last || (last && resultsWithPackageMayBeRemove.Count > 0))
                    {
                        report.AddEmptyRow();
                    }
                }
            }

            if (resultsWithPackageMayBeRemove.Count > 0)
            {
                foreach (var(_, _, last, result) in resultsWithPackageMayBeRemove.Enumerate())
                {
                    var table = new Table().BorderColor(Color.Grey).Expand();
                    table.AddColumns("[grey]Package[/]", "[grey]Version[/]", "[grey]Reason[/]");

                    foreach (var item in result.MightBeRemoved)
                    {
                        if (item.Package.IsGreaterThan(item.Original.Package, out var indeterminate))
                        {
                            var name    = item.Original.Project.Name;
                            var version = item.Original.Package.GetVersionString();
                            var verb    = indeterminate ? "Might be updated from" : "Updated from";
                            var reason  = $"[grey]{verb}[/] [silver]{version}[/] [grey]in[/] [aqua]{name}[/]";

                            table.AddRow(
                                $"[green]{item.Package.Name}[/]",
                                item.Package.GetVersionString(),
                                reason);
                        }
                        else
                        {
                            var name    = item.Original.Project.Name;
                            var version = item.Original.Package.GetVersionString();
                            var verb    = indeterminate ? "Does not match" : "Downgraded from";
                            var reason  = $"[grey]{verb}[/] [silver]{version}[/] [grey]in[/] [aqua]{name}[/]";

                            table.AddRow(
                                $"[green]{item.Package.Name}[/]",
                                item.Package.GetVersionString(),
                                reason);
                        }
                    }

                    report.AddRow($" [yellow]Packages that [u]might[/] be removed from[/] [aqua]{result.Project}[/]:");
                    report.AddRow(table);

                    if (!last)
                    {
                        report.AddEmptyRow();
                    }
                }
            }

            _console.WriteLine();
            _console.Render(
                new Panel(report)
                .RoundedBorder()
                .BorderColor(Color.Grey));
        }
 /// <summary>
 /// Refreshes the current progress.
 /// </summary>
 public void Refresh()
 {
     _renderer.Update(this);
     _console.Render(new ControlSequence(string.Empty));
 }
 /// <summary>
 /// Writes the specified markup to the console.
 /// </summary>
 /// <param name="console">The console to write to.</param>
 /// <param name="value">The value to write.</param>
 public static void Markup(this IAnsiConsole console, string value)
 {
     console.Render(MarkupParser.Parse(value));
 }