/// <summary>
        /// Write the metadata for an OData association link; makes sure any duplicate of the link's values duplicated in metadata are equal.
        /// </summary>
        /// <param name="associationLink">The association link for which to write the metadata.</param>
        /// <param name="owningType">The <see cref="IEdmEntityType"/> instance the association link is defined on.</param>
        /// <param name="duplicatePropertyNamesChecker">The checker instance for duplicate property names.</param>
        /// <param name="projectedProperties">Set of projected properties, or null if all properties should be written.</param>
        internal void WriteAssociationLink(
            ODataAssociationLink associationLink,
            IEdmEntityType owningType,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            ProjectedPropertiesAnnotation projectedProperties)
        {
            DebugUtils.CheckNoExternalCallers();

            ValidationUtils.ValidateAssociationLinkNotNull(associationLink);
            string associationLinkName = associationLink.Name;

            if (projectedProperties.ShouldSkipProperty(associationLinkName))
            {
                return;
            }

            this.ValidateAssociationLink(associationLink, owningType);
            duplicatePropertyNamesChecker.CheckForDuplicateAssociationLinkNames(associationLink);

            AtomLinkMetadata linkMetadata       = associationLink.GetAnnotation <AtomLinkMetadata>();
            string           linkRelation       = AtomUtils.ComputeODataAssociationLinkRelation(associationLink);
            AtomLinkMetadata mergedLinkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(linkMetadata, linkRelation, associationLink.Url, associationLinkName, MimeConstants.MimeApplicationXml);

            this.atomEntryMetadataSerializer.WriteAtomLink(mergedLinkMetadata, null /* etag*/);
        }
Exemple #2
0
        /// <summary>
        /// Writes the navigation link metadata.
        /// </summary>
        /// <param name="navigationLink">The navigation link to write the metadata for.</param>
        /// <param name="duplicatePropertyNamesChecker">The checker instance for duplicate property names.</param>
        internal void WriteNavigationLinkMetadata(ODataNavigationLink navigationLink, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(navigationLink != null, "navigationLink != null");
            Debug.Assert(!string.IsNullOrEmpty(navigationLink.Name), "The navigation link Name should have been validated by now.");
            Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");

            Uri    navigationLinkUrl  = navigationLink.Url;
            string navigationLinkName = navigationLink.Name;

            if (navigationLinkUrl != null)
            {
                // The navigation link URL is a property annotation "[email protected]: 'url'"
                this.JsonWriter.WritePropertyAnnotationName(navigationLinkName, ODataAnnotationNames.ODataNavigationLinkUrl);
                this.JsonWriter.WriteValue(this.UriToString(navigationLinkUrl));
            }

            Uri associationLinkUrl = navigationLink.AssociationLinkUrl;

            if (associationLinkUrl != null)
            {
                duplicatePropertyNamesChecker.CheckForDuplicateAssociationLinkNames(new ODataAssociationLink {
                    Name = navigationLinkName
                });
                this.WriteAssociationLink(navigationLink.Name, associationLinkUrl);
            }
        }
        /// <summary>
        /// Writes the metadata content for an association link
        /// </summary>
        /// <param name="associationLink">The association link to write.</param>
        /// <param name="duplicatePropertyNamesChecker">The checker instance for duplicate property names.</param>
        private void WriteAssociationLink(
            ODataAssociationLink associationLink,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
        {
            DebugUtils.CheckNoExternalCallers();

            duplicatePropertyNamesChecker.CheckForDuplicateAssociationLinkNames(associationLink);

            // Write the "LinkName": {
            this.JsonWriter.WriteName(associationLink.Name);
            this.JsonWriter.StartObjectScope();

            // Write the "associationuri": "url"
            this.JsonWriter.WriteName(JsonConstants.ODataMetadataPropertiesAssociationUriName);
            this.JsonWriter.WriteValue(this.UriToAbsoluteUriString(associationLink.Url));

            // Close the "LinkName" object
            this.JsonWriter.EndObjectScope();
        }
        /// <summary>
        /// Writes the navigation link metadata.
        /// </summary>
        /// <param name="navigationLink">The navigation link to write the metadata for.</param>
        /// <param name="duplicatePropertyNamesChecker">The checker instance for duplicate property names.</param>
        internal void WriteNavigationLinkMetadata(ODataNavigationLink navigationLink, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
        {
            Debug.Assert(navigationLink != null, "navigationLink != null");
            Debug.Assert(!string.IsNullOrEmpty(navigationLink.Name), "The navigation link Name should have been validated by now.");
            Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");

            Uri navigationLinkUrl = navigationLink.Url;
            string navigationLinkName = navigationLink.Name;
            Uri associationLinkUrl = navigationLink.AssociationLinkUrl;
            if (associationLinkUrl != null)
            {
                duplicatePropertyNamesChecker.CheckForDuplicateAssociationLinkNames(navigationLinkName, null);
                this.WriteAssociationLink(navigationLink.Name, associationLinkUrl);
            }

            if (navigationLinkUrl != null)
            {
                // The navigation link URL is a property annotation "[email protected]: 'url'"
                this.ODataAnnotationWriter.WritePropertyAnnotationName(navigationLinkName, ODataAnnotationNames.ODataNavigationLinkUrl);
                this.JsonWriter.WriteValue(this.UriToString(navigationLinkUrl));
            }
        }