Exemple #1
0
 internal string ReadCustomElementString()
 {
     Debug.Assert(
         this.kind == AtomDataKind.Custom,
         "this.kind == AtomDataKind.Custom -- otherwise caller shouldn't invoke ReadCustomElementString");
     return(MaterializeAtom.ReadElementString(this.reader, true));
 }
Exemple #2
0
        private void ParseCurrentFeedCount()
        {
            if (this.feed == null)
            {
                throw new InvalidOperationException(Strings.AtomParser_FeedCountNotUnderFeed);
            }

            if (this.feed.Count.HasValue)
            {
                throw new InvalidOperationException(Strings.AtomParser_ManyFeedCounts);
            }

            long countValue;

            if (!long.TryParse(MaterializeAtom.ReadElementString(this.reader, true), System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out countValue))
            {
                throw new FormatException(Strings.MaterializeFromAtom_CountFormatError);
            }

            if (countValue < 0)
            {
                throw new FormatException(Strings.MaterializeFromAtom_CountFormatError);
            }

            this.feed.Count = countValue;
        }
        internal virtual PrimitiveParserToken TokenizeFromXml(XmlReader reader)
        {
            string text = MaterializeAtom.ReadElementString(reader, true);

            if (text != null)
            {
                return(new TextPrimitiveParserToken(text));
            }
            return(null);
        }
Exemple #4
0
 internal QueryOperationResponse GetResponseWithType(MaterializeAtom results, Type elementType)
 {
     if (this.httpWebResponse != null)
     {
         Dictionary <string, string> headers  = WebUtil.WrapResponseHeaders(this.httpWebResponse);
         QueryOperationResponse      response = QueryOperationResponse.GetInstance(elementType, headers, this.ServiceRequest, results);
         response.StatusCode = (int)this.httpWebResponse.StatusCode;
         return(response);
     }
     return(null);
 }
Exemple #5
0
 internal QueryOperationResponse <TElement> GetResponse <TElement>(MaterializeAtom results)
 {
     if (this.httpWebResponse != null)
     {
         return(new QueryOperationResponse <TElement>(WebUtil.WrapResponseHeaders(this.httpWebResponse), this.ServiceRequest, results)
         {
             StatusCode = (int)this.httpWebResponse.StatusCode
         });
     }
     return(null);
 }
Exemple #6
0
        internal QueryOperationResponse <TElement> GetResponse <TElement>(MaterializeAtom results)
        {
            if (this.httpWebResponse != null)
            {
                Dictionary <string, string>       headers  = WebUtil.WrapResponseHeaders(this.httpWebResponse);
                QueryOperationResponse <TElement> response = new QueryOperationResponse <TElement>(headers, this.ServiceRequest, results);
                response.StatusCode = (int)this.httpWebResponse.StatusCode;
                return(response);
            }

            return(null);
        }
        /// <summary>
        /// Create a parser token from xml feed
        /// </summary>
        /// <param name="reader">The xml reader</param>
        /// <remarks>The reader is expected to be placed at the beginning of the element, and after this method call, the reader will be placed
        /// at the EndElement, such that the next Element will be read in the next Read call.</remarks>
        /// <returns>token</returns>
        internal virtual PrimitiveParserToken TokenizeFromXml(XmlReader reader)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element, "Reader at element");
            string elementString = MaterializeAtom.ReadElementString(reader, true);

            if (elementString != null)
            {
                return(new TextPrimitiveParserToken(elementString));
            }

            return(null);
        }
Exemple #8
0
        /// <summary>
        /// Returns the response for the request.
        /// </summary>
        /// <param name="results">materialized results for the request.</param>
        /// <param name="elementType">element type of the results.</param>
        /// <returns>returns the instance of QueryOperationResponse containing the response.</returns>
        internal QueryOperationResponse GetResponseWithType(MaterializeAtom results, Type elementType)
        {
            if (this.responseMessage != null)
            {
                HeaderCollection headers = new HeaderCollection(this.responseMessage);
                QueryOperationResponse response = QueryOperationResponse.GetInstance(elementType, headers, this.ServiceRequest, results);
                response.StatusCode = (int)this.responseMessage.StatusCode;
                return response;
            }

            return null;
        }
