Example #1
0
        public ResponseWithHeaders <MessageIdDeleteHeaders> Delete(string messageid, string popReceipt, int?timeout = null, CancellationToken cancellationToken = default)
        {
            if (messageid == null)
            {
                throw new ArgumentNullException(nameof(messageid));
            }
            if (popReceipt == null)
            {
                throw new ArgumentNullException(nameof(popReceipt));
            }

            using var message = CreateDeleteRequest(messageid, popReceipt, timeout);
            _pipeline.Send(message, cancellationToken);
            var headers = new MessageIdDeleteHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 204:
                return(ResponseWithHeaders.FromValue(headers, message.Response));

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
Example #2
0
        public ResponseWithHeaders <ContainerRegistryBlobUploadChunkHeaders> UploadChunk(string nextLink, Stream value, CancellationToken cancellationToken = default)
        {
            if (nextLink == null)
            {
                throw new ArgumentNullException(nameof(nextLink));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            using var message = CreateUploadChunkRequest(nextLink, value);
            _pipeline.Send(message, cancellationToken);
            var headers = new ContainerRegistryBlobUploadChunkHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 202:
                return(ResponseWithHeaders.FromValue(headers, message.Response));

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
        public ResponseWithHeaders <BlobDeleteHeaders> Delete(string containerName, string blob, int?timeout = null, string leaseId = null, DeleteSnapshotsOptionType?deleteSnapshots = null, DateTimeOffset?ifModifiedSince = null, DateTimeOffset?ifUnmodifiedSince = null, string ifMatch = null, string ifNoneMatch = null, string ifTags = null, BlobDeleteType?blobDeleteType = null, CancellationToken cancellationToken = default)
        {
            if (containerName == null)
            {
                throw new ArgumentNullException(nameof(containerName));
            }
            if (blob == null)
            {
                throw new ArgumentNullException(nameof(blob));
            }

            using var message = CreateDeleteRequest(containerName, blob, timeout, leaseId, deleteSnapshots, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, ifTags, blobDeleteType);
            _pipeline.Send(message, cancellationToken);
            var headers = new BlobDeleteHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 202:
                return(ResponseWithHeaders.FromValue(headers, message.Response));

            default:
                throw ClientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
        public ResponseWithHeaders <PhoneNumbersSearchAvailablePhoneNumbersHeaders> SearchAvailablePhoneNumbers(string countryCode, PhoneNumberSearchRequest body, CancellationToken cancellationToken = default)
        {
            if (countryCode == null)
            {
                throw new ArgumentNullException(nameof(countryCode));
            }
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            using var message = CreateSearchAvailablePhoneNumbersRequest(countryCode, body);
            _pipeline.Send(message, cancellationToken);
            var headers = new PhoneNumbersSearchAvailablePhoneNumbersHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 202:
                return(ResponseWithHeaders.FromValue(headers, message.Response));

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
Example #5
0
        public virtual Response <ExtractedReceipt> ExtractReceipt(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default)
        {
            SourcePath_internal sourcePath = new SourcePath_internal()
            {
                Source = uri.ToString()
            };
            ResponseWithHeaders <AnalyzeReceiptAsyncHeaders> response = _operations.RestClient.AnalyzeReceiptAsync(includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken);
            var operation = new ExtractReceiptOperation(_operations, response.Headers.OperationLocation);

            ValueTask <Response <ExtractedReceipt> > task = operation.WaitForCompletionAsync();

            // TODO: this feels very bad.  Better way?
            // https://github.com/Azure/azure-sdk-for-net/issues/10391
            task.AsTask().Wait();

            if (!operation.HasValue)
            {
                throw new RequestFailedException("Failed to retrieve response from ExtractReceipt Long-Running Operation");
            }

            // TODO: this is also a mess. Reconcile these together.
            // https://github.com/Azure/azure-sdk-for-net/issues/10391
            return(Response.FromValue(operation.Value, task.AsTask().Result.GetRawResponse()));
        }
        /// <summary>
        /// Trains a model from a collection of custom forms in a blob storage container.
        /// </summary>
        /// <param name="trainingFilesUri">An externally accessible Azure storage blob container Uri.
        /// For more information see <a href="https://docs.microsoft.com/azure/cognitive-services/form-recognizer/build-training-data-set#upload-your-training-data"/>.</param>
        /// <param name="useTrainingLabels">If <c>true</c>, use a label file created in the &lt;link-to-label-tool-doc&gt; to provide training-time labels for training a model. If <c>false</c>, the model will be trained from forms only.</param>
        /// <param name="trainingOptions">A set of options available for configuring the training request.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>
        /// <para>A <see cref="TrainingOperation"/> to wait on this long-running operation. Its <see cref="TrainingOperation.Value"/> upon successful
        /// completion will contain meta-data about the trained model.</para>
        /// <para>Even if training fails, a model is created in the Form Recognizer account with an "invalid" status.
        /// A <see cref="RequestFailedException"/> will be raised containing the modelId to access this invalid model.</para>
        /// </returns>
        public virtual TrainingOperation StartTraining(Uri trainingFilesUri, bool useTrainingLabels, TrainingOptions trainingOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(trainingFilesUri, nameof(trainingFilesUri));
            trainingOptions ??= new TrainingOptions();

            using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormTrainingClient)}.{nameof(StartTraining)}");
            scope.Start();

            try
            {
                var trainRequest = new TrainRequest(trainingFilesUri.AbsoluteUri)
                {
                    SourceFilter = trainingOptions.TrainingFileFilter, UseLabelFile = useTrainingLabels
                };

                ResponseWithHeaders <ServiceTrainCustomModelAsyncHeaders> response = ServiceClient.TrainCustomModelAsync(trainRequest);
                return(new TrainingOperation(response.Headers.Location, ServiceClient, Diagnostics));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async Task <ResponseWithHeaders <Stream, SchemaGetByIdHeaders> > GetByIdAsync(string schemaId, CancellationToken cancellationToken = default)
        {
            if (schemaId == null)
            {
                throw new ArgumentNullException(nameof(schemaId));
            }

            using var message = CreateGetByIdRequest(schemaId);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new SchemaGetByIdHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                var value = message.ExtractResponseContent();
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
Example #8
0
        public ResponseWithHeaders <string, SchemaGetByIdHeaders> GetById(string schemaId, CancellationToken cancellationToken = default)
        {
            if (schemaId == null)
            {
                throw new ArgumentNullException(nameof(schemaId));
            }

            using var message = CreateGetByIdRequest(schemaId);
            _pipeline.Send(message, cancellationToken);
            var headers = new SchemaGetByIdHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                StreamReader streamReader = new StreamReader(message.Response.ContentStream);
                string       value        = streamReader.ReadToEnd();
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
Example #9
0
        public ResponseWithHeaders <ContainerRegistryBlobCompleteUploadHeaders> CompleteUpload(string digest, string location, Stream value = null, CancellationToken cancellationToken = default)
        {
            if (digest == null)
            {
                throw new ArgumentNullException(nameof(digest));
            }
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            using var message = CreateCompleteUploadRequest(digest, location, value);
            _pipeline.Send(message, cancellationToken);
            var headers = new ContainerRegistryBlobCompleteUploadHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 201:
                return(ResponseWithHeaders.FromValue(headers, message.Response));

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
        public async Task <ResponseWithHeaders <QueueServiceStatistics, ServiceGetStatisticsHeaders> > GetStatisticsAsync(int?timeout = null, CancellationToken cancellationToken = default)
        {
            using var message = CreateGetStatisticsRequest(timeout);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new ServiceGetStatisticsHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                QueueServiceStatistics value = default;
                var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
                if (document.Element("StorageServiceStats") is XElement storageServiceStatsElement)
                {
                    value = QueueServiceStatistics.DeserializeQueueServiceStatistics(storageServiceStatsElement);
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
        public async ValueTask <ResponseWithHeaders <TableServiceProperties, ServiceGetPropertiesHeaders> > GetPropertiesAsync(int?timeout = null, string requestId = null, CancellationToken cancellationToken = default)
        {
            using var message = CreateGetPropertiesRequest(timeout, requestId);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new ServiceGetPropertiesHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                TableServiceProperties value = default;
                var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
                if (document.Element("TableServiceProperties") is XElement tableServicePropertiesElement)
                {
                    value = TableServiceProperties.DeserializeTableServiceProperties(tableServicePropertiesElement);
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
        public async Task <ResponseWithHeaders <ListQueuesSegmentResponse, ServiceListQueuesSegmentHeaders> > ListQueuesSegmentAsync(string prefix = null, string marker = null, int?maxresults = null, IEnumerable <string> include = null, int?timeout = null, CancellationToken cancellationToken = default)
        {
            using var message = CreateListQueuesSegmentRequest(prefix, marker, maxresults, include, timeout);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new ServiceListQueuesSegmentHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                ListQueuesSegmentResponse value = default;
                var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
                if (document.Element("EnumerationResults") is XElement enumerationResultsElement)
                {
                    value = ListQueuesSegmentResponse.DeserializeListQueuesSegmentResponse(enumerationResultsElement);
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
        public async ValueTask <ResponseWithHeaders <TableQueryResponse, TableInternalQueryHeaders> > QueryAsync(string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default)
        {
            using var message = CreateQueryRequest(requestId, queryOptions);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new TableInternalQueryHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                TableQueryResponse value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                if (document.RootElement.ValueKind == JsonValueKind.Null)
                {
                    value = null;
                }
                else
                {
                    value = TableQueryResponse.DeserializeTableQueryResponse(document.RootElement);
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }
        /// <summary>
        /// Get the status results for all submitted translation operations.
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        public virtual AsyncPageable <TranslationStatusResult> GetTranslationsAsync(CancellationToken cancellationToken = default)
        {
            async Task <Page <TranslationStatusResult> > FirstPageFunc(int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(GetTranslations)}");
                scope.Start();

                try
                {
                    ResponseWithHeaders <BatchStatusResponse, DocumentTranslationGetOperationsHeaders> response = await _serviceRestClient.GetOperationsAsync(cancellationToken : cancellationToken).ConfigureAwait(false);

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

            async Task <Page <TranslationStatusResult> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(GetTranslations)}");
                scope.Start();

                try
                {
                    Response <BatchStatusResponse> response = await _serviceRestClient.GetOperationsNextPageAsync(nextLink, cancellationToken : cancellationToken).ConfigureAwait(false);

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

            return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc));
        }
 /// <summary>
 /// Initializes a new instance of a RestoreOperation.
 /// </summary>
 /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
 /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartRestore"/> or <see cref="KeyVaultBackupClient.StartRestoreAsync"/>.</param>
 /// <exception cref="ArgumentNullException"><paramref name="client"/> or <paramref name="response"/> is null.</exception>
 internal RestoreOperation(KeyVaultBackupClient client, ResponseWithHeaders <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders> response)
 {
     _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders, RestoreResult, RestoreDetailsInternal>(client, response);
 }
        /// <summary> Insert entity in a table. </summary>
        /// <param name="async">Determines whether execution will occur asynchronously.</param>
        /// <param name="table"> The name of the table. </param>
        /// <param name="timeout"> The The timeout parameter is expressed in seconds. For more information, see &lt;a href=&quot;https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations&gt;Setting Timeouts for Queue Service Operations.&lt;/a&gt;. </param>
        /// <param name="requestId"> Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. </param>
        /// <param name="tableEntityProperties"> The properties for the table entity. </param>
        /// <param name="queryOptions"> Parameter group. </param>
        /// <param name="cancellationToken"> The cancellation token to use. </param>
        private async ValueTask <ResponseWithHeaders <ReadOnlyDictionary <string, object>, TableInternalInsertEntityHeaders> > InsertEntityInternalAsync(bool async, string table, int?timeout = null, string requestId = null, IDictionary <string, object> tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            using var scope = _clientDiagnostics.CreateScope("TableInternalClient.InsertEntity");
            scope.Start();
            try
            {
                using var message = CreateInsertEntityRequest(table, timeout, requestId, tableEntityProperties, queryOptions);
                if (async)
                {
                    await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    _pipeline.Send(message, cancellationToken);
                }

                var headers = new TableInternalInsertEntityHeaders(message.Response);
                switch (message.Response.Status)
                {
                case 201:
                {
                    Dictionary <string, object> value = default;
                    JsonDocument document;
                    if (async)
                    {
                        document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        document = JsonDocument.Parse(message.Response.ContentStream);
                    }
                    using (document)
                    {
                        if (document.RootElement.ValueKind == JsonValueKind.Null)
                        {
                            value = null;
                        }
                        else
                        {
                            Dictionary <string, object> dictionary = new Dictionary <string, object>();
                            foreach (var property in document.RootElement.EnumerateObject())
                            {
                                if (property.Value.ValueKind == JsonValueKind.Null)
                                {
                                    dictionary.Add(property.Name, null);
                                }
                                else
                                {
                                    dictionary.Add(property.Name, property.Value.GetObject());
                                }
                            }
                            value = dictionary;
                        }
                        return(ResponseWithHeaders.FromValue(new ReadOnlyDictionary <string, object>(value), headers, message.Response));
                    }
                }
Example #17
0
        /// <summary>
        /// Get the list of the document formats supported by the Document Translation service.
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        public virtual async Task<Response<IReadOnlyList<DocumentTranslationFileFormat>>> GetSupportedDocumentFormatsAsync(CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(GetSupportedDocumentFormats)}");
            scope.Start();

            try
            {
                ResponseWithHeaders<SupportedFileFormats, DocumentTranslationGetSupportedDocumentFormatsHeaders> response = await _serviceRestClient.GetSupportedDocumentFormatsAsync(cancellationToken).ConfigureAwait(false);
                return Response.FromValue(response.Value.Value, response.GetRawResponse());
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        /// <summary>
        /// Get the list of the glossary formats supported by the Document Translation service.
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        public virtual Response <IReadOnlyList <FileFormat> > GetGlossaryFormats(CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(GetGlossaryFormats)}");
            scope.Start();

            try
            {
                ResponseWithHeaders <SupportedFileFormats, DocumentTranslationGetSupportedGlossaryFormatsHeaders> response = _serviceRestClient.GetSupportedGlossaryFormats(cancellationToken);
                return(Response.FromValue(response.Value.Value, response.GetRawResponse()));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        /// <summary>
        /// Get the status results for all submitted translation operations.
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        public virtual Pageable <TranslationStatusResult> GetTranslations(CancellationToken cancellationToken = default)
        {
            Page <TranslationStatusResult> FirstPageFunc(int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(GetTranslations)}");
                scope.Start();

                try
                {
                    ResponseWithHeaders <TranslationsStatus, DocumentTranslationGetTranslationsStatusHeaders> response = _serviceRestClient.GetTranslationsStatus(cancellationToken: cancellationToken);
                    return(Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            Page <TranslationStatusResult> NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(GetTranslations)}");
                scope.Start();

                try
                {
                    ResponseWithHeaders <TranslationsStatus, DocumentTranslationGetTranslationsStatusHeaders> response = _serviceRestClient.GetTranslationsStatusNextPage(nextLink, cancellationToken: cancellationToken);
                    return(Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc));
        }
 /// <summary>
 /// Gets the status of an Object Anchors asset conversion job.
 /// </summary>
 /// <param name="JobId">The asset conversion job's ID.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns><see cref="Response{AssetConversionProperties}"/>.</returns>
 internal virtual Response <AssetConversionProperties> GetAssetConversionStatus(Guid JobId, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ObjectAnchorsConversionClient)}.{nameof(GetAssetConversionStatus)}");
     scope.Start();
     try
     {
         ResponseWithHeaders <AssetConversionProperties, IngestionJobGetHeaders> properties = _ingestionJobRestClient
                                                                                              .Get(AccountId, JobId, xMrcCv: GenerateCv(), cancellationToken: cancellationToken);
         properties.Value.JobId     = JobId;
         properties.Value.AccountId = AccountId;
         return(properties);
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }
Example #21
0
        /// <summary>
        /// Retrieve a token from the STS service for the specified account identifier asynchronously.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns><see cref="Response{AccessToken}"/>.</returns>
        public virtual async Task <Response <AccessToken> > GetTokenAsync(CancellationToken cancellationToken = default)
        {
            MixedRealityTokenRequestOptions headerOptions = MixedRealityTokenRequestOptions.GenerateNew();

            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MixedRealityStsClient)}.{nameof(GetToken)}");
            scope.AddAttribute(nameof(headerOptions.ClientRequestId), headerOptions.ClientRequestId);
            scope.Start();

            try
            {
                ResponseWithHeaders <StsTokenResponseMessage, MixedRealityStsGetTokenHeaders> response = await _restClient.GetTokenAsync(AccountId, headerOptions, cancellationToken).ConfigureAwait(false);

                return(ResponseWithHeaders.FromValue(response.Value.ToAccessToken(), response.Headers, response.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
Example #22
0
        /// <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 Pageable <string> GetRepositoryNames(CancellationToken cancellationToken = default)
        {
            Page <string> FirstPageFunc(int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryClient)}.{nameof(GetRepositoryNames)}");
                scope.Start();
                try
                {
                    ResponseWithHeaders <Repositories, ContainerRegistryGetRepositoriesHeaders> response = _restClient.GetRepositories(last: null, n: pageSizeHint, cancellationToken);
                    return(Page.FromValues(response.Value.RepositoriesValue, response.Headers.Link, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            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 = _restClient.GetRepositoriesNextPage(uriReference, last: null, n: null, cancellationToken);
                    return(Page.FromValues(response.Value.RepositoriesValue, response.Headers.Link, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc));
        }
 /// <summary>
 /// Initializes a new instance of a SelectiveKeyRestoreOperation.
 /// </summary>
 /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
 /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartRestore"/> or <see cref="KeyVaultBackupClient.StartRestoreAsync"/>.</param>
 /// <exception cref="ArgumentNullException"><paramref name="client"/> or <paramref name="response"/> is null.</exception>
 internal SelectiveKeyRestoreOperation(KeyVaultBackupClient client, ResponseWithHeaders <AzureSecurityKeyVaultAdministrationSelectiveKeyRestoreOperationHeaders> response)
 {
     _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationSelectiveKeyRestoreOperationHeaders, SelectiveKeyRestoreResult>(client, response);
 }