public Carpenter(HttpClient http, ProgressTask task, HammerSettings settings) { var strengths = GetStrengths(settings.Min, settings.Max); task.MaxValue(strengths.Sum(s => s)); _tool = new Hammer(http, () => Factory.Message(settings), () => task.Increment(1), strengths); }
public Driller(HttpClient http, ProgressTask task, DrillSettings settings) { var requests = (uint)settings.RPS * settings.Duration; var delay = Stopwatch.Frequency / settings.RPS; task.MaxValue(requests); _tool = new Drill(http, () => Factory.Message(settings), () => task.Increment(1), requests, delay); }
/// <summary> /// Download the file at the specified uri /// </summary> /// <param name="client">The <see cref="HttpClient"/> used to download</param> /// <param name="fileUri">The file uri</param> /// <param name="outputStream">The output <see cref="Stream"/></param> /// <param name="progress">The <see cref="ProgressTask"/> to use</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/></param> /// <returns>A new awaitable <see cref="Task"/></returns> public static async Task DownloadAsync(this HttpClient client, string fileUri, Stream outputStream, ProgressTask progress, CancellationToken cancellationToken = default) { using (HttpResponseMessage response = await client.GetAsync(fileUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken)) { response.EnsureSuccessStatusCode(); progress.MaxValue(response.Content.Headers.ContentLength ?? 0); progress.StartTask(); var filename = fileUri.Substring(fileUri.LastIndexOf('/') + 1); using var contentStream = await response.Content.ReadAsStreamAsync(cancellationToken); var buffer = new byte[8192]; while (true) { var bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length, cancellationToken); if (bytesRead == 0) { break; } progress.Increment(bytesRead); await outputStream.WriteAsync(buffer, 0, bytesRead, cancellationToken); } } }
private static void UpdateProgress(ICollectionContext ctx, ProgressTask progressTask) { progressTask.MaxValue(ctx.ResultTotal); progressTask.Increment(ctx.ResultCount); }
public Nailer(HttpClient http, ProgressTask task, NailgunSettings settings) { task.MaxValue(settings.Requests); _tool = new Nailgun(http, () => Factory.Message(settings), () => task.Increment(1), settings.Requests); }