Exemple #9
0
        /// <summary>
        /// Returns the response for the request.
        /// </summary>
        /// <param name="results">materialized results for the request.</param>
        /// <typeparam name="TElement">element type of the results.</typeparam>
        /// <returns>returns the instance of QueryOperationResponse containing the response.</returns>
        internal QueryOperationResponse<TElement> GetResponse<TElement>(MaterializeAtom results)
        {
            if (this.responseMessage != null)
            {
                HeaderCollection headers = new HeaderCollection(this.responseMessage);
                QueryOperationResponse<TElement> response = new QueryOperationResponse<TElement>(headers, this.ServiceRequest, results);
                response.StatusCode = (int)this.responseMessage.StatusCode;
                return response;
            }

            return null;
        }
        private MaterializeAtom ReadPropertyFromRawData(ClientPropertyAnnotation property)
        {
            MaterializeAtom    atom;
            DataServiceContext source = (DataServiceContext)base.Source;
            bool applyingChanges      = source.ApplyingChanges;

            try
            {
                source.ApplyingChanges = true;
                string   mime     = null;
                Encoding encoding = null;
                Type     type     = property.EntityCollectionItemType ?? property.NullablePropertyType;
                IList    results  = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type }));
                HttpProcessUtility.ReadContentType(base.ContentType, out mime, out encoding);
                using (Stream stream = base.GetResponseStream())
                {
                    if (property.PropertyType == typeof(byte[]))
                    {
                        int    contentLength = (int)base.ContentLength;
                        byte[] buffer        = null;
                        if (contentLength >= 0)
                        {
                            buffer = ReadByteArrayWithContentLength(stream, contentLength);
                        }
                        else
                        {
                            buffer = ReadByteArrayChunked(stream);
                        }
                        results.Add(buffer);
                        property.SetValue(this.entity, buffer, this.propertyName, false);
                    }
                    else
                    {
                        StreamReader reader = new StreamReader(stream, encoding);
                        object       obj2   = (property.PropertyType == typeof(string)) ? reader.ReadToEnd() : ClientConvert.ChangeType(reader.ReadToEnd(), property.PropertyType);
                        results.Add(obj2);
                        property.SetValue(this.entity, obj2, this.propertyName, false);
                    }
                }
                if (property.MimeTypeProperty != null)
                {
                    property.MimeTypeProperty.SetValue(this.entity, mime, null, false);
                }
                atom = MaterializeAtom.CreateWrapper(source, results);
            }
            finally
            {
                source.ApplyingChanges = applyingChanges;
            }
            return(atom);
        }
Exemple #11
0
        /// <summary>
        /// loading a property from a response
        /// </summary>
        /// <returns>QueryOperationResponse instance containing information about the response.</returns>
        internal QueryOperationResponse LoadProperty()
        {
            MaterializeAtom results = null;

            DataServiceContext context = (DataServiceContext)this.Source;

            ClientEdmModel       model = context.Model;
            ClientTypeAnnotation type  = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(this.entity.GetType()));

            Debug.Assert(type.IsEntityType, "must be entity type to be contained");

            EntityDescriptor box = context.GetEntityDescriptor(this.entity);

            if (EntityStates.Added == box.State)
            {
                throw Error.InvalidOperation(Strings.Context_NoLoadWithInsertEnd);
            }

            ClientPropertyAnnotation property = type.GetProperty(this.propertyName, false);
            Type elementType = property.EntityCollectionItemType ?? property.NullablePropertyType;

            try
            {
                if (type.MediaDataMember == property)
                {
                    results = this.ReadPropertyFromRawData(property);
                }
                else
                {
                    results = this.ReadPropertyFromAtom(property);
                }

                return(this.GetResponseWithType(results, elementType));
            }
            catch (InvalidOperationException ex)
            {
                QueryOperationResponse response = this.GetResponseWithType(results, elementType);
                if (response != null)
                {
                    response.Error = ex;
                    throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, response);
                }

                throw;
            }
        }
