
Tujuan dari proyek ini adalah untuk memperluas plugin spektrum. Konsol dengan beberapa fungsionalitas niche.
IProgress .HttpClient .DataTable .| Kemasan | Versi | Keterangan |
|---|---|---|
Spectre.Console.Extensions.Progress | Adaptor iprogress dan pelaporan httpclient. | |
Spectre.Console.Extensions.Table | Dukungan DataTable dan Dataset. |
Ekstensi untuk AnsiConsole.Progress
Gunakan Specter Spinner dengan antarmuka IProgress standar.
Motivasi : Untuk mencolokkan metode yang menerima IProgress sehingga pelaporan itu deklaratif, akrab, nyaman.
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 ) ;
}
}
} Jalankan kemajuan untuk HttpClient dan HttpRequestMessage yang diberikan. Hasilnya disediakan sebagai System.IO.Stream .
Motivasi : Merupakan tugas yang cukup umum untuk mengunduh sesuatu dan memiliki pemintal untuk itu. Pada dasarnya, Anda bahkan tidak ingin repot -repot melaporkan dalam kasus ini.
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 ( ) ; Tampilan System.Data.DataTable .
System . Data . DataTable dataTable = DataTableFactory ( ) ;
var table = dataTable . FromDataTable ( ) . Border ( TableBorder . Rounded ) ;
AnsiConsole . Render ( ) ; Untuk melihat Spectre.Console beraksi, instal alat global Dotnet-Example.
> dotnet tool restoreSekarang Anda dapat mencantumkan contoh yang tersedia di repositori ini:
> dotnet exampleDan untuk menjalankan contoh:
> dotnet example iprogressUntuk detail lebih lanjut, silakan lihat:
.
| -- Samples
| | -- DataSet
| | -- DataTable
| | -- Directory.Build.props
| | -- http-progress
| | -- iprogress
| ` -- iprogress-http-client-multiple-calls
... Hak Cipta © Alexey Nikiforov.
Disediakan apa adanya di bawah lisensi MIT. Untuk informasi lebih lanjut, lihat lisensi.md.