private static void BeginGetResponse <T>(ExecutionState <T> executionState)
        {
            executionState.CurrentOperation = ExecutorOperation.BeginGetResponse;
            Logger.LogInformational(executionState.OperationContext, SR.TraceGetResponse);

            try
            {
                APMWithTimeout.RunWithTimeout(
                    executionState.Req.BeginGetResponse,
                    Executor.EndGetResponse <T>,
                    Executor.AbortRequest <T>,
                    executionState,
                    executionState.RemainingTimeout);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(executionState.OperationContext, SR.TraceGetResponseError, ex.Message);
                executionState.ExceptionRef = ExecutorBase.TranslateExceptionBasedOnParseError(ex, executionState.Cmd.CurrentResult, executionState.Resp, executionState.Cmd.ParseError);
                Executor.EndOperation(executionState);
            }
        }
        private static void BeginGetRequestStream <T>(ExecutionState <T> executionState)
        {
            executionState.CurrentOperation = ExecutorOperation.BeginGetRequestStream;
            Logger.LogInformational(executionState.OperationContext, SR.TracePrepareUpload);

            try
            {
                APMWithTimeout.RunWithTimeout(
                    executionState.Req.BeginGetRequestStream,
                    Executor.EndGetRequestStream <T>,
                    Executor.AbortRequest <T>,
                    executionState,
                    executionState.RemainingTimeout);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(executionState.OperationContext, SR.TracePrepareUploadError, ex.Message);
                executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                Executor.EndOperation(executionState);
            }
        }
Exemple #3
0
        private static void BeginGetResponse <T>(ExecutionState <T> executionState)
        {
            try
            {
                APMWithTimeout.RunWithTimeout(
                    executionState.Req.BeginGetResponse,
                    (getRespRes) =>
                {
                    try
                    {
                        executionState.CompletedSynchronously = executionState.CompletedSynchronously && getRespRes.CompletedSynchronously;

                        try
                        {
                            executionState.Resp = executionState.Req.EndGetResponse(getRespRes) as HttpWebResponse;
                        }
                        catch (WebException ex)
                        {
                            executionState.Resp = (HttpWebResponse)ex.Response;

                            if (executionState.Resp == null)
                            {
                                throw;
                            }
                            else
                            {
                                executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                            }
                        }

                        FireResponseReceived(executionState);

                        // 7. Do Response parsing (headers etc, no stream available here)
                        if (executionState.RestCMD.PreProcessResponse != null)
                        {
                            executionState.Result = executionState.RestCMD.PreProcessResponse(executionState.RestCMD, executionState.Resp, executionState.ExceptionRef, executionState.OperationContext);

                            // clear exception
                            executionState.ExceptionRef = null;
                        }

                        CheckCancellation(executionState);

                        // 8. (Potentially reads stream from server)
                        if (executionState.RestCMD.RetrieveResponseStream && executionState.ExceptionRef == null)
                        {
                            executionState.RestCMD.ResponseStream = executionState.Resp.GetResponseStream();

                            if (executionState.RestCMD.DestinationStream != null)
                            {
                                if (executionState.RestCMD.StreamCopyState == null)
                                {
                                    executionState.RestCMD.StreamCopyState = new StreamDescriptor();
                                }

                                executionState.RestCMD.ResponseStream.WriteToAsync(executionState.RestCMD.DestinationStream, null /* maxLength */, executionState.OperationExpiryTime, executionState.RestCMD.CalculateMd5ForResponseStream, executionState, executionState.OperationContext, executionState.RestCMD.StreamCopyState, EndResponseStreamCopy);
                            }
                            else
                            {
                                // Dont want to copy stream, just want to consume it so end
                                EndOperation(executionState);
                            }
                        }
                        else
                        {
                            // End
                            EndOperation(executionState);
                        }
                    }
                    catch (Exception ex)
                    {
                        executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                        EndOperation(executionState);
                    }
                },
                    null,
                    executionState.RemainingTimeout,
                    (getRespRes) =>
                {
                    try
                    {
                        executionState.ReqTimedOut = true;
                        executionState.Req.Abort();
                    }
                    catch (Exception)
                    {
                        // no op
                    }
                });
            }
            catch (Exception ex)
            {
                executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                EndOperation(executionState);
            }
        }
Exemple #4
0
        private static void BeginGetRequestStream <T>(ExecutionState <T> executionState)
        {
            try
            {
                APMWithTimeout.RunWithTimeout(
                    executionState.Req.BeginGetRequestStream,
                    (getRequestStreamResp) =>
                {
                    executionState.CompletedSynchronously = executionState.CompletedSynchronously && getRequestStreamResp.CompletedSynchronously;

                    try
                    {
                        executionState.ReqStream = executionState.Req.EndGetRequestStream(getRequestStreamResp);

                        // don't calculate md5 here as we should have already set this for auth purposes
                        executionState.RestCMD.SendStream.WriteToAsync(executionState.ReqStream, null /* maxLength */, executionState.OperationExpiryTime, false, executionState, executionState.OperationContext, null /* streamCopyState */, EndSendStreamCopy);
                    }
                    catch (WebException ex)
                    {
                        if (ex.Status == WebExceptionStatus.RequestCanceled)
                        {
                            // If the below condition is true, ExceptionRef is set anyway, so don't touch it
                            if (!Executor.CheckCancellation(executionState))
                            {
                                executionState.ExceptionRef = Exceptions.GenerateTimeoutException(executionState.Cmd.CurrentResult, null);
                            }
                        }
                        else
                        {
                            executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                        }

                        EndOperation(executionState);
                    }
                    catch (Exception ex)
                    {
                        executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                        EndOperation(executionState);
                    }
                },
                    null,
                    executionState.RemainingTimeout,
                    (getRequestStreamResp) =>
                {
                    try
                    {
                        executionState.ReqTimedOut = true;
                        executionState.Req.Abort();
                    }
                    catch (Exception)
                    {
                        // no op
                    }
                });
            }
            catch (Exception ex)
            {
                executionState.ExceptionRef = StorageException.TranslateException(ex, executionState.Cmd.CurrentResult);
                EndOperation(executionState);
            }
        }