Exemple #12
0
 private void MaterializeResponse(EntityDescriptor entityDescriptor, ResponseInfo responseInfo, string etag)
 {
     using (MaterializeAtom atom = this.GetMaterializer(entityDescriptor, responseInfo))
     {
         atom.SetInsertingObject(entityDescriptor.Entity);
         object obj2 = null;
         foreach (object obj3 in atom)
         {
             if (obj2 != null)
             {
                 System.Data.Services.Client.Error.ThrowInternalError(InternalError.MaterializerReturningMoreThanOneEntity);
             }
             obj2 = obj3;
         }
         if (entityDescriptor.GetLatestETag() == null)
         {
             entityDescriptor.ETag = etag;
         }
     }
 }
        internal QueryOperationResponse LoadProperty()
        {
            MaterializeAtom        results = null;
            QueryOperationResponse responseWithType;
            DataServiceContext     source = (DataServiceContext)base.Source;
            ClientEdmModel         model  = ClientEdmModel.GetModel(source.MaxProtocolVersion);
            ClientTypeAnnotation   clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(this.entity.GetType()));
            EntityDescriptor       entityDescriptor     = source.GetEntityDescriptor(this.entity);

            if (EntityStates.Added == entityDescriptor.State)
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_NoLoadWithInsertEnd);
            }
            ClientPropertyAnnotation property = clientTypeAnnotation.GetProperty(this.propertyName, false);
            Type elementType = property.EntityCollectionItemType ?? property.NullablePropertyType;

            try
            {
                if (clientTypeAnnotation.MediaDataMember == property)
                {
                    results = this.ReadPropertyFromRawData(property);
                }
                else
                {
                    results = this.ReadPropertyFromAtom(entityDescriptor, property);
                }
                responseWithType = base.GetResponseWithType(results, elementType);
            }
            catch (InvalidOperationException exception)
            {
                QueryOperationResponse response = base.GetResponseWithType(results, elementType);
                if (response != null)
                {
                    response.Error = exception;
                    throw new DataServiceQueryException(System.Data.Services.Client.Strings.DataServiceException_GeneralError, exception, response);
                }
                throw;
            }
            return(responseWithType);
        }
 internal QueryOperationResponse(Dictionary <string, string> headers, DataServiceRequest query, MaterializeAtom results)
     : base(headers)
 {
     this.query   = query;
     this.results = results;
 }
        internal static QueryOperationResponse GetInstance(Type elementType, Dictionary <string, string> headers, DataServiceRequest query, MaterializeAtom results)
        {
            Type genericType = typeof(QueryOperationResponse <>).MakeGenericType(elementType);

#if !ASTORIA_LIGHT
            return((QueryOperationResponse)Activator.CreateInstance(
                       genericType,
                       BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Instance,
                       null,
                       new object[] { headers, query, results },
                       System.Globalization.CultureInfo.InvariantCulture));
#else
            System.Reflection.ConstructorInfo[] info = genericType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
            System.Diagnostics.Debug.Assert(1 == info.Length, "only expected 1 ctor");
            return((QueryOperationResponse)Util.ConstructorInvoke(info[0], new object[] { headers, query, results }));
#endif
        }
