/// <summary> /// Gets a collection of items describing the models trained on this Cognitive Services Account /// and their training status. /// </summary> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>A collection of <see cref="CustomFormModelInfo"/> items.</returns> public virtual AsyncPageable <CustomFormModelInfo> GetCustomModelsAsync(CancellationToken cancellationToken = default) { async Task <Page <CustomFormModelInfo> > FirstPageFunc(int?pageSizeHint) { using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormTrainingClient)}.{nameof(GetCustomModels)}"); scope.Start(); try { Response <Models.Models> response = await ServiceClient.ListCustomModelsAsync(cancellationToken).ConfigureAwait(false); return(Page.FromValues(response.Value.ModelList, response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } async Task <Page <CustomFormModelInfo> > NextPageFunc(string nextLink, int?pageSizeHint) { using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormTrainingClient)}.{nameof(GetCustomModels)}"); scope.Start(); try { Response <Models.Models> response = await ServiceClient.ListCustomModelsNextPageAsync(nextLink, cancellationToken).ConfigureAwait(false); return(Page.FromValues(response.Value.ModelList, response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc)); }