/// <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*/); }
/// <summary> /// Writes a stream property to the ATOM payload /// </summary> /// <param name="streamProperty">The stream property to create the payload for.</param> /// <param name="owningType">The <see cref="IEdmEntityType"/> instance for which the stream property 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 WriteStreamProperty( ODataProperty streamProperty, IEdmEntityType owningType, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, ProjectedPropertiesAnnotation projectedProperties) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(streamProperty != null, "Stream property must not be null."); Debug.Assert(streamProperty.Value != null, "The media resource of the stream property must not be null."); WriterValidationUtils.ValidatePropertyNotNull(streamProperty); string propertyName = streamProperty.Name; if (projectedProperties.ShouldSkipProperty(propertyName)) { return; } WriterValidationUtils.ValidatePropertyName(propertyName); duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(streamProperty); IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(streamProperty.Name, owningType, this.MessageWriterSettings.UndeclaredPropertyBehaviorKinds); WriterValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty, this.Version, this.WritingResponse); ODataStreamReferenceValue streamReferenceValue = (ODataStreamReferenceValue)streamProperty.Value; WriterValidationUtils.ValidateStreamReferenceValue(streamReferenceValue, false /*isDefaultStream*/); if (owningType != null && owningType.IsOpen && edmProperty == null) { ValidationUtils.ValidateOpenPropertyValue(streamProperty.Name, streamReferenceValue, this.MessageWriterSettings.UndeclaredPropertyBehaviorKinds); } AtomStreamReferenceMetadata streamReferenceMetadata = streamReferenceValue.GetAnnotation <AtomStreamReferenceMetadata>(); string contentType = streamReferenceValue.ContentType; string linkTitle = streamProperty.Name; Uri readLink = streamReferenceValue.ReadLink; if (readLink != null) { string readLinkRelation = AtomUtils.ComputeStreamPropertyRelation(streamProperty, false); AtomLinkMetadata readLinkMetadata = streamReferenceMetadata == null ? null : streamReferenceMetadata.SelfLink; AtomLinkMetadata mergedMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(readLinkMetadata, readLinkRelation, readLink, linkTitle, contentType); this.atomEntryMetadataSerializer.WriteAtomLink(mergedMetadata, null /* etag */); } Uri editLink = streamReferenceValue.EditLink; if (editLink != null) { string editLinkRelation = AtomUtils.ComputeStreamPropertyRelation(streamProperty, true); AtomLinkMetadata editLinkMetadata = streamReferenceMetadata == null ? null : streamReferenceMetadata.EditLink; AtomLinkMetadata mergedMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(editLinkMetadata, editLinkRelation, editLink, linkTitle, contentType); this.atomEntryMetadataSerializer.WriteAtomLink(mergedMetadata, streamReferenceValue.ETag); } }
internal void WriteNavigationLinkStart(ODataNavigationLink navigationLink, Uri navigationLinkUrlOverride) { base.XmlWriter.WriteStartElement("", "link", "http://www.w3.org/2005/Atom"); string relation = AtomUtils.ComputeODataNavigationLinkRelation(navigationLink); string mediaType = AtomUtils.ComputeODataNavigationLinkType(navigationLink); string name = navigationLink.Name; Uri href = navigationLinkUrlOverride ?? navigationLink.Url; AtomLinkMetadata linkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(navigationLink.GetAnnotation <AtomLinkMetadata>(), relation, href, name, mediaType); this.atomEntryMetadataSerializer.WriteAtomLinkAttributes(linkMetadata, null); }
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); } }
/// <summary> /// Writes the navigation link's start element and atom metadata. /// </summary> /// <param name="navigationLink">The navigation link to write.</param> /// <param name="navigationLinkUrlOverride">Url to use for the navigation link. If this is specified the Url property on the <paramref name="navigationLink"/> /// will be ignored. If this parameter is null, the Url from the navigation link is used.</param> internal void WriteNavigationLinkStart(ODataNavigationLink navigationLink, Uri navigationLinkUrlOverride) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(navigationLink != null, "navigationLink != null"); Debug.Assert(!string.IsNullOrEmpty(navigationLink.Name), "The navigation link name was not verified yet."); Debug.Assert(navigationLink.Url != null, "The navigation link Url was not verified yet."); Debug.Assert(navigationLink.IsCollection.HasValue, "navigationLink.IsCollection.HasValue"); // <atom:link> this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomLinkElementName, AtomConstants.AtomNamespace); string linkRelation = AtomUtils.ComputeODataNavigationLinkRelation(navigationLink); string linkType = AtomUtils.ComputeODataNavigationLinkType(navigationLink); string linkTitle = navigationLink.Name; Uri navigationLinkUrl = navigationLinkUrlOverride ?? navigationLink.Url; AtomLinkMetadata linkMetadata = navigationLink.GetAnnotation <AtomLinkMetadata>(); AtomLinkMetadata mergedMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(linkMetadata, linkRelation, navigationLinkUrl, linkTitle, linkType); this.atomEntryMetadataSerializer.WriteAtomLinkAttributes(mergedMetadata, null /* etag */); }
internal void WriteStreamProperty(ODataProperty streamProperty, IEdmEntityType owningType, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, ProjectedPropertiesAnnotation projectedProperties) { WriterValidationUtils.ValidatePropertyNotNull(streamProperty); string name = streamProperty.Name; if (!projectedProperties.ShouldSkipProperty(name)) { WriterValidationUtils.ValidateProperty(streamProperty); duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(streamProperty); IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(streamProperty.Name, owningType); WriterValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty, base.Version, base.WritingResponse); ODataStreamReferenceValue value2 = (ODataStreamReferenceValue)streamProperty.Value; if (((owningType != null) && owningType.IsOpen) && (edmProperty == null)) { ValidationUtils.ValidateOpenPropertyValue(streamProperty.Name, value2); } AtomStreamReferenceMetadata annotation = value2.GetAnnotation <AtomStreamReferenceMetadata>(); string contentType = value2.ContentType; string title = streamProperty.Name; Uri readLink = value2.ReadLink; if (readLink != null) { string relation = AtomUtils.ComputeStreamPropertyRelation(streamProperty, false); AtomLinkMetadata metadata = (annotation == null) ? null : annotation.SelfLink; AtomLinkMetadata linkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(metadata, relation, readLink, title, contentType); this.atomEntryMetadataSerializer.WriteAtomLink(linkMetadata, null); } Uri editLink = value2.EditLink; if (editLink != null) { string str5 = AtomUtils.ComputeStreamPropertyRelation(streamProperty, true); AtomLinkMetadata metadata4 = (annotation == null) ? null : annotation.EditLink; AtomLinkMetadata metadata5 = ODataAtomWriterMetadataUtils.MergeLinkMetadata(metadata4, str5, editLink, title, contentType); this.atomEntryMetadataSerializer.WriteAtomLink(metadata5, value2.ETag); } } }