Exemple #16
0
        /// <summary>Consumes the next chunk of content from the underlying XML reader.</summary>
        /// <returns>
        /// true if another piece of content is available, identified by DataKind.
        /// false if there is no more content.
        /// </returns>
        internal bool Read()
        {
            // When an external caller 'insists', we'll come all the way down (which is the 'most local'
            // scope at which this is known), and unwind as a no-op.
            if (this.DataKind == AtomDataKind.Finished)
            {
                return(false);
            }

            while (this.reader.Read())
            {
                if (ShouldIgnoreNode(this.reader))
                {
                    continue;
                }

                Debug.Assert(
                    this.reader.NodeType == XmlNodeType.Element || this.reader.NodeType == XmlNodeType.EndElement,
                    "this.reader.NodeType == XmlNodeType.Element || this.reader.NodeType == XmlNodeType.EndElement -- otherwise we should have ignored or thrown");

                AtomDataKind readerData = ParseStateForReader(this.reader);

                if (this.reader.NodeType == XmlNodeType.EndElement)
                {
                    // The only case in which we expect to see an end-element at the top level
                    // is for a feed. Custom elements and entries should be consumed by
                    // their own parsing methods. However we are tolerant of additional EndElements,
                    // which at this point mean we have nothing else to consume.
                    break;
                }

                switch (readerData)
                {
                case AtomDataKind.Custom:
                    if (this.DataKind == AtomDataKind.None)
                    {
                        this.kind = AtomDataKind.Custom;
                        return(true);
                    }
                    else
                    {
                        MaterializeAtom.SkipToEnd(this.reader);
                        continue;
                    }

                case AtomDataKind.Entry:
                    this.kind = AtomDataKind.Entry;
                    this.ParseCurrentEntry(out this.entry);
                    return(true);

                case AtomDataKind.Feed:
                    if (this.DataKind == AtomDataKind.None)
                    {
                        this.feed = new AtomFeed();
                        this.kind = AtomDataKind.Feed;
                        return(true);
                    }

                    throw new InvalidOperationException(Strings.AtomParser_FeedUnexpected);

                case AtomDataKind.FeedCount:
                    this.ParseCurrentFeedCount();
                    break;

                case AtomDataKind.PagingLinks:
                    if (this.feed == null)
                    {
                        // paging link outside of feed?
                        throw new InvalidOperationException(Strings.AtomParser_PagingLinkOutsideOfFeed);
                    }

                    this.kind = AtomDataKind.PagingLinks;
                    this.ParseCurrentFeedPagingLinks();
                    return(true);

                default:
                    Debug.Assert(false, "Atom Parser is in a wrong state...Did you add a new AtomDataKind?");
                    break;
                }
            }

            this.kind  = AtomDataKind.Finished;
            this.entry = null;
            return(false);
        }
Exemple #17
0
 /// <summary>
 /// Processes the result for successfull request and produces the actual result of the request.
 /// </summary>
 /// <typeparam name="TElement">Element type of the result.</typeparam>
 /// <param name="plan">The plan to use for the projection, if available in precompiled form.</param>
 /// <returns>A instance of QueryResponseResult created on top of of the request.</returns>
 internal QueryOperationResponse<TElement> ProcessResult<TElement>(ProjectionPlan plan)
 {
     Debug.Assert(this.responseInfo != null, "The request didn't complete yet, we don't have a response info for it.");
     MaterializeAtom materializeAtom = this.CreateMaterializer(plan, this.ServiceRequest.PayloadKind);
     return this.GetResponse<TElement>(materializeAtom);
 }
Exemple #18
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="headers">HTTP headers</param>
 /// <param name="query">original query</param>
 /// <param name="results">retrieved objects</param>
 internal QueryOperationResponse(HeaderCollection headers, DataServiceRequest query, MaterializeAtom results)
     : base(headers, query, results)
 {
 }
