예제 #1
0
 protected override void FinishCurrentChange(BaseAsyncResult.PerRequest pereq)
 {
     base.FinishCurrentChange(pereq);
     this.ResponseStream.Position = 0L;
     base.perRequest = null;
     base.SetCompleted();
 }
예제 #2
0
 internal void BatchBeginRequest()
 {
     BaseAsyncResult.PerRequest pereq = null;
     try
     {
         ODataRequestMessageWrapper request = this.GenerateBatchRequest();
         if (request != null)
         {
             request.SetContentLengthHeader();
             base.perRequest            = pereq = new BaseAsyncResult.PerRequest();
             pereq.Request              = request;
             pereq.RequestContentStream = new BaseAsyncResult.ContentStream(request.CachedRequestStream, true);
             BaseAsyncResult.AsyncStateBag state = new BaseAsyncResult.AsyncStateBag(pereq, (DataServiceContext)base.Source);
             this.responseStream = new MemoryStream();
             IAsyncResult result = BaseAsyncResult.InvokeAsync(new Func <ODataRequestMessageWrapper, AsyncCallback, object, IAsyncResult>(WebUtil.BeginGetRequestStream), request, new AsyncCallback(this.AsyncEndGetRequestStream), state);
             pereq.SetRequestCompletedSynchronously(result.CompletedSynchronously);
         }
     }
     catch (Exception exception)
     {
         base.HandleFailure(pereq, exception);
         throw;
     }
     finally
     {
         this.HandleCompleted(pereq);
     }
 }
예제 #3
0
 protected override void CompleteCheck(BaseAsyncResult.PerRequest pereq, InternalError errorcode)
 {
     if ((pereq == null) || ((pereq.RequestCompleted || base.IsCompletedInternally) && (!base.IsAborted && !pereq.RequestAborted)))
     {
         System.Data.Services.Client.Error.ThrowInternalError(errorcode);
     }
 }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
 protected override void HandleCompleted(BaseAsyncResult.PerRequest pereq)
 {
     if (pereq != null)
     {
         base.SetCompletedSynchronously(pereq.RequestCompletedSynchronously);
         if (pereq.RequestCompleted)
         {
             Interlocked.CompareExchange <BaseAsyncResult.PerRequest>(ref this.perRequest, null, pereq);
             pereq.Dispose();
         }
     }
     base.HandleCompleted();
 }
예제 #7
0
        private void AsyncEndRead(IAsyncResult asyncResult)
        {
            BaseAsyncResult.AsyncStateBag asyncState = asyncResult.AsyncState as BaseAsyncResult.AsyncStateBag;
            BaseAsyncResult.PerRequest    request    = (asyncState == null) ? null : asyncState.PerRequest;
            int count = 0;

            try
            {
                this.CompleteCheck(request, InternalError.InvalidEndReadCompleted);
                request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                base.SetCompletedSynchronously(asyncResult.CompletedSynchronously);
                Stream stream  = Util.NullCheck <Stream>(request.ResponseStream, InternalError.InvalidEndReadStream);
                Stream stream2 = Util.NullCheck <Stream>(this.outputResponseStream, InternalError.InvalidEndReadCopy);
                byte[] buffer  = Util.NullCheck <byte[]>(this.asyncStreamCopyBuffer, InternalError.InvalidEndReadBuffer);
                count            = stream.EndRead(asyncResult);
                this.usingBuffer = false;
                if (0 < count)
                {
                    stream2.Write(buffer, 0, count);
                }
                if (((0 < count) && (0 < buffer.Length)) && stream.CanRead)
                {
                    if (!asyncResult.CompletedSynchronously)
                    {
                        this.ReadResponseStream(asyncState);
                    }
                }
                else
                {
                    if (stream2.Position < stream2.Length)
                    {
                        ((MemoryStream)stream2).SetLength(stream2.Position);
                    }
                    request.SetComplete();
                    base.SetCompleted();
                }
            }
            catch (Exception exception)
            {
                if (base.HandleFailure(exception))
                {
                    throw;
                }
            }
            finally
            {
                this.HandleCompleted(request);
            }
        }
