Esempio n. 1
0
 internal static void ValidateAssociationLinkNotNull(ODataAssociationLink associationLink)
 {
     if (associationLink == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_EnumerableContainsANullItem("ODataEntry.AssociationLinks"));
     }
 }
Esempio n. 2
0
 internal static void ValidateAssociationLinkNotNull(ODataAssociationLink associationLink)
 {
     if (associationLink == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_EnumerableContainsANullItem("ODataEntry.AssociationLinks"));
     }
 }
        /// <summary>
        /// Check the <paramref name="associationLink"/> for duplicate property names in an entry or complex value.
        /// If not explicitly allowed throw when duplicate properties are detected.
        /// If duplicate properties are allowed see the comment on ODataWriterBehavior.AllowDuplicatePropertyNames
        /// or ODataReaderBehavior.AllowDuplicatePropertyNames for further details.
        /// </summary>
        /// <param name="associationLink">The association link to be checked.</param>
        internal void CheckForDuplicatePropertyNames(ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(associationLink != null, "associationLink != null");
#if DEBUG
            Debug.Assert(this.startNavigationLinkName == null, "CheckForDuplicatePropertyNamesOnNavigationLinkStart was followed by a CheckForDuplicatePropertyNames(ODataProperty).");
#endif

            string            propertyName = associationLink.Name;
            DuplicationRecord existingDuplicationRecord;
            if (!this.TryGetDuplicationRecord(propertyName, out existingDuplicationRecord))
            {
                this.propertyNameCache.Add(
                    propertyName,
                    new DuplicationRecord(DuplicationKind.NavigationProperty)
                {
                    AssociationLinkFound = true
                });
            }
            else
            {
                if (existingDuplicationRecord.DuplicationKind == DuplicationKind.NavigationProperty && !existingDuplicationRecord.AssociationLinkFound)
                {
                    // The only valid case for a duplication with association link is if the existing record is for a navigation property
                    // which doesn't have its association link yet.
                    // In this case just mark the navigation property as having found its association link.
                    existingDuplicationRecord.AssociationLinkFound = true;
                }
                else
                {
                    // In all other cases fail.
                    throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(propertyName));
                }
            }
        }
Esempio n. 4
0
 internal static void ValidateAssociationLink(ODataAssociationLink associationLink)
 {
     ValidateAssociationLinkName(associationLink.Name);
     if (associationLink.Url == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_AssociationLinkMustSpecifyUrl);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Adds an association link to an entry.
        /// </summary>
        /// <param name="entry">The entry to add the association link to.</param>
        /// <param name="associationLink">The association link to add.</param>
        internal static void AddAssociationLink(this ODataEntry entry, ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(associationLink != null, "associationLink != null");

            entry.AssociationLinks = entry.AssociationLinks.ConcatToReadOnlyEnumerable("AssociationLinks", associationLink);
        }
Esempio n. 6
0
 internal static void AddAssociationLinkToEntry(ODataEntry entry, ODataAssociationLink associationLink)
 {
     if (object.ReferenceEquals(entry.AssociationLinks, EmptyAssociationLinksList))
     {
         entry.AssociationLinks = new ReadOnlyEnumerable <ODataAssociationLink>();
     }
     GetSourceListOfEnumerable <ODataAssociationLink>(entry.AssociationLinks, "AssociationLinks").Add(associationLink);
 }
Esempio n. 7
0
 internal static void ValidateAssociationLink(ODataAssociationLink associationLink)
 {
     ValidateAssociationLinkName(associationLink.Name);
     if (associationLink.Url == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_AssociationLinkMustSpecifyUrl);
     }
 }
 private void WriteAssociationLink(ODataAssociationLink associationLink, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
 {
     duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
     base.JsonWriter.WriteName(associationLink.Name);
     base.JsonWriter.StartObjectScope();
     base.JsonWriter.WriteName("associationuri");
     base.JsonWriter.WriteValue(base.UriToAbsoluteUriString(associationLink.Url));
     base.JsonWriter.EndObjectScope();
 }
 internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version, bool writingResponse)
 {
     ODataVersionChecker.CheckAssociationLinks(version);
     if (!writingResponse)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_AssociationLinkInRequest(associationLink.Name));
     }
     ValidationUtils.ValidateAssociationLink(associationLink);
 }
