
L'objectif de ce projet est d'étendre les plugins Spectre.Console avec quelques fonctionnalités de niche.
IProgress .HttpClient .DataTable .| Emballer | Version | Description |
|---|---|---|
Spectre.Console.Extensions.Progress | Adaptateur iProgress et reportage httpclient. | |
Spectre.Console.Extensions.Table | Prise en charge DataTable et DataSet. |
Extensions pour AnsiConsole.Progress
Utilisez Spectre Spinner avec interface IProgress standard.
Motivation : brancher des méthodes qui acceptent IProgress afin que les rapports soient déclaratifs, familiers, pratiques.
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 ) ;
}
}
} Exécutez des progrès pour un HttpClient donné et HttpRequestMessage . Le résultat est fourni en tant que System.IO.Stream .
Motivation : c'est une tâche assez courante de télécharger quelque chose et d'avoir un spinner pour cela. Fondamentalement, vous ne voulez même pas vous soucier de la déclaration dans ce cas.
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 ( ) ; Afficher System.Data.DataTable .
System . Data . DataTable dataTable = DataTableFactory ( ) ;
var table = dataTable . FromDataTable ( ) . Border ( TableBorder . Rounded ) ;
AnsiConsole . Render ( ) ; Pour voir Spectre.Console en action, installez l'outil global dotnet-exemple.
> dotnet tool restoreVous pouvez maintenant énumérer des exemples disponibles dans ce référentiel:
> dotnet exampleEt pour exécuter un exemple:
> dotnet example iprogressPour plus de détails, veuillez consulter:
.
| -- Samples
| | -- DataSet
| | -- DataTable
| | -- Directory.Build.props
| | -- http-progress
| | -- iprogress
| ` -- iprogress-http-client-multiple-calls
... Copyright © Alexey Nikiforov.
Fourni tel quel sous la licence du MIT. Pour plus d'informations, voir Licence.md.