예제 #8
0
        private void ReadResponseStream(BaseAsyncResult.AsyncStateBag asyncStateBag)
        {
            BaseAsyncResult.PerRequest perRequest = asyncStateBag.PerRequest;
            IAsyncResult result = null;

            byte[] asyncStreamCopyBuffer = this.asyncStreamCopyBuffer;
            Stream responseStream        = perRequest.ResponseStream;

            do
            {
                int offset = 0;
                int length = asyncStreamCopyBuffer.Length;
                this.usingBuffer = true;
                result           = BaseAsyncResult.InvokeAsync(new BaseAsyncResult.AsyncAction(responseStream.BeginRead), asyncStreamCopyBuffer, offset, length, new AsyncCallback(this.AsyncEndRead), asyncStateBag);
                perRequest.SetRequestCompletedSynchronously(result.CompletedSynchronously);
                base.SetCompletedSynchronously(result.CompletedSynchronously);
            }while ((result.CompletedSynchronously && !perRequest.RequestCompleted) && (!base.IsCompletedInternally && responseStream.CanRead));
        }
예제 #9
0
 protected override void FinishCurrentChange(BaseAsyncResult.PerRequest pereq)
 {
     base.FinishCurrentChange(pereq);
     if (this.ResponseStream.Position != 0L)
     {
         this.ResponseStream.Position = 0L;
         this.HandleOperationResponseData(this.httpWebResponse, this.ResponseStream);
     }
     else
     {
         this.HandleOperationResponseData(this.httpWebResponse, null);
     }
     pereq.Dispose();
     base.perRequest = null;
     if (!pereq.RequestCompletedSynchronously && !base.IsCompletedInternally)
     {
         this.BeginCreateNextChange();
     }
 }
예제 #10
0
        internal void BeginExecuteQuery(DataServiceContext context)
        {
            IAsyncResult result = null;

            BaseAsyncResult.PerRequest    pereq = new BaseAsyncResult.PerRequest();
            BaseAsyncResult.AsyncStateBag state = new BaseAsyncResult.AsyncStateBag(pereq, context);
            pereq.Request   = this.Request;
            base.perRequest = pereq;
            try
            {
                if ((this.requestContentStream != null) && (this.requestContentStream.Stream != null))
                {
                    if (this.requestContentStream.IsKnownMemoryStream)
                    {
                        this.Request.SetContentLengthHeader();
                    }
                    base.perRequest.RequestContentStream = this.requestContentStream;
                    result = BaseAsyncResult.InvokeAsync(new Func <ODataRequestMessageWrapper, AsyncCallback, object, IAsyncResult>(WebUtil.BeginGetRequestStream), this.Request, new AsyncCallback(this.AsyncEndGetRequestStream), state);
                }
                else
                {
                    result = BaseAsyncResult.InvokeAsync(new Func <ODataRequestMessageWrapper, AsyncCallback, object, IAsyncResult>(WebUtil.BeginGetResponse), this.Request, new AsyncCallback(this.AsyncEndGetResponse), state);
                }
                pereq.SetRequestCompletedSynchronously(result.CompletedSynchronously);
                base.SetCompletedSynchronously(result.CompletedSynchronously);
            }
            catch (Exception exception)
            {
                base.HandleFailure(exception);
                throw;
            }
            finally
            {
                this.HandleCompleted(pereq);
            }
        }
예제 #11
0
 protected override void HandleCompleted(BaseAsyncResult.PerRequest pereq)
 {
     Error.ThrowInternalError(InternalError.InvalidHandleCompleted);
 }
