
O objetivo deste projeto é estender os plugins Spectre.Console com alguma funcionalidade de nicho.
IProgress .HttpClient .DataTable .| Pacote | Versão | Descrição |
|---|---|---|
Spectre.Console.Extensions.Progress | Adaptador iProgress e relatórios httpclient. | |
Spectre.Console.Extensions.Table | DataTable e suporte do conjunto de dados. |
Extensões para AnsiConsole.Progress
Use Specter Spinner com interface IProgress padrão.
Motivação : para conectar os métodos que aceitam IProgress para que os relatórios sejam declarativos, familiares, convenientes.
private static async Task RunSimpleExampleAsync ( )
{
await BuildProgress ( ) . StartAsync (
GenerateProgressTasks ,
( reporter ) => RunSpinnerWithIProgress ( reporter , TimeSpan . FromMilliseconds ( 500 ) ) ,
( reporter ) => RunSpinnerWithIProgress ( reporter , TimeSpan . FromSeconds ( 1 ) ) ) ;
// Collection of tasks to execute,
// every task corresponds to following delegates sequentially.
static IEnumerable < ProgressTask > GenerateProgressTasks ( ProgressContext ctx )
{
yield return ctx . AddTask ( "Task1" ) ;
yield return ctx . AddTask ( "Task2" ) ;
}
static async Task RunSpinnerWithIProgress (
IProgress < double > reporter ,
TimeSpan delay )
{
var capacity = 100 ;
var step = 10 ;
while ( capacity > 0 )
{
reporter . Report ( step ) ;
capacity -= step ;
await Task . Delay ( delay ) ;
}
}
} Execute o progresso para um determinado HttpClient e HttpRequestMessage . O resultado é fornecido como System.IO.Stream .
Motivação : é uma tarefa bastante comum baixar algo e ter um spinner para isso. Basicamente, você nem quer se preocupar em relatar neste caso.
var message = new HttpRequestMessage ( HttpMethod . Get , url ) ;
var http = new HttpClient ( ) ;
var description = "Downloading cats images" ;
await BuildProgress ( ) . StartAsync ( http , message , taskDescription : description , DownloadCallback ) ;
static async Task DownloadCallback ( Stream stream ) => { } ;
await BuildProgress ( )
. WithHttp ( http , request , description , DownloadCallback1 )
. WithHttp ( http , request , description , DownloadCallback2 )
. StartAsync ( ) ; Display System.Data.DataTable .
System . Data . DataTable dataTable = DataTableFactory ( ) ;
var table = dataTable . FromDataTable ( ) . Border ( TableBorder . Rounded ) ;
AnsiConsole . Render ( ) ; Para ver Spectre.Console em ação, instale a ferramenta global dotnet-Exemplo.
> dotnet tool restoreAgora você pode listar exemplos disponíveis neste repositório:
> dotnet exampleE para executar um exemplo:
> dotnet example iprogressPara mais detalhes, consulte:
.
| -- Samples
| | -- DataSet
| | -- DataTable
| | -- Directory.Build.props
| | -- http-progress
| | -- iprogress
| ` -- iprogress-http-client-multiple-calls
... Copyright © Alexey Nikiforov.
Fornecido como está sob a licença do MIT. Para mais informações, consulte License.md.