Exemple #19
0
        internal bool Read()
        {
            if (this.DataKind == AtomDataKind.Finished)
            {
                return(false);
            }

            while (this.reader.Read())
            {
                if (ShouldIgnoreNode(this.reader))
                {
                    continue;
                }

                Debug.Assert(
                    this.reader.NodeType == XmlNodeType.Element || this.reader.NodeType == XmlNodeType.EndElement,
                    "this.reader.NodeType == XmlNodeType.Element || this.reader.NodeType == XmlNodeType.EndElement -- otherwise we should have ignored or thrown");

                AtomDataKind readerData = ParseStateForReader(this.reader);

                if (this.reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                switch (readerData)
                {
                case AtomDataKind.Custom:
                    if (this.DataKind == AtomDataKind.None)
                    {
                        this.kind = AtomDataKind.Custom;
                        return(true);
                    }
                    else
                    {
                        MaterializeAtom.SkipToEnd(this.reader);
                        continue;
                    }

                case AtomDataKind.Entry:
                    this.kind = AtomDataKind.Entry;
                    this.ParseCurrentEntry(out this.entry);
                    return(true);

                case AtomDataKind.Feed:
                    if (this.DataKind == AtomDataKind.None)
                    {
                        this.feed = new AtomFeed();
                        this.kind = AtomDataKind.Feed;
                        return(true);
                    }

                    throw new InvalidOperationException(Strings.AtomParser_FeedUnexpected);

                case AtomDataKind.FeedCount:
                    this.ParseCurrentFeedCount();
                    break;

                case AtomDataKind.PagingLinks:
                    if (this.feed == null)
                    {
                        throw new InvalidOperationException(Strings.AtomParser_PagingLinkOutsideOfFeed);
                    }

                    this.kind = AtomDataKind.PagingLinks;
                    this.ParseCurrentFeedPagingLinks();
                    return(true);

                default:
                    Debug.Assert(false, "Atom Parser is in a wrong state...Did you add a new AtomDataKind?");
                    break;
                }
            }

            this.kind  = AtomDataKind.Finished;
            this.entry = null;
            return(false);
        }
Exemple #20
0
        private MaterializeAtom ReadPropertyFromRawData(ClientPropertyAnnotation property)
        {
            DataServiceContext context = (DataServiceContext)this.Source;

            bool merging = context.ApplyingChanges;

            try
            {
                context.ApplyingChanges = true;

                // if this is the data property for a media entry, what comes back
                // is the raw value (no markup)
#if ASTORIA_OPEN_OBJECT
                object openProps = null;
#endif
                string   mimeType    = null;
                Encoding encoding    = null;
                Type     elementType = property.EntityCollectionItemType ?? property.NullablePropertyType;
                IList    results     = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType));
                ContentTypeUtil.ReadContentType(this.ContentType, out mimeType, out encoding);

                using (Stream responseStream = this.GetResponseStream())
                {
                    // special case byte[], and for everything else let std conversion kick-in
                    if (property.PropertyType == typeof(byte[]))
                    {
                        int    total  = checked ((int)this.ContentLength);
                        byte[] buffer = null;
                        if (total >= 0)
                        {
                            buffer = LoadPropertyResult.ReadByteArrayWithContentLength(responseStream, total);
                        }
                        else
                        {
                            buffer = LoadPropertyResult.ReadByteArrayChunked(responseStream);
                        }

                        results.Add(buffer);
#if ASTORIA_OPEN_OBJECT
                        property.SetValue(this.entity, buffer, this.propertyName, ref openProps, false);
#else
                        property.SetValue(this.entity, buffer, this.propertyName, false);
#endif
                    }
                    else
                    {
                        // responseStream will disposed, StreamReader doesn't need to dispose of it.
                        StreamReader reader         = new StreamReader(responseStream, encoding);
                        object       convertedValue = property.PropertyType == typeof(string) ?
                                                      reader.ReadToEnd() :
                                                      ClientConvert.ChangeType(reader.ReadToEnd(), property.PropertyType);
                        results.Add(convertedValue);
#if ASTORIA_OPEN_OBJECT
                        property.SetValue(this.entity, convertedValue, this.propertyName, ref openProps, false);
#else
                        property.SetValue(this.entity, convertedValue, this.propertyName, false);
#endif
                    }
                }

#if ASTORIA_OPEN_OBJECT
                Debug.Assert(openProps == null, "These should not be set in this path");
#endif
                if (property.MimeTypeProperty != null)
                {
                    // an implication of this 3rd-arg-null is that mime type properties cannot be open props
#if ASTORIA_OPEN_OBJECT
                    property.MimeTypeProperty.SetValue(this.entity, mimeType, null, ref openProps, false);
                    Debug.Assert(openProps == null, "These should not be set in this path");
#else
                    property.MimeTypeProperty.SetValue(this.entity, mimeType, null, false);
#endif
                }

                return(MaterializeAtom.CreateWrapper(context, results));
            }
            finally
            {
                context.ApplyingChanges = merging;
            }
        }
