예제 #1
0
        /// <summary>
        /// Updates the status of the certificate operation.
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>The raw response of the poll operation.</returns>
        public override async ValueTask <Response> UpdateStatusAsync(CancellationToken cancellationToken = default)
        {
            if (!_completed)
            {
                Response <CertificateOperationProperties> pollResponse = await _client.GetPendingCertificateAsync(Properties.Name, cancellationToken).ConfigureAwait(false);

                _response = pollResponse.GetRawResponse();

                Properties = pollResponse;

                // Properties will be null if deleted.
                if (Properties is null)
                {
                    _completed = true;
                    return(_response);
                }
            }

            if (Properties.Status == "completed")
            {
                Response <KeyVaultCertificateWithPolicy> getResponse = await _client.GetCertificateAsync(Properties.Name, cancellationToken).ConfigureAwait(false);

                _response = getResponse.GetRawResponse();

                _value = getResponse.Value;

                _completed = true;
            }
            else if (Properties.Status == "cancelled")
            {
                _completed = true;
            }
            else if (Properties.Error != null)
            {
                _completed = true;
            }

            return(GetRawResponse());
        }
        /// <summary>
        /// Updates the status of the certificate operation
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>The raw response of the poll operation</returns>
        public override async ValueTask <Response> UpdateStatusAsync(CancellationToken cancellationToken = default)
        {
            if (!_completed)
            {
                Response <CertificateOperationProperties> pollResponse = await _client.GetPendingCertificateAsync(Properties.Name, cancellationToken).ConfigureAwait(false);

                SetRawResponse(pollResponse.GetRawResponse());

                Properties = pollResponse;
            }

            if (Properties.Status == "completed")
            {
                Response <CertificateWithPolicy> getResponse = await _client.GetCertificateWithPolicyAsync(Properties.Name, cancellationToken).ConfigureAwait(false);

                SetRawResponse(getResponse.GetRawResponse());

                Value = getResponse.Value;

                _completed = true;

                _hasValue = true;
            }
            else if (Properties.Status == "cancelled")
            {
                _completed = true;

                throw new OperationCanceledException("The certificate opertation has been canceled");
            }
            else if (Properties.Error != null)
            {
                _completed = true;

                throw new InvalidOperationException("The certificate operation failed, see Properties.Error for more details");
            }

            return(GetRawResponse());
        }