/// <summary> /// Sets whether or not tag values will be shown. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <param name="show">Whether or not tag values will be shown.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart ShowTagValues(this BreakdownChart chart, bool show) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.ShowTagValues = show; return(chart); }
/// <summary> /// Sets whether or not the chart and tags should be rendered in compact mode. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <param name="compact">Whether or not the chart and tags should be rendered in compact mode.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart Compact(this BreakdownChart chart, bool compact) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.Compact = compact; return(chart); }
/// <summary> /// Adds an item to the breakdown chart. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <param name="label">The item label.</param> /// <param name="value">The item value.</param> /// <param name="color">The item color.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart AddItem(this BreakdownChart chart, string label, double value, Color color) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.Data.Add(new BreakdownChartItem(label, value, color)); return(chart); }
/// <summary> /// Tags will be shown. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <param name="func">The value formatter to use.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart UseValueFormatter(this BreakdownChart chart, Func <double, CultureInfo, string>?func) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.ValueFormatter = func; return(chart); }
/// <summary> /// Sets the width of the breakdown chart. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <param name="width">The breakdown chart width.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart Width(this BreakdownChart chart, int?width) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.Width = width; return(chart); }
/// <summary> /// Tags will be shown. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart ShowPercentage(this BreakdownChart chart) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.ValueFormatter = (value, culture) => string.Format(culture, "{0}%", value); return(chart); }
/// <summary> /// Tags will be shown. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <param name="func">The value formatter to use.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart UseValueFormatter(this BreakdownChart chart, Func <double, string>?func) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } chart.ValueFormatter = func != null ? (value, _) => func(value) : null; return(chart); }
/// <summary> /// Adds multiple items to the breakdown chart. /// </summary> /// <typeparam name="T">A type that implements <see cref="IBreakdownChartItem"/>.</typeparam> /// <param name="chart">The breakdown chart.</param> /// <param name="items">The items.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart AddItems <T>(this BreakdownChart chart, IEnumerable <T> items) where T : IBreakdownChartItem { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } if (items is null) { throw new ArgumentNullException(nameof(items)); } foreach (var item in items) { AddItem(chart, item); } return(chart); }
/// <summary> /// Adds an item to the breakdown chart. /// </summary> /// <typeparam name="T">A type that implements <see cref="IBreakdownChartItem"/>.</typeparam> /// <param name="chart">The breakdown chart.</param> /// <param name="item">The item.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart AddItem <T>(this BreakdownChart chart, T item) where T : IBreakdownChartItem { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } if (item is BreakdownChartItem chartItem) { chart.Data.Add(chartItem); } else { chart.Data.Add( new BreakdownChartItem( item.Label, item.Value, item.Color)); } return(chart); }
/// <summary> /// Adds multiple items to the breakdown chart. /// </summary> /// <typeparam name="T">A type that implements <see cref="IBarChartItem"/>.</typeparam> /// <param name="chart">The breakdown chart.</param> /// <param name="items">The items.</param> /// <param name="converter">The converter that converts instances of <c>T</c> to <see cref="IBreakdownChartItem"/>.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart AddItems <T>(this BreakdownChart chart, IEnumerable <T> items, Func <T, IBreakdownChartItem> converter) { if (chart is null) { throw new ArgumentNullException(nameof(chart)); } if (items is null) { throw new ArgumentNullException(nameof(items)); } if (converter is null) { throw new ArgumentNullException(nameof(converter)); } foreach (var item in items) { chart.Data.Add(converter(item)); } return(chart); }
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); }
/// <summary> /// Chart and tags is rendered in full size mode. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart FullSize(this BreakdownChart chart) { return(Compact(chart, false)); }
/// <summary> /// Chart and tags is rendered in compact mode. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart Compact(this BreakdownChart chart) { return(Compact(chart, true)); }
/// <summary> /// Tag values will be not be shown. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart HideTagValues(this BreakdownChart chart) { return(ShowTagValues(chart, false)); }
/// <summary> /// Tag values will be shown. /// </summary> /// <param name="chart">The breakdown chart.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static BreakdownChart ShowTagValues(this BreakdownChart chart) { return(ShowTagValues(chart, true)); }