예제 #12
0
        internal void BeginCreateNextChange()
        {
            HttpWebResponse response;

            this.inMemoryResponseStream = new MemoryStream();
            BaseAsyncResult.PerRequest pereq = null;
            IAsyncResult result = null;

Label_000F:
            response = null;
            ODataRequestMessageWrapper requestMessage = null;

            try
            {
                if (base.perRequest != null)
                {
                    base.SetCompleted();
                    System.Data.Services.Client.Error.ThrowInternalError(InternalError.InvalidBeginNextChange);
                }
                requestMessage = this.CreateNextRequest();
                if (requestMessage == null)
                {
                    base.Abortable = null;
                }
                if ((requestMessage != null) || (base.entryIndex < base.ChangedEntries.Count))
                {
                    if (base.ChangedEntries[base.entryIndex].ContentGeneratedForSave)
                    {
                        goto Label_0191;
                    }
                    base.Abortable = requestMessage;
                    BaseAsyncResult.ContentStream stream = this.CreateNonBatchChangeData(base.entryIndex, requestMessage);
                    base.perRequest = pereq = new BaseAsyncResult.PerRequest();
                    pereq.Request   = requestMessage;
                    BaseAsyncResult.AsyncStateBag state = new BaseAsyncResult.AsyncStateBag(pereq, (DataServiceContext)base.Source);
                    if ((stream == null) || (stream.Stream == null))
                    {
                        result = BaseAsyncResult.InvokeAsync(new Func <ODataRequestMessageWrapper, AsyncCallback, object, IAsyncResult>(WebUtil.BeginGetResponse), requestMessage, new AsyncCallback(this.AsyncEndGetResponse), state);
                    }
                    else
                    {
                        if (stream.IsKnownMemoryStream)
                        {
                            requestMessage.SetContentLengthHeader();
                        }
                        pereq.RequestContentStream = stream;
                        result = BaseAsyncResult.InvokeAsync(new Func <ODataRequestMessageWrapper, AsyncCallback, object, IAsyncResult>(WebUtil.BeginGetRequestStream), requestMessage, new AsyncCallback(this.AsyncEndGetRequestStream), state);
                    }
                    pereq.SetRequestCompletedSynchronously(result.CompletedSynchronously);
                    base.SetCompletedSynchronously(pereq.RequestCompletedSynchronously);
                }
                else
                {
                    base.SetCompleted();
                    if (base.CompletedSynchronously)
                    {
                        this.HandleCompleted(pereq);
                    }
                }
            }
            catch (InvalidOperationException exception)
            {
                WebUtil.GetHttpWebResponse(exception, ref response);
                this.HandleOperationException(exception, response);
                this.HandleCompleted(pereq);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
            if (((pereq != null) && pereq.RequestCompleted) && (pereq.RequestCompletedSynchronously && !base.IsCompletedInternally))
            {
                this.FinishCurrentChange(pereq);
            }
Label_0191:
            if (((pereq == null) || (pereq.RequestCompleted && pereq.RequestCompletedSynchronously)) && !base.IsCompletedInternally)
            {
                goto Label_000F;
            }
        }
예제 #13
0
 /// <summary>Set the AsyncWait and invoke the user callback.</summary>
 /// <param name="pereq">the request object</param>
 /// <remarks>This method is not implemented for this class.</remarks>
 protected override void HandleCompleted(BaseAsyncResult.PerRequest pereq)
 {
     Debug.Assert(false, "This method should never be called from GetReadStreamResult.");
     Error.ThrowInternalError(InternalError.InvalidHandleCompleted);
 }
예제 #14
0
 internal AsyncReadState(BaseAsyncResult.PerRequest pereq)
 {
     this.Pereq           = pereq;
     this.totalByteCopied = 0;
 }
예제 #15
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
            {
                if (base.IsAborted)
                {
                    if (request != null)
                    {
                        request.SetComplete();
                    }
                    base.SetCompleted();
                }
                else
                {
                    this.CompleteCheck(request, InternalError.InvalidEndGetResponseCompleted);
                    request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                    base.SetCompletedSynchronously(asyncResult.CompletedSynchronously);
                    HttpWebResponse response = WebUtil.EndGetResponse(Util.NullCheck <ODataRequestMessageWrapper>(request.Request, InternalError.InvalidEndGetResponseRequest), asyncResult, context);
                    request.HttpWebResponse = Util.NullCheck <HttpWebResponse>(response, InternalError.InvalidEndGetResponseResponse);
                    this.SetHttpWebResponse(request.HttpWebResponse);
                    Stream responseStream = null;
                    if (HttpStatusCode.NoContent != response.StatusCode)
                    {
                        responseStream         = WebUtil.GetResponseStream(response, context);
                        request.ResponseStream = responseStream;
                    }
                    if ((responseStream != null) && responseStream.CanRead)
                    {
                        if (this.outputResponseStream == null)
                        {
                            this.outputResponseStream = Util.NullCheck <Stream>(this.GetAsyncResponseStreamCopy(), InternalError.InvalidAsyncResponseStreamCopy);
                        }
                        if (this.asyncStreamCopyBuffer == null)
                        {
                            this.asyncStreamCopyBuffer = Util.NullCheck <byte[]>(this.GetAsyncResponseStreamCopyBuffer(), InternalError.InvalidAsyncResponseStreamCopyBuffer);
                        }
                        this.ReadResponseStream(asyncState);
                    }
                    else
                    {
                        request.SetComplete();
                        base.SetCompleted();
                    }
                }
            }
            catch (Exception exception)
            {
                if (base.HandleFailure(exception))
                {
                    throw;
                }
            }
            finally
            {
                this.HandleCompleted(request);
            }
        }