예제 #1
0
        public static void InitRequest <T>(ExecutionState <T> executionState)
        {
            try
            {
                executionState.Init();

                // 0. Begin Request
                Executor.StartRequestAttempt(executionState);

                // Steps 1 - 4
                Logger.LogInformational(executionState.OperationContext, SR.TraceStartRequestAsync, executionState.Cmd.Uri);
                Executor.ProcessStartOfRequest(executionState);

                if (Executor.CheckTimeout <T>(executionState, false))
                {
                    Executor.EndOperation(executionState);
                    return;
                }

                lock (executionState.CancellationLockerObject)
                {
                    if (Executor.CheckCancellation(executionState))
                    {
                        Executor.EndOperation(executionState);
                        return;
                    }

                    // 5. potentially upload data
                    if (executionState.RestCMD.SendStream != null)
                    {
                        Executor.BeginGetRequestStream(executionState);
                    }
                    else
                    {
                        Executor.BeginGetResponse(executionState);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(executionState.OperationContext, SR.TraceInitRequestError, ex.Message);

                // Store exception and invoke callback here. All operations in this try would be non-retryable by default
                StorageException storageEx = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                storageEx.IsRetryable       = false;
                executionState.ExceptionRef = storageEx;
                executionState.OnComplete();
            }
        }
예제 #2
0
        private static void EndSendStreamCopy <T>(ExecutionState <T> executionState)
        {
            executionState.CurrentOperation = ExecutorOperation.EndUploadRequest;

            lock (executionState.CancellationLockerObject)
            {
                Executor.CheckCancellation(executionState);

                if (executionState.ExceptionRef != null)
                {
                    try
                    {
                        executionState.Req.Abort();
                    }
                    catch (Exception)
                    {
                        // No op
                    }

                    Executor.EndOperation(executionState);
                }
                else
                {
                    try
                    {
                        executionState.ReqStream.Flush();
                        executionState.ReqStream.Dispose();
                        executionState.ReqStream = null;
                    }
                    catch (Exception)
                    {
                        // If we could not flush/dispose the request stream properly,
                        // BeginGetResponse will fail with a more meaningful error anyway.
                    }

                    Executor.BeginGetResponse(executionState);
                }
            }
        }