コード例 #1
0
        /// <summary> List the manifests associated with this repository and the properties of each.
        /// This is useful for determining the collection of artifacts associated with this repository, as each artifact is uniquely identified by its manifest. </summary>
        /// <param name="manifestOrder"> Requested order of manifests in the collection. </param>
        /// <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 <ArtifactManifestProperties> GetAllManifestPropertiesAsync(ArtifactManifestOrder manifestOrder = ArtifactManifestOrder.None, CancellationToken cancellationToken = default)
        {
            async Task <Page <ArtifactManifestProperties> > FirstPageFunc(int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRepository)}.{nameof(GetAllManifestProperties)}");
                scope.Start();
                try
                {
                    string order    = manifestOrder == ArtifactManifestOrder.None ? null : manifestOrder.ToSerialString();
                    var    response = await _restClient.GetManifestsAsync(Name, last : null, n : pageSizeHint, orderby : order, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.RegistryArtifacts, response.Headers.Link, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            async Task <Page <ArtifactManifestProperties> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRepository)}.{nameof(GetAllManifestProperties)}");
                scope.Start();
                try
                {
                    string order        = manifestOrder == ArtifactManifestOrder.None ? null : manifestOrder.ToSerialString();
                    string uriReference = ContainerRegistryClient.ParseUriReferenceFromLinkHeader(nextLink);
                    var    response     = await _restClient.GetManifestsNextPageAsync(uriReference, Name, last : null, n : null, orderby : order, cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.RegistryArtifacts, response.Headers.Link, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc));
        }