示例#1
0
        internal void BatchRequest()
        {
            ODataRequestMessageWrapper request = this.GenerateBatchRequest();

            if (request != null)
            {
                request.SetContentLengthHeader();
                MemoryStream       cachedRequestStream = request.CachedRequestStream;
                DataServiceContext source = (DataServiceContext)base.Source;
                using (Stream stream2 = WebUtil.GetRequestStream(request, source))
                {
                    byte[] buffer   = cachedRequestStream.GetBuffer();
                    int    position = (int)cachedRequestStream.Position;
                    int    count    = ((int)cachedRequestStream.Length) - position;
                    stream2.Write(buffer, position, count);
                }
                try
                {
                    base.batchResponse = WebUtil.GetResponse(request, source, false);
                }
                catch (WebException exception)
                {
                    WebUtil.GetHttpWebResponse(exception, ref this.batchResponse);
                    throw;
                }
                finally
                {
                    if (base.batchResponse != null)
                    {
                        this.responseStream = WebUtil.GetResponseStream(base.batchResponse, source);
                    }
                }
            }
        }
示例#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
        internal void CreateNextChange()
        {
            ODataRequestMessageWrapper requestMessage = null;

            do
            {
                HttpWebResponse response = null;
                try
                {
                    requestMessage = this.CreateNextRequest();
                    if (((requestMessage != null) || (base.entryIndex < base.ChangedEntries.Count)) && !base.ChangedEntries[base.entryIndex].ContentGeneratedForSave)
                    {
                        BaseAsyncResult.ContentStream stream = this.CreateNonBatchChangeData(base.entryIndex, requestMessage);
                        if ((stream != null) && (stream.Stream != null))
                        {
                            if (stream.IsKnownMemoryStream)
                            {
                                requestMessage.SetContentLengthHeader();
                            }
                            using (Stream stream2 = WebUtil.GetRequestStream(requestMessage, (DataServiceContext)base.Source))
                            {
                                int    num;
                                byte[] buffer = new byte[0x10000];
                                do
                                {
                                    num = stream.Stream.Read(buffer, 0, buffer.Length);
                                    if (num > 0)
                                    {
                                        stream2.Write(buffer, 0, num);
                                    }
                                }while (num > 0);
                            }
                        }
                        response = WebUtil.GetResponse(requestMessage, (DataServiceContext)base.Source, false);
                        this.HandleOperationResponse(response);
                        base.HandleOperationResponseHeaders(response.StatusCode, WebUtil.WrapResponseHeaders(response));
                        this.HandleOperationResponseData(response);
                        base.perRequest = null;
                    }
                }
                catch (InvalidOperationException exception)
                {
                    WebUtil.GetHttpWebResponse(exception, ref response);
                    this.HandleOperationException(exception, response);
                }
                finally
                {
                    if (response != null)
                    {
                        response.Close();
                    }
                }
            }while ((base.entryIndex < base.ChangedEntries.Count) && !base.IsCompletedInternally);
        }
示例#4
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;
            }
        }