public async Task <DailyUsageListSegment> ListDailyUsagesSegmentedAsync(ListingCursor cursor, CancellationToken cancellationToken = default) { if (cursor == null) { throw new ArgumentNullException(nameof(cursor)); } // Generate the additional parameters, where needed var restClient = _restClientFactory.Build(); // Send the request to the Verifalia servers var cursorParamName = cursor.Direction == Direction.Forward ? "cursor" : "cursor:prev"; var queryParams = new Dictionary <string, string> { [cursorParamName] = cursor.Cursor }; if (cursor.Limit > 0) { queryParams["limit"] = cursor.Limit.ToString(CultureInfo.InvariantCulture); } return(await ListDailyUsageSegmentedImplAsync(restClient, queryParams, cancellationToken) .ConfigureAwait(false)); }
private async Task <Validation> RetrieveValidationFromPartialValidationAsync(PartialValidation partialValidation, CancellationToken cancellationToken) { if (partialValidation == null) { throw new ArgumentNullException(nameof(partialValidation)); } var allEntries = new List <ValidationEntry>(partialValidation.Overview.NoOfEntries); var currentSegment = partialValidation.Entries; while (currentSegment?.Data != null) { allEntries.AddRange(currentSegment.Data); if (!currentSegment.Meta.IsTruncated) { break; } var listingCursor = new ListingCursor(currentSegment.Meta.Cursor); currentSegment = await ListEntriesSegmentedAsync(partialValidation.Overview.Id, listingCursor, cancellationToken) .ConfigureAwait(false); } return(new Validation { Overview = partialValidation.Overview, Entries = allEntries }); }
internal static async IAsyncEnumerable <TItem> ToAsyncEnumerable <TList, TItem, TOptions>( Func <TOptions, CancellationToken, Task <TList> > fetchFirstSegment, Func <ListingCursor, CancellationToken, Task <TList> > fetchNextSegment, TOptions options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) where TOptions : ListingOptions where TList : ListSegment <TItem> { ListingCursor cursor = null; while (true) { cancellationToken.ThrowIfCancellationRequested(); // Retrieve the first (or its subsequent) result list segment TList segment; if (cursor == null) { segment = await fetchFirstSegment(options, cancellationToken) .ConfigureAwait(false); } else { segment = await fetchNextSegment(cursor, cancellationToken) .ConfigureAwait(false); } // Iterate the result collection foreach (var item in segment.Data) { yield return(item); } // Stop processing if this is the last segment if (!segment.Meta.IsTruncated) { break; } // Build the cursor for the next iteration cursor = new ListingCursor(segment.Meta.Cursor); if (options != null) { cursor.Limit = options.Limit; cursor.Direction = options.Direction; } ; } }
public async Task <QualityLevelListSegment> ListQualityLevelsSegmentedAsync(ListingCursor cursor, CancellationToken cancellationToken = default) { if (cursor == null) { throw new ArgumentNullException(nameof(cursor)); } // Generate the additional parameters, where needed var restClient = _restClientFactory.Build(); // Send the request to the Verifalia servers var cursorParamName = cursor.Direction == Direction.Forward ? "cursor" : "cursor:prev"; var queryParams = new Dictionary <string, string> { [cursorParamName] = cursor.Cursor }; if (cursor.Limit > 0) { queryParams["limit"] = cursor.Limit.ToString(CultureInfo.InvariantCulture); } using (var response = await restClient .InvokeAsync(HttpMethod.Get, "email-validations/quality-levels", queryParams, headers: new Dictionary <string, object> { { "Accept", WellKnownMimeContentTypes.ApplicationJson } }, cancellationToken: cancellationToken) .ConfigureAwait(false)) { return(await ListQualityLevelsSegmentedImplAsync(restClient, response, cancellationToken) .ConfigureAwait(false)); } }