Example #1
0
        protected virtual void ExecuteRequestWithBody(HttpWebRequest request)
        {
            request.BeginGetRequestStream(new AsyncCallback((IAsyncResult callbackResult) =>
            {
                HttpWebRequest tmprequest = (HttpWebRequest)callbackResult.AsyncState;

                ProgressCallbackHelper copy = body.GetBody().CopyToProgress(tmprequest.EndGetRequestStream(callbackResult), null);
                copy.ProgressChanged       += (bytesSent, totalBytes) => { body.OnProgressChange(bytesSent, totalBytes); };
                copy.Completed += (totalBytes) => { body.OnCompleted(totalBytes); };
                copy.Go();

                // Start the asynchronous operation to get the response
                tmprequest.BeginGetResponse(ProcessCallback(action.Success, action.Fail), tmprequest);
            }), request);
        }
Example #2
0
        public RequestBuilder DownloadTo(String filePath, Action <long, long?> OnProgressChanged)
        {
            this.success = (headers, result) =>
            {
                long?length = null;
                if (headers.AllKeys.Contains("Content-Length"))
                {
                    length = long.Parse(headers["Content-Length"]);
                }
                FileStream             fs        = new FileStream(filePath, FileMode.OpenOrCreate);
                ProgressCallbackHelper operation = result.CopyToProgress(fs, length);

                operation.ProgressChanged += (copied, total) => { OnProgressChanged(copied, total); };
                operation.Completed       += (totalbytes) => { fs.Close(); };
                operation.Go();
            };
            return(this);
        }