Represents a Fluent Http Response.
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentHttpAsyncResult"/> class.
 /// </summary>
 /// <param name="request">The <see cref="FluentHttpRequest"/>.</param>
 /// <param name="response">The <see cref="FluentHttpResponse"/>.</param>
 /// <param name="asyncState">The async state.</param>
 /// <param name="asyncWaitHandle">The async wait handle.</param>
 /// <param name="completedSynchronously">Indicates whether the async operation completed synchronously.</param>
 /// <param name="isCompleted">Indicates whether the async operation completed.</param>
 /// <param name="isCancelled">Indicates whether the async operation was cancelled.</param>
 /// <param name="exception">The exception during the http web request.</param>
 /// <param name="innerException">The inner exception during the http web request.</param>
 public FluentHttpAsyncResult(FluentHttpRequest request, FluentHttpResponse response, object asyncState, WaitHandle asyncWaitHandle, bool completedSynchronously, bool isCompleted, bool isCancelled, Exception exception, Exception innerException)
 {
     _request = request;
     _response = response;
     _asyncState = asyncState;
     _asyncWaitHandle = asyncWaitHandle;
     _completedSynchronously = completedSynchronously;
     _isCompleted = isCompleted;
     _isCancelled = isCancelled;
     _exception = exception;
     _innerException = innerException;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentHttpAsyncResult"/> class.
 /// </summary>
 /// <param name="request">The <see cref="FluentHttpRequest"/>.</param>
 /// <param name="response">The <see cref="FluentHttpResponse"/>.</param>
 /// <param name="asyncState">The async state.</param>
 /// <param name="asyncWaitHandle">The async wait handle.</param>
 /// <param name="completedSynchronously">Indicates whether the async operation completed synchronously.</param>
 /// <param name="isCompleted">Indicates whether the async operation completed.</param>
 /// <param name="isCancelled">Indicates whether the async operation was cancelled.</param>
 /// <param name="exception">The exception during the http web request.</param>
 /// <param name="innerException">The inner exception during the http web request.</param>
 public FluentHttpAsyncResult(FluentHttpRequest request, FluentHttpResponse response, object asyncState, WaitHandle asyncWaitHandle, bool completedSynchronously, bool isCompleted, bool isCancelled, Exception exception, Exception innerException)
 {
     _request                = request;
     _response               = response;
     _asyncState             = asyncState;
     _asyncWaitHandle        = asyncWaitHandle;
     _completedSynchronously = completedSynchronously;
     _isCompleted            = isCompleted;
     _isCancelled            = isCancelled;
     _exception              = exception;
     _innerException         = innerException;
 }
Beispiel #3
0
        public FluentHttpAsyncResult Execute()
        {
            AuthenticateIfRequried();

            var requestUrl = BuildRequestUrl();

            var httpWebHelper = new HttpWebHelper();

            // todo add cookies

            var headers        = GetHeaders().GetHeaderPairs();
            var httpWebRequest = httpWebHelper.CreateHttpWebRequest(requestUrl, GetMethod(), headers, null);

            PrepareHttpWebRequest(httpWebRequest);

            FluentHttpResponse fluentHttpResponse = null;

            httpWebHelper.ResponseReceived +=
                (o, e) =>
            {
                fluentHttpResponse = new FluentHttpResponse(this, e.Response);
                var args = new ResponseHeadersReceivedEventArgs(fluentHttpResponse, e.Exception, null);
                OnResponseHeadersRecived(args);
                e.ResponseSaveStream = fluentHttpResponse.SaveStream;
            };

            var httpWebHelperResult = httpWebHelper.Execute(httpWebRequest, GetBody().Stream);

            return(new FluentHttpAsyncResult(this, fluentHttpResponse, null, null, true, true, false, httpWebHelperResult.Exception, httpWebHelperResult.InnerException));

            /*
             * System.Threading.ManualResetEvent wait = new System.Threading.ManualResetEvent(false);
             * FluentHttpAsyncResult asyncResult = null;
             *
             * ExecuteAsync(ar => { asyncResult = ar; wait.Set(); });
             * wait.WaitOne();
             *
             * if (asyncResult.Exception == null)
             *  return asyncResult;
             *
             * throw asyncResult.Exception;
             */
        }
Beispiel #4
0
        public void ExecuteAsync(FluentHttpAsyncCallback callback, object state)
        {
            AuthenticateIfRequried();

            var requestUrl = BuildRequestUrl();

            var httpWebHelper = new HttpWebHelper();

            // todo add cookies

            var headers        = GetHeaders().GetHeaderPairs();
            var httpWebRequest = httpWebHelper.CreateHttpWebRequest(requestUrl, GetMethod(), headers, null);

            PrepareHttpWebRequest(httpWebRequest);

            FluentHttpResponse fluentHttpResponse = null;

            httpWebHelper.ResponseReceived +=
                (o, e) =>
            {
                fluentHttpResponse = new FluentHttpResponse(this, e.Response);
                var args = new ResponseHeadersReceivedEventArgs(fluentHttpResponse, e.Exception, state);
                OnResponseHeadersRecived(args);
                e.ResponseSaveStream = fluentHttpResponse.SaveStream;
            };

            httpWebHelper.ExecuteAsync(httpWebRequest, GetBody().Stream,
                                       ar =>
            {
                if (callback != null)
                {
                    var asyncResult           = (HttpWebHelperResult)ar;
                    var fluentHttpAsyncResult = new FluentHttpAsyncResult(this, fluentHttpResponse, state, null, ar.CompletedSynchronously, true, false, asyncResult.Exception, asyncResult.InnerException);
                    callback(fluentHttpAsyncResult);
                }
            }, null);
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponseHeadersReceivedEventArgs"/> class.
 /// </summary>
 /// <param name="response">
 /// The response.
 /// </param>
 /// <param name="asyncState">The async state</param>
 public ResponseHeadersReceivedEventArgs(FluentHttpResponse response, Exception exception, object asyncState)
 {
     _response   = response;
     _exception  = exception;
     _asyncState = asyncState;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponseHeadersReceivedEventArgs"/> class.
 /// </summary>
 /// <param name="response">
 /// The response.
 /// </param>
 /// <param name="asyncState">The async state</param>
 public ResponseHeadersReceivedEventArgs(FluentHttpResponse response, Exception exception, object asyncState)
 {
     _response = response;
     _exception = exception;
     _asyncState = asyncState;
 }