コード例 #1
0
        /// <summary>
        /// Calls the server to get updated status of the long-running operation.
        /// </summary>
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>The HTTP response from the service.</returns>
        private async ValueTask <Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken)
        {
            if (!_hasCompleted)
            {
                Response <CopyOperationResult> update = async
                    ? await _serviceClient.GetCustomModelCopyResultAsync(new Guid(_modelId), new Guid(_resultId), cancellationToken).ConfigureAwait(false)
                    : _serviceClient.GetCustomModelCopyResult(new Guid(_modelId), new Guid(_resultId), cancellationToken);

                _response = update.GetRawResponse();

                if (update.Value.Status == OperationStatus.Succeeded)
                {
                    _hasCompleted = true;
                    _value        = ConvertValue(update.Value, _targetModelId, CustomFormModelStatus.Ready);
                }
                else if (update.Value.Status == OperationStatus.Failed)
                {
                    _hasCompleted = true;
                    _value        = ConvertValue(update.Value, _targetModelId, CustomFormModelStatus.Invalid);
                    throw await CreateExceptionForFailedOperationAsync(async, update.Value.CopyResult.Errors).ConfigureAwait(false);
                }
            }

            return(GetRawResponse());
        }
コード例 #2
0
        /// <summary>
        /// Calls the server to get updated status of the long-running operation.
        /// </summary>
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>The HTTP response from the service.</returns>
        private async ValueTask <Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken)
        {
            if (!_hasCompleted)
            {
                Response <CopyOperationResult> update = async
                    ? await _serviceClient.GetCustomModelCopyResultAsync(new Guid(_modelId), new Guid(_resultId), cancellationToken).ConfigureAwait(false)
                    : _serviceClient.GetCustomModelCopyResult(new Guid(_modelId), new Guid(_resultId), cancellationToken);

                _response = update.GetRawResponse();

                if (update.Value.Status == OperationStatus.Succeeded)
                {
                    // We need to first assign a value and then mark the operation as completed to avoid a race condition with the getter in Value
                    _value        = ConvertValue(update.Value, _targetModelId, CustomFormModelStatus.Ready);
                    _hasCompleted = true;
                }
                else if (update.Value.Status == OperationStatus.Failed)
                {
                    _requestFailedException = await ClientCommon
                                              .CreateExceptionForFailedOperationAsync(async, _diagnostics, _response, update.Value.CopyResult.Errors)
                                              .ConfigureAwait(false);

                    _hasCompleted = true;
                    throw _requestFailedException;
                }
            }

            return(GetRawResponse());
        }