Exemplo n.º 1
0
        /// <summary>
        /// Creates the materializer link with a resource set.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="resourceSet">The resource set.</param>
        /// <returns>The materializer link.</returns>
        public static MaterializerNavigationLink CreateLink(ODataNestedResourceInfo link, ODataResourceSet resourceSet)
        {
            Debug.Assert(link.GetAnnotation <MaterializerNavigationLink>() == null, "there should be no MaterializerNestedResourceInfo annotation on the feed link yet");
            MaterializerNavigationLink materializedNestedResourceInfo = new MaterializerNavigationLink(link, resourceSet);

            link.SetAnnotation <MaterializerNavigationLink>(materializedNestedResourceInfo);
            return(materializedNestedResourceInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes an ODataNestedResourceInfo instance for the deferred link payload.
        /// </summary>
        /// <param name="payloadElement">The deferred link to process.</param>
        public override void Visit(DeferredLink payloadElement)
        {
            if (this.items.Peek() is ODataNestedResourceInfo)
            {
                ODataNestedResourceInfo navigationLink = (ODataNestedResourceInfo)this.items.Pop();
                navigationLink.Url = new Uri(payloadElement.UriString);

                var contentType = payloadElement.Annotations.Where(a => a is ContentTypeAnnotation).SingleOrDefault();
                if (contentType != null)
                {
                    navigationLink.IsCollection = contentType.StringRepresentation.Contains("feed");
                }

                var entry = (ODataResource)this.items.Peek();

                var annotation = entry.GetAnnotation <ODataEntryNavigationLinksObjectModelAnnotation>();
                if (annotation == null)
                {
                    annotation = new ODataEntryNavigationLinksObjectModelAnnotation();
                    entry.SetAnnotation <ODataEntryNavigationLinksObjectModelAnnotation>(annotation);
                }

                annotation.Add(navigationLink, this.currentPropertyPosition);

                this.items.Push(navigationLink);

                if (!this.response)
                {
                    navigationLink.SetAnnotation(new ODataNavigationLinkExpandedItemObjectModelAnnotation()
                    {
                        ExpandedItem = new ODataEntityReferenceLink()
                        {
                            Url = navigationLink.Url
                        }
                    });
                }

                base.Visit(payloadElement);
                this.currentPropertyPosition++;
            }
            else
            {
                this.items.Push(new ODataEntityReferenceLink()
                {
                    Url = new Uri(payloadElement.UriString)
                });
            }
        }
        public void UpdateSingletonComplexProperty()
        {
            ODataResource complex0 = new ODataResource()
            {
                TypeName   = NameSpacePrefix + "Address",
                Properties = new[]
                {
                    new ODataProperty()
                    {
                        Name = "Street", Value = "1 Microsoft Way"
                    },
                    new ODataProperty()
                    {
                        Name = "City", Value = "London"
                    },
                    new ODataProperty()
                    {
                        Name = "PostalCode", Value = "98052"
                    }
                }
            };

            ODataNestedResourceInfo homeAddress0 = new ODataNestedResourceInfo()
            {
                Name = "HomeAddress", IsCollection = false
            };

            homeAddress0.SetAnnotation(complex0);

            ODataResource complex1 = new ODataResource()
            {
                TypeName   = NameSpacePrefix + "Address",
                Properties = new[]
                {
                    new ODataProperty()
                    {
                        Name = "Street", Value = "Zixing 999"
                    },
                    new ODataProperty()
                    {
                        Name = "City", Value = "Seattle"
                    },
                    new ODataProperty()
                    {
                        Name = "PostalCode", Value = "1111"
                    }
                }
            };
            ODataNestedResourceInfo homeAddress1 = new ODataNestedResourceInfo()
            {
                Name = "HomeAddress", IsCollection = false
            };

            homeAddress1.SetAnnotation(complex1);

            for (int i = 0; i < mimeTypes.Length; i++)
            {
                ODataResource currentHomeAddress;
                ODataResource updatedHomeAddress;

                object[] properties;
                if (i % 2 == 0)
                {
                    currentHomeAddress = complex0;
                    updatedHomeAddress = complex1;
                    properties         = new[] { homeAddress1 };
                }
                else
                {
                    currentHomeAddress = complex1;
                    updatedHomeAddress = complex0;
                    properties         = new[] { homeAddress0 };
                }
                List <ODataResource> entries = this.QueryEntry("VipCustomer", mimeTypes[i]);
                if (!mimeTypes[i].Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    ODataValueAssertEqualHelper.AssertODataPropertyAndResourceEqual(currentHomeAddress, entries[0]);
                }

                this.UpdateEntry("Customer", "VipCustomer", mimeTypes[i], properties);

                List <ODataResource> updatedentries = this.QueryEntry("VipCustomer", mimeTypes[i]);
                if (!mimeTypes[i].Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    ODataValueAssertEqualHelper.AssertODataPropertyAndResourceEqual(updatedHomeAddress, updatedentries[0]);
                }
            }
        }
Exemplo n.º 4
0
        private void Read(Lazy <ODataReader> lazyReader)
        {
            foreach (var state in this.expectedStates)
            {
                lazyReader.Value.Read();
                ExceptionUtilities.Assert(lazyReader.Value.State == state, "Expected %1, Found %2", state, lazyReader.Value.State);
                switch (state)
                {
                case ODataReaderState.ResourceSetStart:
                    if (readItems.Count > 0)
                    {
                        ODataNestedResourceInfo navLink = (ODataNestedResourceInfo)readItems.Peek();
                        var annotation = navLink.GetAnnotation <ODataNavigationLinkExpandedItemObjectModelAnnotation>();
                        if (annotation == null)
                        {
                            annotation = new ODataNavigationLinkExpandedItemObjectModelAnnotation();
                            navLink.SetAnnotation(annotation);
                        }

                        annotation.ExpandedItem = lazyReader.Value.Item;
                    }

                    readItems.Push(lazyReader.Value.Item);
                    break;

                case ODataReaderState.ResourceStart:
                    var currentEntry = (ODataResource)lazyReader.Value.Item;
                    if (readItems.Count > 0)
                    {
                        ODataResourceSet feed = readItems.Peek() as ODataResourceSet;
                        if (feed != null)
                        {
                            var annotation = feed.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>();
                            if (annotation == null)
                            {
                                annotation = new ODataFeedEntriesObjectModelAnnotation();
                                feed.SetAnnotation(annotation);
                            }
                            annotation.Add((ODataResource)lazyReader.Value.Item);
                        }
                        else
                        {
                            ODataNestedResourceInfo navLink = (ODataNestedResourceInfo)readItems.Peek();
                            var annotation = navLink.GetAnnotation <ODataNavigationLinkExpandedItemObjectModelAnnotation>();
                            if (annotation == null)
                            {
                                annotation = new ODataNavigationLinkExpandedItemObjectModelAnnotation();
                                navLink.SetAnnotation(annotation);
                            }

                            annotation.ExpandedItem = currentEntry;
                        }
                    }

                    readItems.Push(currentEntry);
                    break;

                case ODataReaderState.NestedResourceInfoStart:
                    ODataResource entry = (ODataResource)readItems.Peek();
                    var           navLinksAnnotation = entry.GetAnnotation <ODataEntryNavigationLinksObjectModelAnnotation>();
                    if (navLinksAnnotation == null)
                    {
                        navLinksAnnotation = new ODataEntryNavigationLinksObjectModelAnnotation();
                        entry.SetAnnotation(navLinksAnnotation);
                    }

                    navLinksAnnotation.Add((ODataNestedResourceInfo)lazyReader.Value.Item, entry.Properties.Count() + navLinksAnnotation.Count);
                    readItems.Push(lazyReader.Value.Item);
                    break;

                case ODataReaderState.ResourceEnd:
                case ODataReaderState.ResourceSetEnd:
                case ODataReaderState.NestedResourceInfoEnd:
                    if (readItems.Count() > 1)
                    {
                        readItems.Pop();
                    }
                    break;
                }
            }

            this.expectedStates.Clear();
        }