protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { IAsyncRequestContext requestContext = executionContext.RequestContext; IAsyncResponseContext responseContext = executionContext.ResponseContext; Exception exception = responseContext.AsyncResult.Exception; IExecutionContext executionContext2 = ExecutionContext.CreateFromAsyncContext(executionContext); if (exception != null) { if (RetryPolicy.Retry(executionContext2, exception)) { requestContext.Retries++; requestContext.Metrics.SetCounter(Metric.AttemptCount, requestContext.Retries); LogForRetry(requestContext, exception); PrepareForRetry(requestContext); responseContext.AsyncResult.Exception = null; using (requestContext.Metrics.StartEvent(Metric.RetryPauseTime)) { RetryPolicy.WaitBeforeRetry(executionContext2); } InvokeAsync(executionContext); return; } LogForError(requestContext, exception); } else { RetryPolicy.NotifySuccess(executionContext2); } base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Invokes the inner handler /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { try { var requestContext = executionContext.RequestContext; var responseContext = executionContext.ResponseContext; var regionalEndpoint = requestContext.Request.Endpoint; var exception = responseContext.AsyncResult.Exception; if (exception != null) { if (IsInvalidEndpointException(exception)) { EvictCacheKeyForRequest(requestContext, regionalEndpoint); } } else { PreInvoke(ExecutionContext.CreateFromAsyncContext(executionContext)); } } catch (Exception e) { executionContext.ResponseContext.AsyncResult.Exception = e; } finally { // Call outer handler base.InvokeAsyncCallback(executionContext); } }
/// <summary> /// Invokes the inner handler and performs a retry, if required as per the /// retry policy. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { var requestContext = executionContext.RequestContext; var responseContext = executionContext.ResponseContext; var exception = responseContext.AsyncResult.Exception; if (exception != null) { var syncExecutionContext = ExecutionContext.CreateFromAsyncContext(executionContext); var shouldRetry = this.RetryPolicy.Retry(syncExecutionContext, exception); if (shouldRetry) { requestContext.Retries++; requestContext.Metrics.SetCounter(Metric.AttemptCount, requestContext.Retries); LogForRetry(requestContext, exception); PrepareForRetry(requestContext); using (requestContext.Metrics.StartEvent(Metric.RetryPauseTime)) this.RetryPolicy.WaitBeforeRetry(syncExecutionContext); // Retry by calling InvokeAsync this.InvokeAsync(executionContext); return; } else { LogForError(requestContext, exception); } } // Call outer handler base.InvokeAsyncCallback(executionContext); }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { this.CallCount++; try { if (this.Action != null) { Action(this.CallCount); } if (this.Action2 != null) { Action2(this.CallCount, Amazon.Runtime.Internal.ExecutionContext.CreateFromAsyncContext(executionContext)); } if (this.Validate != null) { Validate(this.CallCount); } } catch (Exception exception) { executionContext.ResponseContext.AsyncResult.Exception = exception; } base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Calls the PostInvoke methods after calling the next handler /// in the pipeline. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { IExecutionContext syncExecutionContext = ExecutionContext.CreateFromAsyncContext(executionContext); // Process the response if an exception hasn't occured if (executionContext.ResponseContext.AsyncResult.Exception == null) { byte[] encryptedKMSEnvelopeKey; Dictionary <string, string> encryptionContext; if (KMSEnvelopeKeyIsPresent(syncExecutionContext, out encryptedKMSEnvelopeKey, out encryptionContext)) { throw new NotSupportedException("The AWS SDK for .NET Framework 3.5 version of " + EncryptionClient.GetType().Name + " does not support KMS key wrapping via the async programming model. " + "Please use the synchronous version instead."); } var getObjectResponse = executionContext.ResponseContext.Response as GetObjectResponse; if (getObjectResponse != null) { DecryptObject(encryptedKMSEnvelopeKey, getObjectResponse); } var completeMultiPartUploadRequest = executionContext.RequestContext.Request.OriginalRequest as CompleteMultipartUploadRequest; var completeMultipartUploadResponse = executionContext.ResponseContext.Response as CompleteMultipartUploadResponse; if (completeMultipartUploadResponse != null) { CompleteMultipartUpload(completeMultiPartUploadRequest); } PostInvokeSynchronous(syncExecutionContext, null); } base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Processes HTTP redirects and reissues the call to the /// redirected location. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { var exception = executionContext.ResponseContext.AsyncResult.Exception; if (exception != null) { var webException = exception as WebException; var httpException = exception as HttpErrorResponseException; if (webException == null && httpException != null) { webException = httpException.InnerException as WebException; } if (webException != null) { // Call InvokeAsync to redirect to new location. if (HandleRedirect(ExecutionContext.CreateFromAsyncContext(executionContext), webException)) { executionContext.ResponseContext.AsyncResult.Exception = null; RetryHandler.PrepareForRetry(executionContext.RequestContext); base.InvokeAsync(executionContext); return; } } } // Not a redirect, call outer callbacks to continue processing response. base.InvokeAsyncCallback(executionContext); }
private void GetResponseCallbackHelper(object state) { IAsyncResult result = state as IAsyncResult; IAsyncExecutionContext executionContext = null; IHttpRequest <TRequestContent> httpRequest = null; try { executionContext = result.AsyncState as IAsyncExecutionContext; httpRequest = executionContext.RuntimeState as IHttpRequest <TRequestContent>; var httpResponse = httpRequest.EndGetResponse(result); executionContext.ResponseContext.HttpResponse = httpResponse; } catch (Exception exception) { // Capture the exception and invoke outer handlers to // process the exception. executionContext.ResponseContext.AsyncResult.Exception = exception; } finally { executionContext.RequestContext.Metrics.StopEvent(Metric.HttpRequestTime); httpRequest.Dispose(); base.InvokeAsyncCallback(executionContext); } }
private void GetRequestStreamCallbackHelper(object state) { IAsyncResult result = state as IAsyncResult; IAsyncExecutionContext executionContext = null; IHttpRequest <TRequestContent> httpRequest = null; try { executionContext = result.AsyncState as IAsyncExecutionContext; httpRequest = executionContext.RuntimeState as IHttpRequest <TRequestContent>; var requestContent = httpRequest.EndGetRequestContent(result); WriteContentToRequestBody(requestContent, httpRequest, executionContext.RequestContext); //var requestStream = httpRequest.EndSetRequestBody(result); httpRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), executionContext); } catch (Exception exception) { httpRequest.Dispose(); // Capture the exception and invoke outer handlers to // process the exception. executionContext.ResponseContext.AsyncResult.Exception = exception; base.InvokeAsyncCallback(executionContext); } }
/// <summary> /// Calls pre invoke logic before calling the next handler /// in the pipeline. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <returns>IAsyncResult which represent an async operation.</returns> public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { IExecutionContext syncExecutionContext = ExecutionContext.CreateFromAsyncContext(executionContext); ThrowIfRangeGet(syncExecutionContext); if (NeedToGenerateKMSInstructions(syncExecutionContext)) { throw new NotSupportedException("The AWS SDK for .NET Framework 3.5 version of " + EncryptionClient.GetType().Name + " does not support KMS key wrapping via the async programming model. " + "Please use the synchronous version instead."); } var instructions = GenerateInstructions(syncExecutionContext); var putObjectRequest = syncExecutionContext.RequestContext.OriginalRequest as PutObjectRequest; if (putObjectRequest != null) { EncryptObject(instructions, putObjectRequest); } PreInvokeSynchronous(syncExecutionContext, instructions); return(base.InvokeAsync(executionContext)); }
/// <summary> /// This callback method is called by the callback method of the inner handler /// as part of asynchronous processing after any underlying asynchronous /// operations complete. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> public void AsyncCallback(IAsyncExecutionContext executionContext) { try { this.InvokeAsyncCallback(executionContext); } catch (Exception exception) { // Log exception this.Logger.Error(exception, string.Format("An exception of type {0} was thrown from InvokeAsyncCallback().", exception.GetType().Name)); executionContext.RequestContext.Metrics.AddProperty(Metric.Exception, exception); // An unhandled exception occured in the callback implementation. // Capture the exception and end the callback processing by signalling the // wait handle. executionContext.RequestContext.Metrics.StopEvent(Metric.ClientExecuteTime); LogMetrics(ExecutionContext.CreateFromAsyncContext(executionContext)); var asyncResult = executionContext.ResponseContext.AsyncResult; asyncResult.Exception = exception; asyncResult.SignalWaitHandle(); if (asyncResult.AsyncCallback != null) { asyncResult.AsyncCallback(asyncResult); } } }
private void ProcessPostResponse(IAsyncResult result) { IAsyncExecutionContext executionContext = null; IHttpRequest <string> httpRequest = null; try { executionContext = result.AsyncState as IAsyncExecutionContext; httpRequest = executionContext.RuntimeState as IHttpRequest <string>; var httpResponse = httpRequest.EndGetResponse(result); executionContext.ResponseContext.HttpResponse = httpResponse; } catch (Exception exception) { // Capture the exception and invoke outer handlers to // process the exception. executionContext.ResponseContext.AsyncResult.Exception = exception; } finally { httpRequest.Dispose(); } PostResponseHelper(result); }
private void PostResponseHelper(IAsyncResult result) { IAsyncExecutionContext executionContext = result.AsyncState as IAsyncExecutionContext; IWebResponseData response = executionContext.ResponseContext.HttpResponse; RuntimeAsyncResult asyncResult = executionContext.ResponseContext.AsyncResult as RuntimeAsyncResult; if (executionContext.ResponseContext.AsyncResult.Exception == null) { PostObjectResponse postResponse = new PostObjectResponse(); postResponse.HttpStatusCode = response.StatusCode; postResponse.ContentLength = response.ContentLength; if (response.IsHeaderPresent(HeaderKeys.XAmzRequestIdHeader)) { postResponse.RequestId = response.GetHeaderValue(HeaderKeys.XAmzRequestIdHeader); } if (response.IsHeaderPresent(HeaderKeys.XAmzId2Header)) { postResponse.HostId = response.GetHeaderValue(HeaderKeys.XAmzId2Header); } if (response.IsHeaderPresent(HeaderKeys.XAmzVersionIdHeader)) { postResponse.VersionId = response.GetHeaderValue(HeaderKeys.XAmzVersionIdHeader); } PostObjectRequest request = executionContext.RequestContext.OriginalRequest as PostObjectRequest; asyncResult.Request = request; asyncResult.Response = postResponse; } asyncResult.Exception = executionContext.ResponseContext.AsyncResult.Exception; asyncResult.Action = executionContext.RequestContext.Action; asyncResult.InvokeCallback(); }
/// <summary> /// Handles and processes any exception thrown from underlying handlers. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { var responseContext = executionContext.ResponseContext; var exception = responseContext.AsyncResult.Exception; if (exception != null) { try { DisposeReponse(executionContext.ResponseContext); bool rethrow = ProcessException( ExecutionContext.CreateFromAsyncContext(executionContext), exception); // Suppress exception if (!rethrow) { responseContext.AsyncResult.Exception = null; } } catch (Exception processedException) { // Catch any new exception thrown by ProcessException() responseContext.AsyncResult.Exception = processedException; } } // Call outer handler base.InvokeAsyncCallback(executionContext); }
public void AsyncCallback(IAsyncExecutionContext executionContext) { try { this.InvokeAsyncCallback(executionContext); } catch (Exception exception) { // Log exception this.Logger.Error(exception, "An exception of type {0} was thrown from InvokeAsyncCallback().", exception.GetType().Name); executionContext.RequestContext.Metrics.AddProperty(Metric.Exception, exception); // An unhandled exception occured in the callback implementation. // Capture the exception and end the callback processing by signalling the // wait handle. executionContext.RequestContext.Metrics.StopEvent(Metric.ClientExecuteTime); LogMetrics(ExecutionContext.CreateFromAsyncContext(executionContext)); var asyncResult = executionContext.ResponseContext.AsyncResult; asyncResult.Exception = exception; asyncResult.SignalWaitHandle(); if (asyncResult.AsyncCallback != null) { asyncResult.AsyncCallback(asyncResult); } } }
void ErrorCallback(Exception exception, IAsyncExecutionContext executionContext) { // Handle the exception by logging it and setting the exception on the context, // so that the exception is visible to the caller this.Logger.Error(exception, "An exception of type {0} was thrown from InvokeAsyncCallback().", exception.GetType().Name); executionContext.RequestContext.Metrics.AddProperty(Metric.Exception, exception); // An unhandled exception occured in the callback implementation. // Capture the exception and end the callback processing by signalling the // wait handle. executionContext.RequestContext.Metrics.StopEvent(Metric.ClientExecuteTime); LogMetrics(ExecutionContext.CreateFromAsyncContext(executionContext)); executionContext.ResponseContext.AsyncResult = new RuntimeAsyncResult(executionContext.RequestContext.Callback, executionContext.RequestContext.State); executionContext.ResponseContext.AsyncResult.Exception = exception; executionContext.ResponseContext.AsyncResult.AsyncOptions = executionContext.RequestContext.AsyncOptions; executionContext.ResponseContext.AsyncResult.Action = executionContext.RequestContext.Action; executionContext.ResponseContext.AsyncResult.Request = executionContext.RequestContext.OriginalRequest; executionContext.ResponseContext.AsyncResult.InvokeCallback(); }
/// <summary> /// Invokes the inner handler and performs a retry, if required as per the /// retry policy. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { var requestContext = executionContext.RequestContext; var responseContext = executionContext.ResponseContext; var exception = responseContext.AsyncResult.Exception; if (exception != null) { var syncExecutionContext = ExecutionContext.CreateFromAsyncContext(executionContext); var shouldRetry = this.RetryPolicy.Retry(syncExecutionContext, exception); if (shouldRetry) { requestContext.Retries++; PrepareForRetry(requestContext); try { this.RetryPolicy.WaitBeforeRetry(syncExecutionContext); } finally { } // Retry by calling InvokeAsync this.InvokeAsync(executionContext); return; } } // Call outer handler base.InvokeAsyncCallback(executionContext); }
public virtual IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { if (this.InnerHandler != null) { return(InnerHandler.InvokeAsync(executionContext)); } throw new InvalidOperationException("Cannot invoke InnerHandler. InnerHandler is not set."); }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { if (executionContext.ResponseContext.AsyncResult.Exception == null) { PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext)); } base.InvokeAsyncCallback(executionContext); }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { if (executionContext.get_ResponseContext().get_AsyncResult().get_Exception() == null) { PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext)); } this.InvokeAsyncCallback(executionContext); }
void ErrorCallback(Exception exception, IAsyncExecutionContext executionContext) { // Handle the exception by logging it and setting the exception on the context, // so that the exception is visible to the caller executionContext.ResponseContext.AsyncResult.Exception = exception; this.Logger.Error(exception, "An exception was thrown from the runtime pipeline invoked by the thread pool."); }
/// <summary> /// Unmarshalls the response returned by the HttpHandler. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { // Unmarshall the response if an exception hasn't occured if (executionContext.ResponseContext.AsyncResult.Exception == null) { Unmarshall(ExecutionContext.CreateFromAsyncContext(executionContext)); } base.InvokeAsyncCallback(executionContext); }
public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { if (UnityInitializer.IsMainThread()) { _throttler.Enqueue(executionContext, InvokeAsyncHelper, ErrorCallback); return(null); } return(base.InvokeAsync(executionContext)); }
/// <summary> /// Issues an HTTP request for the current request context. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <returns>IAsyncResult which represent an async operation.</returns> public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { IHttpRequest <TRequestContent> httpRequest = null; try { SetMetrics(executionContext.RequestContext); httpRequest = CreateWebRequest(executionContext.RequestContext); executionContext.RuntimeState = httpRequest; IRequest wrappedRequest = executionContext.RequestContext.Request; if (executionContext.RequestContext.Retries == 0) { // First call, initialize an async result. executionContext.ResponseContext.AsyncResult = new RuntimeAsyncResult(executionContext.RequestContext.Callback, executionContext.RequestContext.State); } // Set request headers httpRequest.SetRequestHeaders(executionContext.RequestContext.Request.Headers); executionContext.RequestContext.Metrics.StartEvent(Metric.HttpRequestTime); if (wrappedRequest.HasRequestBody()) { // Send request body if present. httpRequest.BeginGetRequestContent(new AsyncCallback(GetRequestStreamCallback), executionContext); } else { // Get response if there is no response body to send. httpRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), executionContext); } return(executionContext.ResponseContext.AsyncResult); } catch (Exception exception) { if (executionContext.ResponseContext.AsyncResult != null) { // An exception will be thrown back to the calling code. // Dispose AsyncResult as it will not be used further. executionContext.ResponseContext.AsyncResult.Dispose(); executionContext.ResponseContext.AsyncResult = null; } if (httpRequest != null) { httpRequest.Abort(); httpRequest.Dispose(); } // Log this exception as it will not be caught by ErrorHandler. this.Logger.Error(exception, "An exception occured while initiating an asynchronous HTTP request."); throw; } }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { Exception exception = executionContext.get_ResponseContext().get_AsyncResult().get_Exception(); if (executionContext.get_ResponseContext().get_AsyncResult().get_Exception() != null) { HandleException(ExecutionContext.CreateFromAsyncContext(executionContext), exception); } this.InvokeAsyncCallback(executionContext); }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { if (executionContext.ResponseContext.AsyncResult.Exception != null) { CaptureCSMCallEventExceptionData(executionContext.RequestContext, executionContext.ResponseContext.AsyncResult.Exception); } CSMCallEventMetricsCapture(ExecutionContext.CreateFromAsyncContext(executionContext)); CSMUtilities.BeginSerializetoJsonAndPostOverUDP(executionContext.RequestContext.CSMCallEvent); base.InvokeAsyncCallback(executionContext); }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { Exception exception = executionContext.ResponseContext.AsyncResult.Exception; if (executionContext.ResponseContext.AsyncResult.Exception != null) { HandleException(ExecutionContext.CreateFromAsyncContext(executionContext), exception); } base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Initializes a new instance of the <see cref="AsyncRelayCommand"/> class. /// </summary> /// <param name="context">Synchronization context to run into.</param> /// <param name="onExecute">Asynchron handler for execute command.</param> /// <param name="onCanExecute">Handler to validate whether execution is possible.</param> public AsyncRelayCommand( IAsyncExecutionContext context, AsyncCommandExecutionHandler onExecute, Func <bool>?onCanExecute = null) { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.executeHandler = onExecute ?? throw new ArgumentNullException(nameof(onExecute)); this.canExecuteHandler = onCanExecute; this.context.PropertyChanged += this.NotifyCommandIfIsBusyChanged; }
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { if (executionContext.ResponseContext.AsyncResult.Exception == null && HandleRedirect(ExecutionContext.CreateFromAsyncContext(executionContext))) { base.InvokeAsync(executionContext); } else { base.InvokeAsyncCallback(executionContext); } }
/// <summary> /// Extracts the X-Amz-Id-2 header from WebExceptions and adds it to the AmazonS3ControlException and metrics /// </summary> /// <param name="executionContext"></param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { var exception = executionContext.ResponseContext.AsyncResult.Exception; if (executionContext.ResponseContext.AsyncResult.Exception != null) { ExtractAmazonIdHeader(ExecutionContext.CreateFromAsyncContext(executionContext), exception); } // Call outer handler base.InvokeAsyncCallback(executionContext); }
protected virtual void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { if (OuterHandler != null) { OuterHandler.AsyncCallback(executionContext); } else { executionContext.ResponseContext.AsyncResult.Response = executionContext.ResponseContext.Response; executionContext.ResponseContext.AsyncResult.InvokeCallback(); } }
public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { if (UnityInitializer.IsMainThread()) { _throttler.Enqueue(executionContext, InvokeAsyncHelper, ErrorCallback); return null; } else { return base.InvokeAsync(executionContext); } }
/// <summary> /// Processes HTTP redirects and reissues the call to the /// redirected location. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { // Call InvokeAsync to redirect to new location. if (HandleRedirect(ExecutionContext.CreateFromAsyncContext(executionContext))) { base.InvokeAsync(executionContext); return; } // Not a redirect, call outer callbacks to continue processing response. base.InvokeAsyncCallback(executionContext); }
private void ErrorCallback(Exception exception, IAsyncExecutionContext executionContext) { Logger.Error(exception, "An exception of type {0} was thrown from InvokeAsyncCallback().", exception.GetType().Name); executionContext.RequestContext.Metrics.AddProperty(Metric.Exception, exception); executionContext.RequestContext.Metrics.StopEvent(Metric.ClientExecuteTime); LogMetrics(ExecutionContext.CreateFromAsyncContext(executionContext)); executionContext.ResponseContext.AsyncResult = new RuntimeAsyncResult(executionContext.RequestContext.Callback, executionContext.RequestContext.State); executionContext.ResponseContext.AsyncResult.Exception = exception; executionContext.ResponseContext.AsyncResult.AsyncOptions = executionContext.RequestContext.AsyncOptions; executionContext.ResponseContext.AsyncResult.Action = executionContext.RequestContext.Action; executionContext.ResponseContext.AsyncResult.Request = executionContext.RequestContext.OriginalRequest; executionContext.ResponseContext.AsyncResult.InvokeCallback(); }
/// <summary> /// Calls the PostInvoke methods after calling the next handler /// in the pipeline. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext)); base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Captures the overall execution time. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <returns>IAsyncResult which represent an async operation.</returns> public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { executionContext.RequestContext.Metrics.AddProperty(Metric.AsyncCall, true); executionContext.RequestContext.Metrics.StartEvent(Metric.ClientExecuteTime); return base.InvokeAsync(executionContext); }
/// <summary> /// Captures the overall execution time and logs final metrics. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { executionContext.RequestContext.Metrics.StopEvent(Metric.ClientExecuteTime); this.LogMetrics(ExecutionContext.CreateFromAsyncContext(executionContext)); base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Invokes the inner handler and performs a retry, if required as per the /// retry policy. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { var requestContext = executionContext.RequestContext; var responseContext = executionContext.ResponseContext; var exception = responseContext.AsyncResult.Exception; if (exception != null) { var syncExecutionContext = ExecutionContext.CreateFromAsyncContext(executionContext); var shouldRetry = this.RetryPolicy.Retry(syncExecutionContext, exception); if (shouldRetry) { requestContext.Retries++; requestContext.Metrics.SetCounter(Metric.AttemptCount, requestContext.Retries); LogForRetry(requestContext, exception); PrepareForRetry(requestContext); try { requestContext.Metrics.StartEvent(Metric.RetryPauseTime); this.RetryPolicy.WaitBeforeRetry(syncExecutionContext); } finally { requestContext.Metrics.StopEvent(Metric.RetryPauseTime); } // Retry by calling InvokeAsync this.InvokeAsync(executionContext); return; } else { LogForError(requestContext, exception); } } // Call outer handler base.InvokeAsyncCallback(executionContext); }
/// <summary> /// Calls pre invoke logic before calling the next handler /// in the pipeline. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <returns>IAsyncResult which represent an async operation.</returns> public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { PreInvoke(ExecutionContext.CreateFromAsyncContext(executionContext)); return base.InvokeAsync(executionContext); }
public static IExecutionContext CreateFromAsyncContext(IAsyncExecutionContext asyncContext) { return new ExecutionContext(asyncContext.RequestContext, asyncContext.ResponseContext); }
/// <summary> /// This callback method contains the processing logic that should be executed /// after the underlying asynchronous operation completes. /// This method is called as part of a callback chain which starts /// from the InvokeAsyncCallback method of the bottommost handler and then invokes /// each callback method of the handler above it. /// This method calls OuterHandler.AsyncCallback to continue processing of the /// request by the pipeline, unless it's the topmost handler. /// </summary> /// <param name="executionContext">The execution context, it contains the /// request and response context.</param> protected virtual void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { if (this.OuterHandler!=null) { this.OuterHandler.AsyncCallback(executionContext); } else { // No more outer handlers to process, signal completion executionContext.ResponseContext.AsyncResult.Response = executionContext.ResponseContext.Response; var asyncResult = executionContext.ResponseContext.AsyncResult; asyncResult.SignalWaitHandle(); if (asyncResult.AsyncCallback != null) { asyncResult.AsyncCallback(asyncResult); } } }
void InvokeAsyncHelper(IAsyncExecutionContext executionContext) { base.InvokeAsync(executionContext); }
/// <summary> /// Contains the processing logic for an asynchronous request invocation. /// This method should calls InnerHandler.InvokeSync to continue processing of the /// request by the pipeline. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <returns>IAsyncResult which represent an async operation.</returns> public virtual IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext) { if (this.InnerHandler != null) { return InnerHandler.InvokeAsync(executionContext); } throw new InvalidOperationException("Cannot invoke InnerHandler. InnerHandler is not set."); }