Esempio n. 10
0
        /// <summary>
        /// Validates association link before writing.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        /// <param name="entryEntityType">The entity type of the entry the association link belongs to.</param>
        protected void ValidateAssociationLink(ODataAssociationLink associationLink, IEdmEntityType entryEntityType)
        {
            Debug.Assert(associationLink != null, "associationLink != null");

            WriterValidationUtils.ValidateAssociationLink(associationLink, this.Version, this.WritingResponse);

            // We don't need the returned IEdmProperty since it was already validated to be a navigation property.
            WriterValidationUtils.ValidateNavigationPropertyDefined(associationLink.Name, entryEntityType, this.outputContext.MessageWriterSettings.UndeclaredPropertyBehaviorKinds);
        }
Esempio n. 11
0
 internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version, bool writingResponse)
 {
     ODataVersionChecker.CheckAssociationLinks(version);
     if (!writingResponse)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_AssociationLinkInRequest(associationLink.Name));
     }
     ValidationUtils.ValidateAssociationLink(associationLink);
 }
Esempio n. 12
0
        /// <summary>
        /// Validates association link before writing.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        /// <param name="entryEntityType">The entity type of the entry the association link belongs to.</param>
        protected void ValidateAssociationLink(ODataAssociationLink associationLink, IEdmEntityType entryEntityType)
        {
            Debug.Assert(associationLink != null, "associationLink != null");

            WriterValidationUtils.ValidateAssociationLink(associationLink, this.Version, this.WritingResponse);

            // We don't need the returned IEdmProperty since it was already validated to be a navigation property.
            WriterValidationUtils.ValidateNavigationPropertyDefined(associationLink.Name, entryEntityType);
        }
