Beispiel #1
0
        public override void GetAsync(HttpFormGetRequest getRequest, Action <HttpFormResponse> onComplete, Action <Exception> onError)
        {
            Check.Argument.IsNotNull(getRequest, "getRequest");

            string cacheKey = BuildCacheKey(getRequest);

            HttpFormResponse response;

            Cache.TryGet(cacheKey, out response);

            if (response == null)
            {
                base.GetAsync(
                    getRequest,
                    r =>
                {
                    if ((r != null) && !Cache.Contains(cacheKey))
                    {
                        Cache.Set(cacheKey, r, SystemTime.Now().AddMinutes(_cacheDurationInMinutes));
                    }

                    onComplete(r);
                },
                    onError
                    );
            }
            else
            {
                onComplete(response);
            }
        }
Beispiel #2
0
        public HttpFormResponse Get(HttpFormGetRequest getRequest)
        {
            Check.Argument.IsNotNull(getRequest, "getRequest");
            Check.Argument.IsNotEmpty(getRequest.Url, "getRequest.Url");

            WebRequest request = CreateRequest(getRequest.Url, getRequest.UserName, getRequest.Password, getRequest.ContentType, getRequest.Headers, getRequest.Cookies, false);

            return(ReadResponse(request));
        }
Beispiel #3
0
        internal HttpFormResponse Post(HttpFormGetRequest postRequest, string rawData)
        {
            Check.Argument.IsNotNull(postRequest, "postRequest");
            Check.Argument.IsNotEmpty(postRequest.Url, "postRequest.Url");

            WebRequest request = CreateRequest(postRequest.Url, postRequest.UserName, postRequest.Password, postRequest.ContentType, postRequest.Headers, postRequest.Cookies, true);

            PreapreRequestToPost(request, rawData);

            return(ReadResponse(request));
        }
Beispiel #4
0
        public void GetAsync(HttpFormGetRequest getRequest, Action <HttpFormResponse> onComplete, Action <Exception> onError)
        {
            Check.Argument.IsNotNull(getRequest, "getRequest");
            Check.Argument.IsNotEmpty(getRequest.Url, "getRequest.Url");

            WebRequest request = CreateRequest(getRequest.Url, getRequest.UserName, getRequest.Password, getRequest.ContentType, getRequest.Headers, getRequest.Cookies, false);

            try
            {
                request.BeginGetResponse(ResponseCallback, new StateContainer {
                    Request = request, OnComplete = onComplete, OnError = onError
                });
            }
            catch (Exception e)
            {
                if (onError != null)
                {
                    onError(e);
                }
            }
        }
Beispiel #5
0
        private static string BuildCacheKey(HttpFormGetRequest getRequest)
        {
            Check.Argument.IsNotInvalidWebUrl(getRequest.Url, "getRequest.Url");

            StringBuilder cacheKeyValue = new StringBuilder(getRequest.Url);

            if (!string.IsNullOrEmpty(getRequest.UserName))
            {
                cacheKeyValue.Append("|" + getRequest.UserName);
            }

            if (!string.IsNullOrEmpty(getRequest.Password))
            {
                cacheKeyValue.Append("|" + getRequest.Password);
            }

            if (!string.IsNullOrEmpty(getRequest.ContentType))
            {
                cacheKeyValue.Append("|" + getRequest.ContentType);
            }

            if (getRequest.Headers.Count > 0)
            {
                foreach (string key in getRequest.Headers)
                {
                    cacheKeyValue.Append("|{0}:{1}".FormatWith(key, getRequest.Headers[key]));
                }
            }

            if (getRequest.Cookies.Count > 0)
            {
                foreach (string key in getRequest.Cookies)
                {
                    cacheKeyValue.Append("|{0}:{1}".FormatWith(key, getRequest.Cookies[key]));
                }
            }

            return("rawHtml:{0}".FormatWith(cacheKeyValue.ToString().Hash()));
        }
Beispiel #6
0
        public override HttpFormResponse Get(HttpFormGetRequest getRequest)
        {
            Check.Argument.IsNotNull(getRequest, "getRequest");

            string cacheKey = BuildCacheKey(getRequest);

            HttpFormResponse response;

            Cache.TryGet(cacheKey, out response);

            if (response == null)
            {
                response = base.Get(getRequest);

                if ((response != null) && !Cache.Contains(cacheKey))
                {
                    Cache.Set(cacheKey, response, SystemTime.Now().AddMinutes(_cacheDurationInMinutes));
                }
            }

            return(response);
        }
Beispiel #7
0
        internal void PostAsync(HttpFormGetRequest postRequest, string rawData, Action <HttpFormResponse> onComplete, Action <Exception> onError)
        {
            Check.Argument.IsNotNull(postRequest, "postRequest");
            Check.Argument.IsNotEmpty(postRequest.Url, "postRequest.Url");

            WebRequest request = CreateRequest(postRequest.Url, postRequest.UserName, postRequest.Password, postRequest.ContentType, postRequest.Headers, postRequest.Cookies, true);

            byte[] content = Encoding.UTF8.GetBytes(rawData);
            request.ContentLength = content.Length;

            try
            {
                request.BeginGetRequestStream(RequestCallback, new StateContainer {
                    Request = request, RequestContent = content, OnComplete = onComplete, OnError = onError
                });
            }
            catch (Exception e)
            {
                if (onError != null)
                {
                    onError(e);
                }
            }
        }
Beispiel #8
0
 public override void GetAsync(HttpFormGetRequest getRequest)
 {
     GetAsync(getRequest, delegate { }, delegate { });
 }
Beispiel #9
0
 public void GetAsync(HttpFormGetRequest getRequest)
 {
     GetAsync(getRequest, null, null);
 }
Beispiel #10
0
 public virtual void GetAsync(HttpFormGetRequest getRequest, Action <HttpFormResponse> onComplete, Action <Exception> onError)
 {
     _innerHttpForm.GetAsync(getRequest, onComplete, onError);
 }
Beispiel #11
0
 public virtual void GetAsync(HttpFormGetRequest getRequest)
 {
     _innerHttpForm.GetAsync(getRequest);
 }
Beispiel #12
0
 public virtual HttpFormResponse Get(HttpFormGetRequest getRequest)
 {
     return(_innerHttpForm.Get(getRequest));
 }