Esempio n. 1
0
        /// <summary> Get the collection of registry artifacts for a repository. </summary>
        /// <param name="orderBy"> 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> GetManifestsAsync(ManifestOrderBy orderBy = ManifestOrderBy.None, CancellationToken cancellationToken = default)
        {
            async Task <Page <ArtifactManifestProperties> > FirstPageFunc(int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRepository)}.{nameof(GetManifests)}");
                scope.Start();
                try
                {
                    string order    = orderBy == ManifestOrderBy.None ? null : orderBy.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(GetManifests)}");
                scope.Start();
                try
                {
                    string order        = orderBy == ManifestOrderBy.None ? null : orderBy.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));
        }
 public static string ToSerialString(this ManifestOrderBy value) => value switch
 {