Esempio n. 13
0
        /// <summary>
        /// Validates an <see cref="ODataAssociationLink"/> to ensure it's not null.
        /// </summary>
        /// <param name="associationLink">The association link to ensure it's not null.</param>
        internal static void ValidateAssociationLinkNotNull(ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();

            // null link can not appear in the enumeration
            if (associationLink == null)
            {
                throw new ODataException(Strings.ValidationUtils_EnumerableContainsANullItem("ODataEntry.AssociationLinks"));
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Adds an association link to an entry.
        /// </summary>
        /// <param name="entry">The entry to add the association link to.</param>
        /// <param name="associationLink">The association link to add.</param>
        internal static void AddAssociationLinkToEntry(ODataEntry entry, ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(associationLink != null, "associationLink != null");

            if (object.ReferenceEquals(entry.AssociationLinks, EmptyAssociationLinksList))
            {
                entry.AssociationLinks = new ReadOnlyEnumerable <ODataAssociationLink>();
            }

            ReaderUtils.GetSourceListOfEnumerable(entry.AssociationLinks, "AssociationLinks").Add(associationLink);
        }
 internal void WriteAssociationLink(ODataAssociationLink associationLink, IEdmEntityType owningType, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, ProjectedPropertiesAnnotation projectedProperties)
 {
     ValidationUtils.ValidateAssociationLinkNotNull(associationLink);
     if (!projectedProperties.ShouldSkipProperty(associationLink.Name))
     {
         base.ValidateAssociationLink(associationLink, owningType);
         duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
         AtomLinkMetadata annotation = associationLink.GetAnnotation<AtomLinkMetadata>();
         string relation = AtomUtils.ComputeODataAssociationLinkRelation(associationLink);
         AtomLinkMetadata linkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(annotation, relation, associationLink.Url, associationLink.Name, "application/xml");
         this.atomEntryMetadataSerializer.WriteAtomLink(linkMetadata, null);
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Validates an <see cref="ODataAssociationLink"/> to ensure all required information is specified and valid.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        internal static void ValidateAssociationLink(ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(associationLink != null, "associationLink != null");

            ValidateAssociationLinkName(associationLink.Name);

            // Association link must specify the Url
            if (associationLink.Url == null)
            {
                throw new ODataException(Strings.ValidationUtils_AssociationLinkMustSpecifyUrl);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Validates an <see cref="ODataAssociationLink"/> to ensure all required information is specified and valid.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        /// <param name="version">The version of the OData protocol used for checking.</param>
        /// <param name="writingResponse">true if we are writing a response; otherwise false.</param>
        internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version, bool writingResponse)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(associationLink != null, "associationLink != null");

            ODataVersionChecker.CheckAssociationLinks(version);

            if (!writingResponse)
            {
                throw new ODataException(Strings.WriterValidationUtils_AssociationLinkInRequest(associationLink.Name));
            }

            ValidationUtils.ValidateAssociationLink(associationLink);
        }
Esempio n. 18
0
        /// <summary>Checks that for duplicate association links and if there already is a navigation link with the same name
        /// sets the association link URL on that navigation link.</summary>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker for the current scope.</param>
        /// <param name="associationLink">The association link to be checked.</param>
        internal static void CheckForDuplicateAssociationLinkAndUpdateNavigationLink(
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
            Debug.Assert(associationLink != null, "associationLink != null");

            ODataNavigationLink navigationLink = duplicatePropertyNamesChecker.CheckForDuplicateAssociationLinkNames(associationLink);

            // We must not set the AssociationLinkUrl to null since that would disable templating on it, but we want templating to work if the association link was not in the payload.
            if (navigationLink != null && navigationLink.AssociationLinkUrl == null && associationLink.Url != null)
            {
                navigationLink.AssociationLinkUrl = associationLink.Url;
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Adds an association link to an entry.
        /// </summary>
        /// <param name="entry">The entry to get or create the association link for.</param>
        /// <param name="navigationProperty">The navigation property to get or create the association link for.</param>
        /// <returns>The association link that we either retrieved or created for the <paramref name="navigationProperty"/>.</returns>
        internal static ODataAssociationLink GetOrCreateAssociationLinkForNavigationProperty(ODataEntry entry, IEdmNavigationProperty navigationProperty)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(navigationProperty != null, "navigationProperty != null");

            ODataAssociationLink associationLink = entry.AssociationLinks.FirstOrDefault(al => al.Name == navigationProperty.Name);

            if (associationLink == null)
            {
                associationLink = new ODataAssociationLink {
                    Name = navigationProperty.Name
                };
                entry.AddAssociationLink(associationLink);
            }

            return(associationLink);
        }
 internal void CheckForDuplicatePropertyNames(ODataAssociationLink associationLink)
 {
     DuplicationRecord record;
     string name = associationLink.Name;
     if (!this.TryGetDuplicationRecord(name, out record))
     {
         DuplicationRecord record2 = new DuplicationRecord(DuplicationKind.NavigationProperty) {
             AssociationLinkFound = true
         };
         this.propertyNameCache.Add(name, record2);
     }
     else
     {
         if ((record.DuplicationKind != DuplicationKind.NavigationProperty) || record.AssociationLinkFound)
         {
             throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(name));
         }
         record.AssociationLinkFound = true;
     }
 }
        internal void CheckForDuplicatePropertyNames(ODataAssociationLink associationLink)
        {
            DuplicationRecord record;
            string            name = associationLink.Name;

            if (!this.TryGetDuplicationRecord(name, out record))
            {
                DuplicationRecord record2 = new DuplicationRecord(DuplicationKind.NavigationProperty)
                {
                    AssociationLinkFound = true
                };
                this.propertyNameCache.Add(name, record2);
            }
            else
            {
                if ((record.DuplicationKind != DuplicationKind.NavigationProperty) || record.AssociationLinkFound)
                {
                    throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(name));
                }
                record.AssociationLinkFound = true;
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Validates an <see cref="ODataAssociationLink"/> to ensure it's not null.
        /// </summary>
        /// <param name="associationLink">The association link to ensure it's not null.</param>
        internal static void ValidateAssociationLinkNotNull(ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();

            // null link can not appear in the enumeration
            if (associationLink == null)
            {
                throw new ODataException(Strings.ValidationUtils_EnumerableContainsANullItem("ODataEntry.AssociationLinks"));
            }
        }
        /// <summary>
        /// Read the property metadata for the properties of an entry being read.
        /// </summary>
        /// <param name="entryState">The entry state for the current reader.</param>
        /// <param name="metadataPropertiesFoundBitField">The bit fields with all the properties found in metadata value so far.</param>
        /// <remarks>
        /// Pre-Condition:  first node of the 'properties' property's value (we will throw if this is not a start object node)
        /// Post-Condition: JsonNodeType.Property:      the next metadata property
        ///                 JsonNodeType.EndObject:     the end-object node of the metadata object
        ///                 
        /// This method will not validate anything against the model because it will read the type name and thus it can't rely
        /// on knowing the actual type of the entry being read.
        /// </remarks>
        private void ReadPropertiesMetadataProperty(
            IODataJsonReaderEntryState entryState,
            ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField)
        {
            Debug.Assert(entryState != null, "entryState != null");

            if (!this.ReadingResponse || this.MessageReaderSettings.MaxProtocolVersion < ODataVersion.V3)
            {
                this.JsonReader.SkipValue();
                return;
            }

            ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(
                ref metadataPropertiesFoundBitField,
                ODataJsonReaderUtils.MetadataPropertyBitMask.Properties,
                JsonConstants.ODataMetadataPropertiesName);

            this.JsonReader.AssertBuffering();

            // make sure the 'properties' property value is an object
            if (this.JsonReader.NodeType != JsonNodeType.StartObject)
            {
                throw new ODataException(o.Strings.ODataJsonEntryAndFeedDeserializer_PropertyInEntryMustHaveObjectValue(JsonConstants.ODataMetadataPropertiesName, this.JsonReader.NodeType));
            }

            // read over the start-object node of the metadata object for 'properties'
            this.JsonReader.ReadStartObject();

            while (this.JsonReader.NodeType == JsonNodeType.Property)
            {
                string propertyName = this.JsonReader.ReadPropertyName();

                ValidationUtils.ValidateAssociationLinkName(propertyName);
                ReaderValidationUtils.ValidateNavigationPropertyDefined(propertyName, entryState.EntityType, this.MessageReaderSettings);

                // read the start-object node of the metadata for the current propertyName
                this.JsonReader.ReadStartObject();

                while (this.JsonReader.NodeType == JsonNodeType.Property)
                {
                    string innerPropertyName = this.JsonReader.ReadPropertyName();

                    // ignore all properties we don't understand
                    if (string.CompareOrdinal(innerPropertyName, JsonConstants.ODataMetadataPropertiesAssociationUriName) == 0)
                    {
                        string associationUrlString = this.JsonReader.ReadStringValue(JsonConstants.ODataMetadataPropertiesAssociationUriName);
                        ODataJsonReaderUtils.ValidateMetadataStringProperty(associationUrlString, JsonConstants.ODataMetadataPropertiesAssociationUriName);
                        ODataAssociationLink associationLink = new ODataAssociationLink
                        {
                            Name = propertyName,
                            Url = this.ProcessUriFromPayload(associationUrlString)
                        };

                        ValidationUtils.ValidateAssociationLink(associationLink);
                        entryState.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
                        ReaderUtils.AddAssociationLinkToEntry(entryState.Entry, associationLink);
                    }
                    else
                    {
                        // skip over all unknown properties and read the next property or 
                        // the end of the metadata for the current propertyName
                        this.JsonReader.SkipValue();
                    }
                }

                // read the end-object node of the metadata for the current propertyName
                this.JsonReader.ReadEndObject();
            }

            // read over the end-object node of the metadata object for 'properties'
            this.JsonReader.ReadEndObject();

            this.JsonReader.AssertBuffering();
            Debug.Assert(
                this.JsonReader.NodeType == JsonNodeType.Property || this.JsonReader.NodeType == JsonNodeType.EndObject,
                "Post-Condition: expected JsonNodeType.Property or JsonNodeType.EndObject");
        }
        /// <summary>
        /// Reads a an association link in atom:entry.
        /// </summary>
        /// <param name="entryState">The reader entry state for the entry being read.</param>
        /// <param name="linkRelation">The rel attribute value for the link, unescaped parsed URI.</param>
        /// <param name="linkHRef">The href attribute value for the link (or null if the href attribute was not present).</param>
        /// <returns>true, if the association link was read succesfully, false otherwise.</returns>
        /// <remarks>
        /// Pre-Condition:   XmlNodeType.Element atom:link  - The atom:link element to read.
        /// Post-Condition:  Any                            - The node after the atom:link element if the link was read by this method.
        ///                  XmlNodeType.Element atom:link  - The atom:link element to read if the link was not read by this method.
        /// </remarks>
        private bool TryReadAssociationLinkInEntry(IODataAtomReaderEntryState entryState, string linkRelation, string linkHRef)
        {
            Debug.Assert(entryState != null, "entryState != null");
            Debug.Assert(linkRelation != null, "linkRelation != null");
            this.XmlReader.AssertNotBuffering();
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomLinkElementName,
                "The XML reader must be on the atom:link element for this method to work.");

            string associationLinkName = AtomUtils.GetNameFromAtomLinkRelationAttribute(linkRelation, AtomConstants.ODataNavigationPropertiesAssociationLinkRelationPrefix);
            if (string.IsNullOrEmpty(associationLinkName) || !this.ReadingResponse || this.MessageReaderSettings.MaxProtocolVersion < ODataVersion.V3)
            {
                return false;
            }

            ReaderValidationUtils.ValidateNavigationPropertyDefined(associationLinkName, entryState.EntityType, this.MessageReaderSettings);

            // Get the type of the link
            string asssociationLinkType = this.XmlReader.GetAttribute(this.AtomTypeAttributeName, this.EmptyNamespace);

            if (asssociationLinkType != null &&
                !HttpUtils.CompareMediaTypeNames(asssociationLinkType, MimeConstants.MimeApplicationXml))
            {
                throw new ODataException(o.Strings.ODataAtomEntryAndFeedDeserializer_InvalidTypeAttributeOnAssociationLink(associationLinkName));
            }

            ODataAssociationLink associationLink = new ODataAssociationLink { Name = associationLinkName };

            // Allow null (we won't set the Url property) and empty (relative URL) values.
            if (linkHRef != null)
            {
                associationLink.Url = this.ProcessUriFromPayload(linkHRef, this.XmlReader.XmlBaseUri);
            }

            entryState.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
            ReaderUtils.AddAssociationLinkToEntry(entryState.Entry, associationLink);

            // Read and store ATOM link metadata (captures extra info like lang, title) if ATOM metadata reading is turned on.
            AtomLinkMetadata atomLinkMetadata = this.EntryMetadataDeserializer.ReadAtomLinkElementInEntryContent(linkRelation, linkHRef);
            if (atomLinkMetadata != null)
            {
                associationLink.SetAnnotation(atomLinkMetadata);
            }

            this.XmlReader.Skip();
            return true;
        }
        /// <summary>
        /// Check the <paramref name="associationLink"/> for duplicate property names in an entry or complex value.
        /// If not explicitly allowed throw when duplicate properties are detected.
        /// If duplicate properties are allowed see the comment on ODataWriterBehavior.AllowDuplicatePropertyNames  
        /// or ODataReaderBehavior.AllowDuplicatePropertyNames for further details.
        /// </summary>
        /// <param name="associationLink">The association link to be checked.</param>
        internal void CheckForDuplicatePropertyNames(ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(associationLink != null, "associationLink != null");
#if DEBUG
            Debug.Assert(this.startNavigationLinkName == null, "CheckForDuplicatePropertyNamesOnNavigationLinkStart was followed by a CheckForDuplicatePropertyNames(ODataProperty).");
#endif

            string propertyName = associationLink.Name;
            DuplicationRecord existingDuplicationRecord;
            if (!this.TryGetDuplicationRecord(propertyName, out existingDuplicationRecord))
            {
                this.propertyNameCache.Add(
                    propertyName,
                    new DuplicationRecord(DuplicationKind.NavigationProperty)
                    {
                        AssociationLinkFound = true
                    });
            }
            else
            {
                if (existingDuplicationRecord.DuplicationKind == DuplicationKind.NavigationProperty && !existingDuplicationRecord.AssociationLinkFound)
                {
                    // The only valid case for a duplication with association link is if the existing record is for a navigation property
                    // which doesn't have its association link yet.
                    // In this case just mark the navigation property as having found its association link.
                    existingDuplicationRecord.AssociationLinkFound = true;
                }
                else
                {
                    // In all other cases fail.
                    throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(propertyName));
                }
            }
        }
Esempio n. 26
0
 protected void ValidateAssociationLink(ODataAssociationLink associationLink, IEdmEntityType entryEntityType)
 {
     WriterValidationUtils.ValidateAssociationLink(associationLink, this.Version, this.WritingResponse);
     WriterValidationUtils.ValidateNavigationPropertyDefined(associationLink.Name, entryEntityType);
 }
 private void ReadPropertiesMetadataProperty(IODataJsonReaderEntryState entryState, ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField)
 {
     if (!base.ReadingResponse || (base.MessageReaderSettings.MaxProtocolVersion < ODataVersion.V3))
     {
         base.JsonReader.SkipValue();
     }
     else
     {
         ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.Properties, "properties");
         if (base.JsonReader.NodeType != JsonNodeType.StartObject)
         {
             throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_PropertyInEntryMustHaveObjectValue("properties", base.JsonReader.NodeType));
         }
         base.JsonReader.ReadStartObject();
         while (base.JsonReader.NodeType == JsonNodeType.Property)
         {
             string associationLinkName = base.JsonReader.ReadPropertyName();
             ValidationUtils.ValidateAssociationLinkName(associationLinkName);
             ReaderValidationUtils.ValidateNavigationPropertyDefined(associationLinkName, entryState.EntityType, base.MessageReaderSettings);
             base.JsonReader.ReadStartObject();
             while (base.JsonReader.NodeType == JsonNodeType.Property)
             {
                 if (string.CompareOrdinal(base.JsonReader.ReadPropertyName(), "associationuri") == 0)
                 {
                     string propertyValue = base.JsonReader.ReadStringValue("associationuri");
                     ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "associationuri");
                     ODataAssociationLink associationLink = new ODataAssociationLink {
                         Name = associationLinkName,
                         Url = base.ProcessUriFromPayload(propertyValue)
                     };
                     ValidationUtils.ValidateAssociationLink(associationLink);
                     entryState.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
                     ReaderUtils.AddAssociationLinkToEntry(entryState.Entry, associationLink);
                 }
                 else
                 {
                     base.JsonReader.SkipValue();
                 }
             }
             base.JsonReader.ReadEndObject();
         }
         base.JsonReader.ReadEndObject();
     }
 }
        /// <summary>
        /// Validates an <see cref="ODataAssociationLink"/> to ensure all required information is specified and valid.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        /// <param name="version">The version of the OData protocol used for checking.</param>
        /// <param name="writingResponse">true if we are writing a response; otherwise false.</param>
        internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version, bool writingResponse)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(associationLink != null, "associationLink != null");

            ODataVersionChecker.CheckAssociationLinks(version);

            if (!writingResponse)
            {
                throw new ODataException(Strings.WriterValidationUtils_AssociationLinkInRequest(associationLink.Name));
            }

            ValidationUtils.ValidateAssociationLink(associationLink);
        }
