コード例 #1
0
            /// <summary>
            /// Logs the fact that the operation has progressed.
            /// </summary>
            /// <param name="result">The operation result</param>
            /// <param name="isResourceCreateOrUpdate">Is Create or Update operation, other option include Move etc.</param>
            internal void UpdateProgress(TrackingOperationResult result, bool isResourceCreateOrUpdate)
            {
                if (isResourceCreateOrUpdate)
                {
                    var currentState = this.GetOperationState(result.OperationResult);

                    if (result.Failed || currentState == null || !this.LastState.EqualsInsensitively(currentState))
                    {
                        this.SetProgressPercentageAndWriteProgress(100.0);
                    }

                    if (currentState == null)
                    {
                        return;
                    }

                    this.LastState = currentState;
                }
                else
                {
                    if (result.Failed)
                    {
                        this.SetProgressPercentageAndWriteProgress(100.0);
                    }
                }

                this.SetProgressRecordPercentComplete(result.OperationResult.PercentComplete);
                this.WriteProgressAction(this.ProgressRecord);
            }
コード例 #2
0
        /// <summary>
        /// Indicates an in-progress state.
        /// </summary>
        /// <param name="operationResult">The result of the operation.</param>
        private TrackingOperationResult WaitResult(OperationResult operationResult)
        {
            var result = new TrackingOperationResult
            {
                ShouldWait      = true,
                Failed          = false,
                RetryAfter      = operationResult.RetryAfter ?? LongRunningOperationHelper.DefaultRetryAfter,
                TrackingUri     = operationResult.LocationUri ?? operationResult.OperationUri,
                OperationResult = operationResult,
            };

            this.UpdateProgress(result);
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Indicates a failed terminal state.
        /// </summary>
        /// <param name="operationResult">The result of the operation.</param>
        /// <param name="message">The exception message.</param>
        private void FailedResult(OperationResult operationResult, string message)
        {
            var result = new TrackingOperationResult
            {
                ShouldWait      = false,
                Failed          = true,
                RetryAfter      = operationResult.RetryAfter ?? LongRunningOperationHelper.DefaultRetryAfter,
                TrackingUri     = operationResult.LocationUri ?? operationResult.OperationUri,
                OperationResult = operationResult,
            };

            this.UpdateProgress(result);

            throw new InvalidOperationException(message);
        }
コード例 #4
0
        /// <summary>
        /// Handles the operation response/
        /// </summary>
        /// <param name="operationResult">The result of the operation.</param>
        /// <param name="lastRequestUri">The last <see cref="Uri"/> that was used to request operation state.</param>
        private TrackingOperationResult HandleOperationResponse(OperationResult operationResult, Uri lastRequestUri)
        {
            if (!operationResult.HttpStatusCode.IsSuccessfulRequest())
            {
                if (operationResult.HttpStatusCode.IsServerFailureRequest() ||
                    operationResult.HttpStatusCode == HttpStatusCodeExt.TooManyRequests)
                {
                    var result = new TrackingOperationResult
                    {
                        ShouldWait      = true,
                        Failed          = false,
                        RetryAfter      = operationResult.RetryAfter ?? LongRunningOperationHelper.DefaultRetryAfter,
                        TrackingUri     = lastRequestUri,
                        OperationResult = operationResult,
                    };

                    this.UpdateProgress(result);
                    return(result);
                }
                else
                {
                    this.FailedResult(
                        operationResult,
                        string.Format("The operation failed because the resource provider returned an unexpected HTTP status code of: '{0}'.", (int)operationResult.HttpStatusCode));
                }
            }

            if (operationResult.HttpStatusCode == HttpStatusCode.Accepted)
            {
                return(this.WaitResult(operationResult));
            }

            if (operationResult.HttpStatusCode != HttpStatusCode.OK &&
                operationResult.HttpStatusCode != HttpStatusCode.Created &&
                (!this.IsResourceCreateOrUpdate && operationResult.HttpStatusCode != HttpStatusCode.NoContent))
            {
                this.FailedResult(
                    operationResult,
                    string.Format("The operation failed because the resource provider returned an unexpected HTTP status code of: '{0}'.", (int)operationResult.HttpStatusCode));
            }

            return(this.IsResourceCreateOrUpdate
                ? this.HandleCreateOrUpdateResponse(operationResult)
                : this.SuccessfulResult(operationResult));
        }
コード例 #5
0
 /// <summary>
 /// Logs the fact that the operation has progressed.
 /// </summary>
 /// <param name="result">The operation result</param>
 private void UpdateProgress(TrackingOperationResult result)
 {
     this.ProgressTrackerObject.UpdateProgress(result);
 }
コード例 #6
0
            /// <summary>
            /// Logs the fact that the operation has progressed.
            /// </summary>
            /// <param name="result">The operation result</param>
            internal void UpdateProgress(TrackingOperationResult result)
            {
                var currentState = this.GetOperationState(result.OperationResult);

                if (result.Failed || currentState == null || !this.LastState.EqualsInsensitively(currentState))
                {
                    this.SetProgressRecordPercentComplete(100.0);
                    this.WriteProgressAction(this.ProgressRecord);
                }

                if (currentState == null)
                {
                    return;
                }

                this.LastState = currentState;
                this.SetProgressRecordPercentComplete(result.OperationResult.PercentComplete);
                this.WriteProgressAction(this.ProgressRecord);
            }
コード例 #7
0
 /// <summary>
 /// Logs the fact that the operation has progressed.
 /// </summary>
 /// <param name="result">The operation result</param>
 private void UpdateProgress(TrackingOperationResult result)
 {
     this.ProgressTrackerObject.UpdateProgress(result);
 }
コード例 #8
0
        /// <summary>
        /// Indicates a failed terminal state.
        /// </summary>
        /// <param name="operationResult">The result of the operation.</param>
        /// <param name="message">The exception message.</param>
        private void FailedResult(OperationResult operationResult, string message)
        {
            var result = new TrackingOperationResult
            {
                ShouldWait = false,
                Failed = true,
                RetryAfter = operationResult.RetryAfter ?? LongRunningOperationHelper.DefaultRetryAfter,
                TrackingUri = operationResult.LocationUri ?? operationResult.OperationUri,
                OperationResult = operationResult,
            };

            this.UpdateProgress(result);

            throw new InvalidOperationException(message);
        }
コード例 #9
0
        /// <summary>
        /// Indicates an in-progress state.
        /// </summary>
        /// <param name="operationResult">The result of the operation.</param>
        private TrackingOperationResult WaitResult(OperationResult operationResult)
        {
            var result = new TrackingOperationResult
            {
                ShouldWait = true,
                Failed = false,
                RetryAfter = operationResult.RetryAfter ?? LongRunningOperationHelper.DefaultRetryAfter,
                TrackingUri = operationResult.LocationUri ?? operationResult.OperationUri,
                OperationResult = operationResult,
            };

            this.UpdateProgress(result);
            return result;
        }
コード例 #10
0
        /// <summary>
        /// Handles the operation response/
        /// </summary>
        /// <param name="operationResult">The result of the operation.</param>
        /// <param name="lastRequestUri">The last <see cref="Uri"/> that was used to request operation state.</param>
        private TrackingOperationResult HandleOperationResponse(OperationResult operationResult, Uri lastRequestUri)
        {
            if (!operationResult.HttpStatusCode.IsSuccessfulRequest())
            {
                if (operationResult.HttpStatusCode.IsServerFailureRequest() ||
                    operationResult.HttpStatusCode == HttpStatusCodeExt.TooManyRequests)
                {
                    var result = new TrackingOperationResult
                    {
                        ShouldWait = true,
                        Failed = false,
                        RetryAfter = operationResult.RetryAfter ?? LongRunningOperationHelper.DefaultRetryAfter,
                        TrackingUri = lastRequestUri,
                        OperationResult = operationResult,
                    };

                    this.UpdateProgress(result);
                    return result;
                }
                else
                {
                    this.FailedResult(
                        operationResult,
                        string.Format("The operation failed because the resource provider returned an unexpected HTTP status code of: '{0}'.", (int)operationResult.HttpStatusCode));
                }
            }

            if (operationResult.HttpStatusCode == HttpStatusCode.Accepted)
            {
                return this.WaitResult(operationResult);
            }

            if (operationResult.HttpStatusCode != HttpStatusCode.OK &&
                operationResult.HttpStatusCode != HttpStatusCode.Created &&
                (!this.IsResourceCreateOrUpdate && operationResult.HttpStatusCode != HttpStatusCode.NoContent))
            {
                this.FailedResult(
                    operationResult,
                    string.Format("The operation failed because the resource provider returned an unexpected HTTP status code of: '{0}'.", (int)operationResult.HttpStatusCode));
            }

            return this.IsResourceCreateOrUpdate
                ? this.HandleCreateOrUpdateResponse(operationResult)
                : this.SuccessfulResult(operationResult);

        }
コード例 #11
0
 /// <summary>
 /// Logs the fact that the operation has progressed.
 /// </summary>
 /// <param name="result">The operation result</param>
 private void UpdateProgress(TrackingOperationResult result)
 {
     this.ProgressTrackerObject.UpdateProgress(result, this.IsResourceCreateOrUpdate);
 }
コード例 #12
0
 /// <summary>
 /// Logs the fact that the operation has progressed.
 /// </summary>
 /// <param name="result">The operation result</param>
 private void UpdateProgress(TrackingOperationResult result)
 {
     this.ProgressTrackerObject.UpdateProgress(result, this.IsResourceCreateOrUpdate);
 }