Esempio n. 1
0
        internal MaterializeAtom GetMaterializer(DataServiceContext context, ProjectionPlan plan)
        {
            Debug.Assert(this.IsCompletedInternally, "request hasn't completed yet");

            MaterializeAtom materializer;

            if (HttpStatusCode.NoContent != this.StatusCode)
            {
                materializer = DataServiceRequest.Materialize(context, this.ServiceRequest.QueryComponents, plan, this.ContentType, this.GetResponseStream());
            }
            else
            {
                materializer = MaterializeAtom.EmptyResults;
            }

            return(materializer);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an instance of <see cref="MaterializeAtom"/> for the given plan.
        /// </summary>
        /// <param name="plan">The projection plan.</param>
        /// <param name="payloadKind">expected payload kind.</param>
        /// <returns>A new materializer instance</returns>
        private MaterializeAtom CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind)
        {
            QueryComponents queryComponents = this.ServiceRequest.QueryComponents(this.responseInfo.Model);

            // In V2, in projection path, we did not check for assignability between the expected type and the type returned by the type resolver.
            if (plan != null || queryComponents.Projection != null)
            {
                this.RequestInfo.TypeResolver.IsProjectionRequest();
            }

            var responseMessageWrapper = new HttpWebResponseMessage(
                new HeaderCollection(this.responseMessage), 
                this.responseMessage.StatusCode, 
                this.GetResponseStream,
                this.AllowDirectNetworkStreamReading ? this.responseMessage : null); // If AllowDirectNetworkStreamReading is true, the responseMessage will be disposed later when enumeration has finished.

            return DataServiceRequest.Materialize(
                this.responseInfo,
                queryComponents,
                plan,
                this.ContentType,
                responseMessageWrapper,
                payloadKind);
        }
Esempio n. 3
0
        internal QueryOperationResponse <TElement> ProcessResult <TElement>(DataServiceContext context, ProjectionPlan plan)
        {
            MaterializeAtom materializeAtom = DataServiceRequest.Materialize(context, this.ServiceRequest.QueryComponents, plan, this.ContentType, this.GetResponseStream());

            return(this.GetResponse <TElement>(materializeAtom));
        }