Exemple #21
0
        internal QueryOperationResponse <TElement> ProcessResult <TElement>(ProjectionPlan plan)
        {
            MaterializeAtom results = this.CreateMaterializer(plan, this.ServiceRequest.PayloadKind);

            return(this.GetResponse <TElement>(results));
        }
Exemple #22
0
        private MaterializeAtom ReadPropertyFromAtom(ClientPropertyAnnotation property)
        {
            DataServiceContext context = (DataServiceContext)this.Source;
            bool merging = context.ApplyingChanges;

            try
            {
                context.ApplyingChanges = true;

                // store the results so that they can be there in the response body.
                Type  elementType = property.IsEntityCollection ? property.EntityCollectionItemType : property.NullablePropertyType;
                IList results     = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType));

                DataServiceQueryContinuation continuation = null;

                // elementType.ElementType has Nullable stripped away, use nestedType for materializer
                using (MaterializeAtom materializer = this.GetMaterializer(this.plan))
                {
                    Debug.Assert(materializer != null, "materializer != null -- otherwise GetMaterializer() returned null rather than empty");

#if ASTORIA_OPEN_OBJECT
                    object openProperties = null;
#endif
                    foreach (object child in materializer)
                    {
                        if (property.IsEntityCollection)
                        {
                            results.Add(child);
                        }
                        else if (property.IsPrimitiveOrComplexCollection)
                        {
                            Debug.Assert(property.PropertyType.IsAssignableFrom(child.GetType()), "Created instance for storing collection items has to be compatible with the actual one.");

                            // Collection materialization rules requires to clear the collection if not null or set the property first and then add the collection items
                            object collectionInstance = property.GetValue(this.entity);
                            if (collectionInstance == null)
                            {
                                // type of child has been resolved as per rules for collections so it is the correct type to instantiate
                                collectionInstance = Activator.CreateInstance(child.GetType());

                                // allowAdd is false - we need to assign instance as the new property value
                                property.SetValue(this.entity, collectionInstance, this.propertyName, false /* allowAdd? */);
                            }
                            else
                            {
                                // Clear existing collection
                                property.ClearBackingICollectionInstance(collectionInstance);
                            }

                            foreach (var collectionItem in (IEnumerable)child)
                            {
                                Debug.Assert(property.PrimitiveOrComplexCollectionItemType.IsAssignableFrom(collectionItem.GetType()), "Type of materialized collection items have to be compatible with the type of collection items in the actual collection property.");
                                property.AddValueToBackingICollectionInstance(collectionInstance, collectionItem);
                            }

                            results.Add(collectionInstance);
                        }
                        else
                        {
#if ASTORIA_OPEN_OBJECT
                            property.SetValue(this.entity, child, this.propertyName, ref openProperties, false);
#else
                            // it is either primitive type, complex type or 1..1 navigation property so we just allow setting the value but not adding.
                            property.SetValue(this.entity, child, this.propertyName, false);
                            results.Add(child);
#endif
                        }
                    }

                    continuation = materializer.GetContinuation(null);
                }

                return(MaterializeAtom.CreateWrapper(context, results, continuation));
            }
            finally
            {
                context.ApplyingChanges = merging;
            }
        }
 internal static QueryOperationResponse GetInstance(Type elementType, Dictionary <string, string> headers, DataServiceRequest query, MaterializeAtom results)
 {
     return((QueryOperationResponse)Activator.CreateInstance(typeof(QueryOperationResponse <>).MakeGenericType(new Type[] { elementType }), BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { headers, query, results }, CultureInfo.InvariantCulture));
 }
