using Amazon.CloudSearchDomain.Model; using Amazon.Runtime; using Amazon.Runtime.Internal; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Amazon.CloudSearchDomain.Internal { /// /// Custom pipeline handler to make sure streams. /// public class ValidationResponseHandler : PipelineHandler { #if BCL /// /// Calls the post invoke logic after calling the next handler /// in the pipeline. /// /// The execution context which contains both the /// requests and response context. public override void InvokeSync(IExecutionContext executionContext) { base.InvokeSync(executionContext); PostInvoke(executionContext); } #endif #if BCL45 /// /// Calls the and post invoke logic after calling the next handler /// in the pipeline. /// /// The response type for the current request. /// The execution context, it contains the /// request and response context. /// A task that represents the asynchronous operation. public override async System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext) { var response = await base.InvokeAsync(executionContext).ConfigureAwait(false); PostInvoke(executionContext); return response; } #elif AWS_APM_API /// /// Calls the PostInvoke methods after calling the next handler /// in the pipeline. /// /// The execution context, it contains the /// request and response context. protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext) { // Process the response if an exception hasn't occured if (executionContext.ResponseContext.AsyncResult.Exception == null) { PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext)); } base.InvokeAsyncCallback(executionContext); } #endif #if BCL /// /// Custom pipeline handler to make sure streams. /// /// protected virtual void PostInvoke(IExecutionContext executionContext) { var uploadDocumentsRequest = executionContext.RequestContext.OriginalRequest as UploadDocumentsRequest; if (uploadDocumentsRequest != null) { // If Documents property is set as the underlying stream for FilePath, dispose it. if (uploadDocumentsRequest.Documents != null && !string.IsNullOrEmpty(uploadDocumentsRequest.FilePath)) { uploadDocumentsRequest.Documents.Dispose(); uploadDocumentsRequest.Documents = null; } } } #endif } }