Beispiel #1
0
        protected override void AsyncEndGetResponse(IAsyncResult asyncResult)
        {
            BaseAsyncResult.AsyncStateBag asyncState = asyncResult.AsyncState as BaseAsyncResult.AsyncStateBag;
            BaseAsyncResult.PerRequest    request    = (asyncState == null) ? null : asyncState.PerRequest;
            DataServiceContext            context    = (asyncState == null) ? null : asyncState.Context;

            try
            {
                this.CompleteCheck(request, InternalError.InvalidEndGetResponseCompleted);
                request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                BaseAsyncResult.EqualRefCheck(base.perRequest, request, InternalError.InvalidEndGetResponse);
                ODataRequestMessageWrapper wrapper  = Util.NullCheck <ODataRequestMessageWrapper>(request.Request, InternalError.InvalidEndGetResponseRequest);
                HttpWebResponse            response = null;
                response = WebUtil.EndGetResponse(wrapper, asyncResult, context);
                request.HttpWebResponse = Util.NullCheck <HttpWebResponse>(response, InternalError.InvalidEndGetResponseResponse);
                if (!this.IsBatch)
                {
                    this.HandleOperationResponse(response);
                    this.HandleOperationResponseHeaders(response.StatusCode, WebUtil.WrapResponseHeaders(response));
                }
                Stream responseStream = WebUtil.GetResponseStream(response, context);
                request.ResponseStream = responseStream;
                if ((responseStream != null) && responseStream.CanRead)
                {
                    if (this.buildBatchBuffer == null)
                    {
                        this.buildBatchBuffer = new byte[0x1f40];
                    }
                    do
                    {
                        asyncResult = BaseAsyncResult.InvokeAsync(new BaseAsyncResult.AsyncAction(responseStream.BeginRead), this.buildBatchBuffer, 0, this.buildBatchBuffer.Length, new AsyncCallback(this.AsyncEndRead), new AsyncReadState(request));
                        request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                    }while (((asyncResult.CompletedSynchronously && !request.RequestCompleted) && !base.IsCompletedInternally) && responseStream.CanRead);
                }
                else
                {
                    request.SetComplete();
                    if (!base.IsCompletedInternally && !request.RequestCompletedSynchronously)
                    {
                        this.FinishCurrentChange(request);
                    }
                }
            }
            catch (Exception exception)
            {
                if (base.HandleFailure(request, exception))
                {
                    throw;
                }
            }
            finally
            {
                this.HandleCompleted(request);
            }
        }
Beispiel #2
0
        private void AsyncEndRead(IAsyncResult asyncResult)
        {
            AsyncReadState asyncState = (AsyncReadState)asyncResult.AsyncState;

            BaseAsyncResult.PerRequest pereq = asyncState.Pereq;
            int count = 0;

            try
            {
                this.CompleteCheck(pereq, InternalError.InvalidEndReadCompleted);
                pereq.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                BaseAsyncResult.EqualRefCheck(base.perRequest, pereq, InternalError.InvalidEndRead);
                Stream stream = Util.NullCheck <Stream>(pereq.ResponseStream, InternalError.InvalidEndReadStream);
                count = stream.EndRead(asyncResult);
                if (0 < count)
                {
                    Util.NullCheck <Stream>(this.ResponseStream, InternalError.InvalidEndReadCopy).Write(this.buildBatchBuffer, 0, count);
                    asyncState.TotalByteCopied += count;
                    if (!asyncResult.CompletedSynchronously && stream.CanRead)
                    {
                        do
                        {
                            asyncResult = BaseAsyncResult.InvokeAsync(new BaseAsyncResult.AsyncAction(stream.BeginRead), this.buildBatchBuffer, 0, this.buildBatchBuffer.Length, new AsyncCallback(this.AsyncEndRead), asyncState);
                            pereq.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                            if ((!asyncResult.CompletedSynchronously || pereq.RequestCompleted) || base.IsCompletedInternally)
                            {
                                return;
                            }
                        }while (stream.CanRead);
                    }
                }
                else
                {
                    pereq.SetComplete();
                    if (!base.IsCompletedInternally && !pereq.RequestCompletedSynchronously)
                    {
                        this.FinishCurrentChange(pereq);
                    }
                }
            }
            catch (Exception exception)
            {
                if (base.HandleFailure(pereq, exception))
                {
                    throw;
                }
            }
            finally
            {
                this.HandleCompleted(pereq);
            }
        }