Esempio n. 29
0
        /// <summary>
        /// Validates an <see cref="ODataAssociationLink"/> to ensure all required information is specified and valid.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        internal static void ValidateAssociationLink(ODataAssociationLink associationLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(associationLink != null, "associationLink != null");

            ValidateAssociationLinkName(associationLink.Name);

            // Association link must specify the Url
            if (associationLink.Url == null)
            {
                throw new ODataException(Strings.ValidationUtils_AssociationLinkMustSpecifyUrl);
            }
        }
Esempio n. 30
0
 internal static string ComputeODataAssociationLinkRelation(ODataAssociationLink associationLink)
 {
     return string.Join("/", new string[] { "http://schemas.microsoft.com/ado/2007/08/dataservices", "relatedlinks", associationLink.Name });
 }
 private bool TryReadAssociationLinkInEntry(IODataAtomReaderEntryState entryState, string linkRelation, string linkHRef)
 {
     string nameFromAtomLinkRelationAttribute = AtomUtils.GetNameFromAtomLinkRelationAttribute(linkRelation, "http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/");
     if ((string.IsNullOrEmpty(nameFromAtomLinkRelationAttribute) || !base.ReadingResponse) || (base.MessageReaderSettings.MaxProtocolVersion < ODataVersion.V3))
     {
         return false;
     }
     ReaderValidationUtils.ValidateNavigationPropertyDefined(nameFromAtomLinkRelationAttribute, entryState.EntityType, base.MessageReaderSettings);
     string attribute = base.XmlReader.GetAttribute(base.AtomTypeAttributeName, base.EmptyNamespace);
     if ((attribute != null) && !HttpUtils.CompareMediaTypeNames(attribute, "application/xml"))
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomEntryAndFeedDeserializer_InvalidTypeAttributeOnAssociationLink(nameFromAtomLinkRelationAttribute));
     }
     ODataAssociationLink associationLink = new ODataAssociationLink {
         Name = nameFromAtomLinkRelationAttribute
     };
     if (linkHRef != null)
     {
         associationLink.Url = base.ProcessUriFromPayload(linkHRef, base.XmlReader.XmlBaseUri);
     }
     entryState.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
     ReaderUtils.AddAssociationLinkToEntry(entryState.Entry, associationLink);
     AtomLinkMetadata annotation = this.EntryMetadataDeserializer.ReadAtomLinkElementInEntryContent(linkRelation, linkHRef);
     if (annotation != null)
     {
         associationLink.SetAnnotation<AtomLinkMetadata>(annotation);
     }
     base.XmlReader.Skip();
     return true;
 }
Esempio n. 32
0
        /// <summary>
        /// Validates association link before writing.
        /// </summary>
        /// <param name="associationLink">The association link to validate.</param>
        /// <param name="entryEntityType">The entity type of the entry the association link belongs to.</param>
        protected void ValidateAssociationLink(ODataAssociationLink associationLink, IEdmEntityType entryEntityType)
        {
            Debug.Assert(associationLink != null, "associationLink != null");

            WriterValidationUtils.ValidateAssociationLink(associationLink, this.Version, this.WritingResponse);

            // We don't need the returned IEdmProperty since it was already validated to be a navigation property.
            WriterValidationUtils.ValidateNavigationPropertyDefined(associationLink.Name, entryEntityType);
        }
Esempio n. 33
0
 protected void ValidateAssociationLink(ODataAssociationLink associationLink, IEdmEntityType entryEntityType)
 {
     WriterValidationUtils.ValidateAssociationLink(associationLink, this.Version, this.WritingResponse);
     WriterValidationUtils.ValidateNavigationPropertyDefined(associationLink.Name, entryEntityType);
 }