public static AsyncHttpRequest GetAsync(this HttpWebRequest webRequest, Action <AsyncHttpRequest> callBack)
        {
            var asyncRequest = new AsyncHttpRequest(webRequest, callBack);

            asyncRequest.GetAsync();
            return(asyncRequest);
        }
        private void ProcessWebResponse(AsyncHttpRequest request)
        {
            RunningRequestsCount--;

            switch (QueueState)
            {
            case HttpRequestQueueState.Connecting:
                ProcessResponseConnecting(request);
                break;

            case HttpRequestQueueState.Running:
                ProcessResponseRunning(request);
                break;

            case HttpRequestQueueState.Reconnecting:
                ProcessResponseReConnecting(request);
                break;

            case HttpRequestQueueState.Offline:
                ProcessResponseOffline(request);
                break;
            }

            ProcessQueuedItems();
        }
 private void ExecuteHttpRequest(QueuedRequest request)
 {
     try
     {
         RunningRequestsCount++;
         var asyncHttpRequest = new AsyncHttpRequest(request.Request, WebRequestCallback, request);
         if (request.PostData == null)
         {
             asyncHttpRequest.GetAsync();
         }
         else
         {
             asyncHttpRequest.PostAsync(request.PostData);
         }
     }
     catch (Exception ex)
     {
         log.Error(ex);
     }
 }
        private void ProcessResponseRunning(AsyncHttpRequest request)
        {
            var queuedRequest = (QueuedRequest)request.State;

            switch (request.WebStatus)
            {
            case WebExceptionStatus.Success:
                DecrementTimedOutCount();
                queuedRequest.Callback(HttpRequestQueueResultCode.Success, request, queuedRequest.State);
                break;

            case WebExceptionStatus.Timeout:
                IncrementTimedOutCount();
                queuedRequest.Callback(HttpRequestQueueResultCode.RequestTimeout, request, queuedRequest.State);
                break;

            default:
                SetOffline();
                queuedRequest.Callback(HttpRequestQueueResultCode.Error, request, queuedRequest.State);
                break;
            }
        }
        private void ProcessResponseOffline(AsyncHttpRequest request)
        {
            var queuedRequest = (QueuedRequest)request.State;

            queuedRequest.Callback(HttpRequestQueueResultCode.Offline, null, queuedRequest.State);
        }
 private void WebRequestCallback(AsyncHttpRequest request)
 {
     fiber.Enqueue(() => ProcessWebResponse(request));
 }