コード例 #1
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);
     }
 }
コード例 #2
0
ファイル: BaseSaveResult.cs プロジェクト: modulexcite/pash-1
        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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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));
        }
コード例 #5
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);
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
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);
            }
        }