/// <summary> List repositories. </summary> /// <param name="cancellationToken"> The cancellation token to use. </param> public virtual AsyncPageable <string> GetRepositoriesAsync(CancellationToken cancellationToken = default) { return(PageResponseEnumerator.CreateAsyncEnumerable(async(continuationToken, pageSizeHint) => { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryClient)}.{nameof(GetRepositories)}"); scope.Start(); try { Response <Repositories> response = await _restClient.GetRepositoriesAsync( continuationToken, pageSizeHint, cancellationToken) .ConfigureAwait(false); string lastRepository = null; if (!string.IsNullOrEmpty(response.Value.Link)) { Uri nextLink = new Uri(response.Value.Link); NameValueCollection queryParams = HttpUtility.ParseQueryString(nextLink.Query); lastRepository = queryParams["last"]; } return Page <string> .FromValues(response.Value.RepositoriesValue, lastRepository, response.GetRawResponse()); } catch (Exception ex) { scope.Failed(ex); throw; } })); }
/// <summary> List repositories in this registry. </summary> /// <param name="cancellationToken"> The cancellation token to use. </param> /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Container Registry service.</exception> public virtual AsyncPageable <string> GetRepositoryNamesAsync(CancellationToken cancellationToken = default) { async Task <Page <string> > FirstPageFunc(int?pageSizeHint) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryClient)}.{nameof(GetRepositoryNames)}"); scope.Start(); try { ResponseWithHeaders <Repositories, ContainerRegistryGetRepositoriesHeaders> response = await _restClient.GetRepositoriesAsync(last : null, n : pageSizeHint, cancellationToken).ConfigureAwait(false); return(Page.FromValues(response.Value.RepositoriesValue, response.Headers.Link, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } async Task <Page <string> > NextPageFunc(string continuationToken, int?pageSizeHint) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryClient)}.{nameof(GetRepositoryNames)}"); scope.Start(); try { string uriReference = ParseUriReferenceFromLinkHeader(continuationToken); ResponseWithHeaders <Repositories, ContainerRegistryGetRepositoriesHeaders> response = await _restClient.GetRepositoriesNextPageAsync(uriReference, last : null, n : null, cancellationToken).ConfigureAwait(false); return(Page.FromValues(response.Value.RepositoriesValue, response.Headers.Link, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc)); }