コード例 #1
0
        /// <summary>
        /// Synchronous batch request
        /// </summary>
        internal void BatchRequest()
        {
            ODataRequestMessageWrapper batchRequestMessage = this.GenerateBatchRequest();

            if (batchRequestMessage != null)
            {
                batchRequestMessage.SetRequestStream(batchRequestMessage.CachedRequestStream);

                try
                {
                    this.batchResponseMessage = this.RequestInfo.GetSyncronousResponse(batchRequestMessage, false);
                }
                catch (DataServiceTransportException ex)
                {
                    InvalidOperationException exception = WebUtil.GetHttpWebResponse(ex, ref this.batchResponseMessage);

                    // For non-async batch requests we rethrow the WebException.  This is shipped behavior.
                    throw exception;
                }
                finally
                {
                    if (this.batchResponseMessage != null)
                    {
                        // For non-async batch requests we call the test hook to get the response stream but we cannot consume it
                        // because we rethrow what we caught and the customer need to be able to read the response stream from the WebException.
                        // Note that on the async batch code path we do consume the response stream and throw a DataServiceRequestException.
                        this.responseStream = this.batchResponseMessage.GetStream();
                    }
                }
            }
        }
コード例 #2
0
ファイル: SaveResult.cs プロジェクト: pbvs/odata.net
        /// <summary>
        /// This starts the next change
        /// </summary>
        internal void CreateNextChange()
        {
            ODataRequestMessageWrapper requestMessage = null;

            do
            {
                IODataResponseMessage responseMsg = null;

                try
                {
                    requestMessage = this.CreateNextRequest();
                    if ((requestMessage != null) || (this.entryIndex < this.ChangedEntries.Count))
                    {
                        if (this.ChangedEntries[this.entryIndex].ContentGeneratedForSave)
                        {
                            Debug.Assert(this.ChangedEntries[this.entryIndex] is LinkDescriptor, "only expected RelatedEnd to presave");
                            Debug.Assert(
                                this.ChangedEntries[this.entryIndex].State == EntityStates.Added ||
                                this.ChangedEntries[this.entryIndex].State == EntityStates.Modified,
                                "only expected added to presave");
                            continue;
                        }

                        ContentStream contentStream = this.CreateNonBatchChangeData(this.entryIndex, requestMessage);
                        if (contentStream != null && contentStream.Stream != null)
                        {
                            requestMessage.SetRequestStream(contentStream);
                        }

                        responseMsg = this.RequestInfo.GetSynchronousResponse(requestMessage, false);

                        this.HandleOperationResponse(responseMsg);
                        this.HandleOperationResponseHeaders((HttpStatusCode)responseMsg.StatusCode, new HeaderCollection(responseMsg));
                        this.HandleOperationResponseData(responseMsg);
                        this.perRequest = null;
                    }
                }
                catch (InvalidOperationException e)
                {
                    e = WebUtil.GetHttpWebResponse(e, ref responseMsg);
                    this.HandleOperationException(e, responseMsg);
                }
                finally
                {
                    WebUtil.DisposeMessage(responseMsg);
                }

                // we have no more pending requests or there has been an error in the previous request and we decided not to continue
                // (When an error occurs and we are not going to continue on error, we call SetCompleted
            }while (this.entryIndex < this.ChangedEntries.Count && !this.IsCompletedInternally);

            Debug.Assert(this.entryIndex < this.ChangedEntries.Count || this.ChangedEntries.All(o => o.ContentGeneratedForSave), "didn't generate content for all entities/links");
        }