Esempio n. 1
0
        protected virtual WebQueryAsyncResult ExecuteGetOrDeleteAsync(GetDeleteHeadOptions method, string url, object userState)
        {
            WebResponse = null;

            var request = BuildGetDeleteHeadOptionsWebRequest(method, url);
            var state = new Triplet<WebRequest, object, object>
                            {
                                First = request,
                                Second = null,
                                Third = userState
                            };

            var args = new WebQueryRequestEventArgs(url);
            OnQueryRequest(args);

            var inner = request.BeginGetResponse(GetAsyncResponseCallback, state);
            RegisterAbortTimer(request, inner); 
            var result = new WebQueryAsyncResult { InnerResult = inner };
            return result;
        }
Esempio n. 2
0
        private WebQueryAsyncResult ExecuteGetOrDeleteAsync(ICache cache, 
                                                            string key, 
                                                            string url, 
                                                            WebRequest request,
                                                            object userState)
        {
            var fetch = cache.Get<Stream>(key);
            if (fetch != null)
            {
                var args = new WebQueryResponseEventArgs(fetch);
                OnQueryResponse(args);

                var result = new WebQueryAsyncResult
                {
                    CompletedSynchronously = true
                };
                return result;
            }
            else
            {
                var state = new Triplet<WebRequest, Pair<ICache, string>, object>
                                {
                                    First = request,
                                    Second = new Pair<ICache, string>
                                                 {
                                        First = cache,
                                        Second = key
                                    },
                                    Third = userState
                                };

                var args = new WebQueryRequestEventArgs(url);
                OnQueryRequest(args);

                var inner = request.BeginGetResponse(GetAsyncResponseCallback, state);
                RegisterAbortTimer(request, inner); 
                var result = new WebQueryAsyncResult { InnerResult = inner };
                return result;
            }
        }
Esempio n. 3
0
        public virtual WebQueryAsyncResult ExecuteStreamPostAsync(string url, 
                                                                  TimeSpan duration, 
                                                                  int resultCount)
        {
            WebResponse = null;

            byte[] content;
            var request = BuildPostOrPutWebRequest(PostOrPut.Post, url, out content);
            var state = OnPostStreamQueryRequest(url, request, content, duration, resultCount);

#if SILVERLIGHT
            var httpRequest = request as HttpWebRequest;
            if (httpRequest != null)
            {
                httpRequest.AllowReadStreamBuffering = false;
            }
#endif

            var inner = request.BeginGetRequestStream(PostAsyncStreamRequestCallback, state);
            var result = new WebQueryAsyncResult { InnerResult = inner };
            return result;
        }
Esempio n. 4
0
        public virtual WebQueryAsyncResult ExecuteStreamGetAsync(string url, 
                                                                 TimeSpan duration, 
                                                                 int resultCount)
        {
            WebResponse = null;

            var request = BuildGetDeleteHeadOptionsWebRequest(GetDeleteHeadOptions.Get, url);
            var state = OnGetStreamQueryRequest(url, request, duration, resultCount);

#if SILVERLIGHT
            var httpRequest = request as HttpWebRequest;
            if (httpRequest != null)
            {
                httpRequest.AllowReadStreamBuffering = false;
            }
#endif

            var inner = request.BeginGetResponse(AsyncStreamCallback, state);
            var result = new WebQueryAsyncResult { InnerResult = inner };
            return result;
        }
Esempio n. 5
0
        protected virtual WebQueryAsyncResult ExecutePostOrPutAsync(PostOrPut method, 
                                                                    string url, 
                                                                    string prefixKey,
                                                                    ICache cache, 
                                                                    TimeSpan slidingExpiration,
                                                                    object userState)
        {
            WebResponse = null;

            byte[] content;
            var request = BuildPostOrPutWebRequest(method, url, out content);

            var state = new Triplet<WebRequest, Pair<byte[], Triplet<ICache, TimeSpan, string>>, object>
                            {
                                First = request,
                                Second = new Pair<byte[], Triplet<ICache, TimeSpan, string>>
                                             {
                                                 First = content,
                                                 Second = new Triplet<ICache, TimeSpan, string>
                                                              {
                                                                  First = cache,
                                                                  Second = slidingExpiration,
                                                                  Third = prefixKey
                                                              }
                                             },
                                Third = userState
                            };

            var args = new WebQueryRequestEventArgs(url);
            OnQueryRequest(args);

            var inner = request.BeginGetRequestStream(PostAsyncRequestCallback, state);
            var result = new WebQueryAsyncResult { InnerResult = inner };
            RegisterAbortTimer(request, result);
            return result;
        }
Esempio n. 6
0
        protected virtual WebQueryAsyncResult ExecutePostOrPutAsync(PostOrPut method,
                                                                    string url,
                                                                    IEnumerable<HttpPostParameter> parameters,
                                                                    object userState)
        {
            WebResponse = null;

            string boundary;
            var request = BuildMultiPartFormRequest(method, url, parameters, out boundary);

            var state = new Triplet<WebRequest, Pair<string, IEnumerable<HttpPostParameter>>, object>
                            {
                                First = request,
                                Second = new Pair<string, IEnumerable<HttpPostParameter>>
                                             {
                                                 First = boundary,
                                                 Second = parameters
                                             },
                                Third = userState
                            };
            var args = new WebQueryRequestEventArgs(url);

            OnQueryRequest(args);
            
            var inner = request.BeginGetRequestStream(PostAsyncRequestCallbackMultiPart, state);
            var result = new WebQueryAsyncResult { InnerResult = inner };
            RegisterAbortTimer(request, result);
            return result;
        }
Esempio n. 7
0
        protected virtual WebQueryAsyncResult ExecutePostOrPutAsync(PostOrPut method, string url, object userState)
        {
            WebResponse = null;

            byte[] content;
            var request = BuildPostOrPutWebRequest(method, url, out content);

            var state = new Triplet<WebRequest, byte[], object>
                            {
                                First = request,
                                Second = content,
                                Third = userState
                            };

            var args = new WebQueryRequestEventArgs(url);
            OnQueryRequest(args);

            var inner = request.BeginGetRequestStream(PostAsyncRequestCallback, state);
            var result = new WebQueryAsyncResult { InnerResult = inner };
            RegisterAbortTimer(request, result);
            return result;
        }