Esempio n. 4
0
        private IEnumerable <OperationResponse> HandleBatchResponse(ODataBatchReader batchReader)
        {
            if (this.batchMessageReader == null)
            {
                goto Label_056D;
            }
            bool iteratorVariable0 = false;
            bool iteratorVariable1 = false;
            int  index             = 0;
            int  iteratorVariable3 = 0;

            this.entryIndex = 0;
            Label_PostSwitchInIterator :;
            while (batchReader.Read())
            {
                Exception iteratorVariable4;
                switch (batchReader.State)
                {
                case ODataBatchReaderState.Operation:
                {
                    iteratorVariable4 = this.ProcessCurrentOperationResponse(batchReader);
                    if (iteratorVariable1)
                    {
                        break;
                    }
                    QueryOperationResponse iteratorVariable5 = null;
                    try
                    {
                        if (iteratorVariable4 == null)
                        {
                            DataServiceRequest query   = this.Queries[index];
                            MaterializeAtom    results = DataServiceRequest.Materialize(this.RequestInfo.GetDeserializationInfo(null), query.QueryComponents(this.RequestInfo.MaxProtocolVersion), null, this.currentOperationResponse.GetHeader("Content-Type"), this.currentOperationResponse.CreateResponseMessage(), query.PayloadKind);
                            iteratorVariable5 = QueryOperationResponse.GetInstance(query.ElementType, this.currentOperationResponse.Headers, query, results);
                        }
                    }
                    catch (ArgumentException exception)
                    {
                        iteratorVariable4 = exception;
                    }
                    catch (FormatException exception2)
                    {
                        iteratorVariable4 = exception2;
                    }
                    catch (InvalidOperationException exception3)
                    {
                        iteratorVariable4 = exception3;
                    }
                    if (iteratorVariable5 == null)
                    {
                        if (this.Queries == null)
                        {
                            throw iteratorVariable4;
                        }
                        DataServiceRequest request2 = this.Queries[index];
                        if (this.RequestInfo.IgnoreResourceNotFoundException && (this.currentOperationResponse.StatusCode == HttpStatusCode.NotFound))
                        {
                            iteratorVariable5 = QueryOperationResponse.GetInstance(request2.ElementType, this.currentOperationResponse.Headers, request2, MaterializeAtom.EmptyResults);
                        }
                        else
                        {
                            iteratorVariable5       = QueryOperationResponse.GetInstance(request2.ElementType, this.currentOperationResponse.Headers, request2, MaterializeAtom.EmptyResults);
                            iteratorVariable5.Error = iteratorVariable4;
                        }
                    }
                    iteratorVariable5.StatusCode = (int)this.currentOperationResponse.StatusCode;
                    index++;
                    yield return(iteratorVariable5);

                    goto Label_PostSwitchInIterator;
                }

                case ODataBatchReaderState.ChangesetStart:
                {
                    if ((this.IsBatch && iteratorVariable0) || (iteratorVariable3 != 0))
                    {
                        System.Data.Services.Client.Error.ThrowBatchUnexpectedContent(InternalError.UnexpectedBeginChangeSet);
                    }
                    iteratorVariable1 = true;
                    continue;
                }

                case ODataBatchReaderState.ChangesetEnd:
                {
                    iteratorVariable0 = true;
                    iteratorVariable3 = 0;
                    iteratorVariable1 = false;
                    continue;
                }

                default:
                    goto Label_0491;
                }
                this.entryIndex = this.ValidateContentID(this.currentOperationResponse.Headers);
                try
                {
                    Descriptor descriptor = this.ChangedEntries[this.entryIndex];
                    iteratorVariable3 += this.SaveResultProcessed(descriptor);
                    if (iteratorVariable4 != null)
                    {
                        throw iteratorVariable4;
                    }
                    this.HandleOperationResponseHeaders(this.currentOperationResponse.StatusCode, this.currentOperationResponse.Headers);
                    this.HandleOperationResponse(descriptor, this.currentOperationResponse.Headers);
                }
                catch (Exception exception4)
                {
                    this.ChangedEntries[this.entryIndex].SaveError = exception4;
                    iteratorVariable4 = exception4;
                    if (!CommonUtil.IsCatchableExceptionType(exception4))
                    {
                        throw;
                    }
                }
                ChangeOperationResponse iteratorVariable6 = new ChangeOperationResponse(this.currentOperationResponse.Headers, this.ChangedEntries[this.entryIndex])
                {
                    StatusCode = (int)this.currentOperationResponse.StatusCode
                };
                if (iteratorVariable4 != null)
                {
                    iteratorVariable6.Error = iteratorVariable4;
                }
                iteratorVariable3++;
                this.entryIndex++;
                yield return(iteratorVariable6);

                goto Label_PostSwitchInIterator;
Label_0491:
                System.Data.Services.Client.Error.ThrowBatchExpectedResponse(InternalError.UnexpectedBatchState);
            }
            if (((this.Queries == null) && ((!iteratorVariable0 || (0 < index)) || (this.ChangedEntries.Any <Descriptor>(o => (o.ContentGeneratedForSave && (o.SaveResultWasProcessed == 0))) && (!this.IsBatch || (this.ChangedEntries.FirstOrDefault <Descriptor>(o => (o.SaveError != null)) == null))))) || ((this.Queries != null) && (index != this.Queries.Length)))
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Batch_IncompleteResponseCount);
            }
Label_056D:
            yield break;
        }
Esempio n. 5
0
        private MaterializeAtom CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind)
        {
            HttpWebResponseMessage message = new HttpWebResponseMessage(this.httpWebResponse, () => this.GetResponseStream());

            return(DataServiceRequest.Materialize(this.responseInfo, this.ServiceRequest.QueryComponents(this.responseInfo.MaxProtocolVersion), plan, this.ContentType, message, payloadKind));
        }