Exemple #24
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;
        }
Exemple #25
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="headers">HTTP headers</param>
 /// <param name="query">original query</param>
 /// <param name="results">retrieved objects</param>
 internal QueryOperationResponse(HeaderCollection headers, DataServiceRequest query, MaterializeAtom results)
     : base(headers)
 {
     this.query   = query;
     this.results = results;
 }
        private MaterializeAtom ReadPropertyFromAtom(EntityDescriptor box, ClientPropertyAnnotation property)
        {
            MaterializeAtom    atom2;
            DataServiceContext source = (DataServiceContext)base.Source;
            bool applyingChanges      = source.ApplyingChanges;

            try
            {
                source.ApplyingChanges = true;
                bool   flag2           = EntityStates.Deleted == box.State;
                bool   instanceCreated = false;
                object instance        = null;
                if (property.IsEntityCollection)
                {
                    instance = this.GetCollectionInstance(property, out instanceCreated);
                }
                Type  type    = property.IsEntityCollection ? property.EntityCollectionItemType : property.NullablePropertyType;
                IList results = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type }));
                DataServiceQueryContinuation continuation = null;
                using (MaterializeAtom atom = base.GetMaterializer(this.plan))
                {
                    bool flag4 = property.EdmProperty.PropertyKind == EdmPropertyKind.Navigation;
                    int  num   = 0;
                    foreach (object obj3 in atom)
                    {
                        if (property.IsEntityCollection)
                        {
                            property.SetValue(instance, obj3, this.propertyName, true);
                            results.Add(obj3);
                        }
                        else if (property.IsPrimitiveOrComplexCollection)
                        {
                            object obj4 = property.GetValue(this.entity);
                            if (obj4 == null)
                            {
                                obj4 = Activator.CreateInstance(obj3.GetType());
                                property.SetValue(this.entity, obj4, this.propertyName, false);
                            }
                            else
                            {
                                property.ClearBackingICollectionInstance(obj4);
                            }
                            foreach (object obj5 in (IEnumerable)obj3)
                            {
                                property.AddValueToBackingICollectionInstance(obj4, obj5);
                            }
                            results.Add(obj4);
                        }
                        else
                        {
                            property.SetValue(this.entity, obj3, this.propertyName, false);
                            results.Add(obj3);
                        }
                        num++;
                        if (((obj3 != null) && (MergeOption.NoTracking != atom.MergeOptionValue)) && flag4)
                        {
                            if (flag2)
                            {
                                source.DeleteLink(this.entity, this.propertyName, obj3);
                            }
                            else
                            {
                                source.AttachLink(this.entity, this.propertyName, obj3, atom.MergeOptionValue);
                            }
                        }
                    }
                    continuation = atom.GetContinuation(null);
                    Util.SetNextLinkForCollection(property.IsEntityCollection ? instance : this.entity, continuation);
                }
                if (instanceCreated)
                {
                    property.SetValue(this.entity, instance, this.propertyName, false);
                }
                atom2 = MaterializeAtom.CreateWrapper(source, results, continuation);
            }
            finally
            {
                source.ApplyingChanges = applyingChanges;
            }
            return(atom2);
        }
Exemple #27
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));
        }
Exemple #28
0
        internal static QueryOperationResponse GetInstance(Type elementType, HeaderCollection headers, DataServiceRequest query, MaterializeAtom results)
        {
            Type genericType = typeof(QueryOperationResponse <>).MakeGenericType(elementType);

#if !ASTORIA_LIGHT && !PORTABLELIB
            return((QueryOperationResponse)Activator.CreateInstance(
                       genericType,
                       BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Instance,
                       null,
                       new object[] { headers, query, results },
                       System.Globalization.CultureInfo.InvariantCulture));
#else
            ConstructorInfo info = genericType.GetInstanceConstructors(false /*isPublic*/).Single();
            return((QueryOperationResponse)Util.ConstructorInvoke(info, new object[] { headers, query, results }));
#endif
        }