internal void WriteEntityReferenceLinks(ODataEntityReferenceLinks entityReferenceLinks) { base.WritePayloadStart(); base.XmlWriter.WriteStartElement(string.Empty, "links", base.MessageWriterSettings.WriterBehavior.ODataNamespace); base.XmlWriter.WriteAttributeString("xmlns", base.MessageWriterSettings.WriterBehavior.ODataNamespace); if (entityReferenceLinks.Count.HasValue) { base.WriteCount(entityReferenceLinks.Count.Value, true); } IEnumerable <ODataEntityReferenceLink> links = entityReferenceLinks.Links; if (links != null) { foreach (ODataEntityReferenceLink link in links) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(link); this.WriteEntityReferenceLink(link, false); } } if (entityReferenceLinks.NextPageLink != null) { string str = base.UriToUrlAttributeValue(entityReferenceLinks.NextPageLink); base.XmlWriter.WriteElementString(string.Empty, "next", base.MessageWriterSettings.WriterBehavior.ODataNamespace, str); } base.XmlWriter.WriteEndElement(); base.WritePayloadEnd(); }
/// <summary> /// Writes a set of links (Uris) in response to a $ref query; includes optional count and next-page-link information. /// </summary> /// <param name="entityReferenceLinks">The set of entity reference links to write out.</param> private void WriteEntityReferenceLinksImplementation(ODataEntityReferenceLinks entityReferenceLinks) { Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null"); bool wroteNextLink = false; // { this.JsonWriter.StartObjectScope(); // "@odata.context": ... this.WriteContextUriProperty(ODataPayloadKind.EntityReferenceLinks); if (entityReferenceLinks.Count.HasValue) { // We try to write the count property at the top of the payload if one is available. // "@odata.count": ... this.WriteCountAnnotation(entityReferenceLinks.Count.Value); } if (entityReferenceLinks.NextPageLink != null) { // We try to write the next link at the top of the payload if one is available. If not, we try again at the end. wroteNextLink = true; // "@odata.next": ... this.WriteNextLinkAnnotation(entityReferenceLinks.NextPageLink); } this.InstanceAnnotationWriter.WriteInstanceAnnotations(entityReferenceLinks.InstanceAnnotations); // "value": this.JsonWriter.WriteValuePropertyName(); // "[": this.JsonWriter.StartArrayScope(); IEnumerable <ODataEntityReferenceLink> entityReferenceLinksEnumerable = entityReferenceLinks.Links; if (entityReferenceLinksEnumerable != null) { foreach (ODataEntityReferenceLink entityReferenceLink in entityReferenceLinksEnumerable) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(entityReferenceLink); this.WriteEntityReferenceLinkImplementation(entityReferenceLink, /* isTopLevel */ false); } } // "]" this.JsonWriter.EndArrayScope(); if (!wroteNextLink && entityReferenceLinks.NextPageLink != null) { // "@odata.next": ... this.WriteNextLinkAnnotation(entityReferenceLinks.NextPageLink); } // "}" this.JsonWriter.EndObjectScope(); }
/// <summary> /// Writes a set of links (Uris) in response to a $links query; includes optional count and next-page-link information. /// </summary> /// <param name="entityReferenceLinks">The set of entity reference links to write out.</param> /// <param name="includeResultsWrapper">true if the 'results' wrapper should be included into the payload; otherwise false.</param> private void WriteEntityReferenceLinksImplementation(ODataEntityReferenceLinks entityReferenceLinks, bool includeResultsWrapper) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null"); if (includeResultsWrapper) { // { this.JsonWriter.StartObjectScope(); } if (entityReferenceLinks.Count.HasValue) { Debug.Assert(includeResultsWrapper, "Expected 'includeResultsWrapper' to be true if a count is specified."); this.JsonWriter.WriteName(JsonConstants.ODataCountName); this.JsonWriter.WriteValue(entityReferenceLinks.Count.Value); } if (includeResultsWrapper) { // "results": this.JsonWriter.WriteDataArrayName(); } this.JsonWriter.StartArrayScope(); IEnumerable <ODataEntityReferenceLink> entityReferenceLinksEnumerable = entityReferenceLinks.Links; if (entityReferenceLinksEnumerable != null) { foreach (ODataEntityReferenceLink entityReferenceLink in entityReferenceLinksEnumerable) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(entityReferenceLink); this.WriteEntityReferenceLinkImplementation(entityReferenceLink); } } this.JsonWriter.EndArrayScope(); if (entityReferenceLinks.NextPageLink != null) { // "__next": ... Debug.Assert(includeResultsWrapper, "Expected 'includeResultsWrapper' to be true if a next page link is specified."); this.JsonWriter.WriteName(JsonConstants.ODataNextLinkName); this.JsonWriter.WriteValue(this.UriToAbsoluteUriString(entityReferenceLinks.NextPageLink)); } if (includeResultsWrapper) { this.JsonWriter.EndObjectScope(); } }
/// <summary> /// Writes a set of links (Uris) in response to a $ref query; includes optional count and next-page-link information. /// </summary> /// <param name="entityReferenceLinks">The set of entity reference links to write out.</param> internal void WriteEntityReferenceLinks(ODataEntityReferenceLinks entityReferenceLinks) { Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null"); this.WritePayloadStart(); // COMPAT 25: Should $link payloads use the default 'd' namespace prefix for data service elements (instead of no prefix)? // <feed> ... this.XmlWriter.WriteStartElement(string.Empty, AtomConstants.AtomFeedElementName, AtomConstants.AtomNamespace); // xmlns:metadata= this.XmlWriter.WriteAttributeString(AtomConstants.XmlnsNamespacePrefix, AtomConstants.ODataMetadataNamespacePrefix, null, AtomConstants.ODataMetadataNamespace); // metadata:context this.WriteContextUriProperty(this.contextUriBuilder.BuildContextUri(ODataPayloadKind.EntityReferenceLinks)); if (entityReferenceLinks.Count.HasValue) { // <m:count> this.WriteCount(entityReferenceLinks.Count.Value); } IEnumerable <ODataEntityReferenceLink> entityReferenceLinkEnumerable = entityReferenceLinks.Links; if (entityReferenceLinkEnumerable != null) { foreach (ODataEntityReferenceLink entityReferenceLink in entityReferenceLinkEnumerable) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(entityReferenceLink); this.WriteEntityReferenceLink(entityReferenceLink, false); } } if (entityReferenceLinks.NextPageLink != null) { // <d:next> string nextLink = this.UriToUrlAttributeValue(entityReferenceLinks.NextPageLink); this.XmlWriter.WriteElementString(string.Empty, AtomConstants.ODataNextLinkElementName, AtomConstants.ODataNamespace, nextLink); } // </feed> this.XmlWriter.WriteEndElement(); this.WritePayloadEnd(); }
/// <summary> /// Writes a set of links (Uris) in response to a $links query; includes optional count and next-page-link information. /// </summary> /// <param name="entityReferenceLinks">The entity reference links to write.</param> internal void WriteEntityReferenceLinks(ODataEntityReferenceLinks entityReferenceLinks) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null"); this.WritePayloadStart(); // <links> ... this.XmlWriter.WriteStartElement(string.Empty, AtomConstants.ODataLinksElementName, this.MessageWriterSettings.WriterBehavior.ODataNamespace); // xmlns= this.XmlWriter.WriteAttributeString(AtomConstants.XmlnsNamespacePrefix, this.MessageWriterSettings.WriterBehavior.ODataNamespace); if (entityReferenceLinks.Count.HasValue) { // <m:count> this.WriteCount(entityReferenceLinks.Count.Value, true); } IEnumerable <ODataEntityReferenceLink> entityReferenceLinkEnumerable = entityReferenceLinks.Links; if (entityReferenceLinkEnumerable != null) { foreach (ODataEntityReferenceLink entityReferenceLink in entityReferenceLinkEnumerable) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(entityReferenceLink); this.WriteEntityReferenceLink(entityReferenceLink, false); } } if (entityReferenceLinks.NextPageLink != null) { // <d:next> string nextLink = this.UriToUrlAttributeValue(entityReferenceLinks.NextPageLink); this.XmlWriter.WriteElementString(string.Empty, AtomConstants.ODataNextLinkElementName, this.MessageWriterSettings.WriterBehavior.ODataNamespace, nextLink); } // </links> this.XmlWriter.WriteEndElement(); this.WritePayloadEnd(); }
private void WriteEntityReferenceLinksImplementation(ODataEntityReferenceLinks entityReferenceLinks, bool includeResultsWrapper) { if (includeResultsWrapper) { base.JsonWriter.StartObjectScope(); } if (entityReferenceLinks.Count.HasValue) { base.JsonWriter.WriteName("__count"); base.JsonWriter.WriteValue(entityReferenceLinks.Count.Value); } if (includeResultsWrapper) { base.JsonWriter.WriteDataArrayName(); } base.JsonWriter.StartArrayScope(); IEnumerable <ODataEntityReferenceLink> links = entityReferenceLinks.Links; if (links != null) { foreach (ODataEntityReferenceLink link in links) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(link); this.WriteEntityReferenceLinkImplementation(link); } } base.JsonWriter.EndArrayScope(); if (entityReferenceLinks.NextPageLink != null) { base.JsonWriter.WriteName("__next"); base.JsonWriter.WriteValue(base.UriToAbsoluteUriString(entityReferenceLinks.NextPageLink)); } if (includeResultsWrapper) { base.JsonWriter.EndObjectScope(); } }
/// <summary> /// Writes a set of links (Uris) in response to a $links query; includes optional count and next-page-link information. /// </summary> /// <param name="entityReferenceLinks">The set of entity reference links to write out.</param> /// <param name="entitySet">The entity set of the navigation property</param> /// <param name="navigationProperty">The navigation property for which the entity reference links are being written, or null if none is available.</param> private void WriteEntityReferenceLinksImplementation(ODataEntityReferenceLinks entityReferenceLinks, IEdmEntitySet entitySet, IEdmNavigationProperty navigationProperty) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null"); bool wroteNextLink = false; bool wroteCount = false; // { this.JsonWriter.StartObjectScope(); Uri metadataUri; if (this.metadataUriBuilder.TryBuildEntityReferenceLinksMetadataUri(entityReferenceLinks.SerializationInfo, entitySet, navigationProperty, out metadataUri)) { this.WriteMetadataUriProperty(metadataUri); } if (entityReferenceLinks.Count.HasValue) { // We try to write the count property at the top of the payload if one is available. If not, we try again at the end. wroteCount = true; // "odata.count": ... this.WriteCountAnnotation(entityReferenceLinks.Count.Value); } if (entityReferenceLinks.NextPageLink != null) { // We try to write the next link at the top of the payload if one is available. If not, we try again at the end. wroteNextLink = true; // "odata.next": ... this.WriteNextLinkAnnotation(entityReferenceLinks.NextPageLink); } // "value": this.JsonWriter.WriteValuePropertyName(); // "[": this.JsonWriter.StartArrayScope(); IEnumerable <ODataEntityReferenceLink> entityReferenceLinksEnumerable = entityReferenceLinks.Links; if (entityReferenceLinksEnumerable != null) { foreach (ODataEntityReferenceLink entityReferenceLink in entityReferenceLinksEnumerable) { WriterValidationUtils.ValidateEntityReferenceLinkNotNull(entityReferenceLink); this.WriteEntityReferenceLinkImplementation(entityReferenceLink, entitySet, /* navigationProperty */ null, /* isTopLevel */ false); } } // "]" this.JsonWriter.EndArrayScope(); if (!wroteCount && entityReferenceLinks.Count.HasValue) { // "odata.count": ... this.WriteCountAnnotation(entityReferenceLinks.Count.Value); } if (!wroteNextLink && entityReferenceLinks.NextPageLink != null) { // "odata.next": ... this.WriteNextLinkAnnotation(entityReferenceLinks.NextPageLink); } // "}" this.JsonWriter.EndObjectScope(); }