Beispiel #1
0
        private void StartNavigationLink(ODataAtomReaderNavigationLinkDescriptor navigationLinkDescriptor)
        {
            IEdmEntityType expectedEntityType = null;

            if (navigationLinkDescriptor.NavigationProperty != null)
            {
                IEdmTypeReference type = navigationLinkDescriptor.NavigationProperty.Type;
                if (!type.IsCollection())
                {
                    if (navigationLinkDescriptor.NavigationLink.IsCollection == true)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomReader_FeedNavigationLinkForResourceReferenceProperty(navigationLinkDescriptor.NavigationLink.Name));
                    }
                    navigationLinkDescriptor.NavigationLink.IsCollection = false;
                    expectedEntityType = type.AsEntity().EntityDefinition();
                }
                else
                {
                    if (!navigationLinkDescriptor.NavigationLink.IsCollection.HasValue)
                    {
                        navigationLinkDescriptor.NavigationLink.IsCollection = true;
                    }
                    expectedEntityType = type.AsCollection().ElementType().AsEntity().EntityDefinition();
                }
            }
            this.EnterScope(ODataReaderState.NavigationLinkStart, navigationLinkDescriptor.NavigationLink, expectedEntityType);
            ((AtomScope)base.CurrentScope).NavigationProperty = navigationLinkDescriptor.NavigationProperty;
        }
Beispiel #2
0
 protected override bool ReadAtEntryStartImplementation()
 {
     if (base.CurrentEntry == null)
     {
         this.EndEntry();
     }
     else if ((this.atomEntryAndFeedDeserializer.XmlReader.NodeType == XmlNodeType.EndElement) || this.CurrentEntryState.EntryElementEmpty)
     {
         this.EndEntry();
     }
     else if (this.atomInputContext.UseServerApiBehavior)
     {
         ODataAtomReaderNavigationLinkDescriptor navigationLinkDescriptor = this.atomEntryAndFeedDeserializer.ReadEntryContent(this.CurrentEntryState);
         if (navigationLinkDescriptor == null)
         {
             this.EndEntry();
         }
         else
         {
             this.StartNavigationLink(navigationLinkDescriptor);
         }
     }
     else
     {
         this.StartNavigationLink(this.CurrentEntryState.FirstNavigationLinkDescriptor);
     }
     return(true);
 }
Beispiel #3
0
        protected override bool ReadAtNavigationLinkEndImplementation()
        {
            this.atomEntryAndFeedDeserializer.ReadNavigationLinkEnd();
            base.PopScope(ODataReaderState.NavigationLinkEnd);
            ODataAtomReaderNavigationLinkDescriptor navigationLinkDescriptor = this.atomEntryAndFeedDeserializer.ReadEntryContent(this.CurrentEntryState);

            if (navigationLinkDescriptor == null)
            {
                this.EndEntry();
            }
            else
            {
                this.StartNavigationLink(navigationLinkDescriptor);
            }
            return(true);
        }
Beispiel #4
0
 private void StartNavigationLink(ODataAtomReaderNavigationLinkDescriptor navigationLinkDescriptor)
 {
     IEdmEntityType expectedEntityType = null;
     if (navigationLinkDescriptor.NavigationProperty != null)
     {
         IEdmTypeReference type = navigationLinkDescriptor.NavigationProperty.Type;
         if (!type.IsCollection())
         {
             if (navigationLinkDescriptor.NavigationLink.IsCollection == true)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomReader_FeedNavigationLinkForResourceReferenceProperty(navigationLinkDescriptor.NavigationLink.Name));
             }
             navigationLinkDescriptor.NavigationLink.IsCollection = false;
             expectedEntityType = type.AsEntity().EntityDefinition();
         }
         else
         {
             if (!navigationLinkDescriptor.NavigationLink.IsCollection.HasValue)
             {
                 navigationLinkDescriptor.NavigationLink.IsCollection = true;
             }
             expectedEntityType = type.AsCollection().ElementType().AsEntity().EntityDefinition();
         }
     }
     this.EnterScope(ODataReaderState.NavigationLinkStart, navigationLinkDescriptor.NavigationLink, expectedEntityType);
     ((AtomScope) base.CurrentScope).NavigationProperty = navigationLinkDescriptor.NavigationProperty;
 }
        /// <summary>
        /// Starts the navigation link.
        /// Does metadata validation of the navigation link and sets up the reader to report it.
        /// </summary>
        /// <param name="navigationLinkDescriptor">The navigation link descriptor for the navigation link to start.</param>
        private void StartNavigationLink(ODataAtomReaderNavigationLinkDescriptor navigationLinkDescriptor)
        {
            Debug.Assert(navigationLinkDescriptor != null, "navigationLink != null");
            Debug.Assert(!string.IsNullOrEmpty(navigationLinkDescriptor.NavigationLink.Name), "Found navigation link without a name, or with empty name.");
            Debug.Assert(
                navigationLinkDescriptor.NavigationProperty == null || navigationLinkDescriptor.NavigationLink.Name == navigationLinkDescriptor.NavigationProperty.Name, 
                "The navigation link doesn't match the navigation property.");
            Debug.Assert(
                navigationLinkDescriptor.NavigationProperty != null || !this.atomInputContext.Model.IsUserModel() ||
                this.atomInputContext.MessageReaderSettings.UndeclaredPropertyBehaviorKinds.HasFlag(ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty),
                "We don't support open navigation links yet, so either we must not have a model or the reading of undeclared nav. props needs to be allowed.");
            this.atomEntryAndFeedDeserializer.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.atomEntryAndFeedDeserializer.XmlReader.LocalName == AtomConstants.AtomLinkElementName &&
                this.atomEntryAndFeedDeserializer.XmlReader.NamespaceURI == AtomConstants.AtomNamespace,
                "The reader must be on atom:link element.");

            IEdmEntityType targetEntityType = null;
            if (navigationLinkDescriptor.NavigationProperty != null)
            {
                IEdmTypeReference navigationPropertyType = navigationLinkDescriptor.NavigationProperty.Type;
                if (!navigationPropertyType.IsCollection())
                {
                    if (navigationLinkDescriptor.NavigationLink.IsCollection == true)
                    {
                        throw new ODataException(o.Strings.ODataAtomReader_FeedNavigationLinkForResourceReferenceProperty(navigationLinkDescriptor.NavigationLink.Name));
                    }

                    // Set it to false, it's either already set, or it's null.
                    navigationLinkDescriptor.NavigationLink.IsCollection = false;

                    targetEntityType = navigationPropertyType.AsEntity().EntityDefinition();
                }
                else
                {
                    if (!navigationLinkDescriptor.NavigationLink.IsCollection.HasValue)
                    {
                        // Only set collection to true if it was not set already. We need the payload to win so that we can later validate
                        // that if the link is expanded, the expansion is a feed.
                        navigationLinkDescriptor.NavigationLink.IsCollection = true;
                    }

                    targetEntityType = navigationPropertyType.AsCollection().ElementType().AsEntity().EntityDefinition();
                }
            }

            this.EnterScope(ODataReaderState.NavigationLinkStart, navigationLinkDescriptor.NavigationLink, targetEntityType);
            
            // Store a reference to the navigation property in the scope, so that we could validate cardinality of the link when reading it.
            ((AtomScope)this.CurrentScope).NavigationProperty = navigationLinkDescriptor.NavigationProperty;
        }