/// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="entityReferenceLink">The entity reference link to write out.</param>
        /// <param name="isTopLevel">
        /// A flag indicating whether the link is written as top-level element or not;
        /// this controls whether to include namespace declarations etc.
        /// </param>
        private void WriteEntityReferenceLink(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel)
        {
            Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null");

            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);

            // For backward compatibility with WCF DS, the client needs to write the top-level uri element in the metadata namespace.
            string uriElementNamespaceUri = (this.UseClientFormatBehavior && isTopLevel)
                ? AtomConstants.ODataMetadataNamespace
                : this.MessageWriterSettings.WriterBehavior.ODataNamespace;

            // <uri ...
            this.XmlWriter.WriteStartElement(string.Empty, AtomConstants.ODataUriElementName, uriElementNamespaceUri);

            if (isTopLevel)
            {
                // xmlns=
                this.XmlWriter.WriteAttributeString(AtomConstants.XmlnsNamespacePrefix, uriElementNamespaceUri);
            }

            this.XmlWriter.WriteString(this.UriToUrlAttributeValue(entityReferenceLink.Url));

            // </uri>
            this.XmlWriter.WriteEndElement();
        }
示例#2
0
        /// <summary>
        /// Writes a single Uri in response to a $ref query.
        /// </summary>
        /// <param name="entityReferenceLink">The entity reference link to write out.</param>
        /// <param name="isTopLevel">
        /// A flag indicating whether the link is written as top-level element or not;
        /// this controls whether to include namespace declarations etc.
        /// </param>
        private void WriteEntityReferenceLink(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel)
        {
            Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null");

            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);

            if (isTopLevel)
            {
                // <metadata:ref ...
                this.XmlWriter.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataRefElementName, AtomConstants.ODataMetadataNamespace);

                // metadata:context
                this.WriteContextUriProperty(this.contextUriBuilder.BuildContextUri(ODataPayloadKind.EntityReferenceLink));
            }
            else
            {
                // <metadata:ref ...
                this.XmlWriter.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataRefElementName, null);
            }

            this.XmlWriter.WriteAttributeString(AtomConstants.AtomIdElementName, null, this.UriToUrlAttributeValue(entityReferenceLink.Url));

            // </uri>
            this.XmlWriter.WriteEndElement();
        }
        /// <summary>
        /// Asynchronously writes a single Uri in response to a $ref query.
        /// </summary>
        /// <param name="entityReferenceLink">The entity reference link to write out.</param>
        /// <param name="isTopLevel">true if the entity reference link being written is at the top level of the payload.</param>
        private async Task WriteEntityReferenceLinkImplementationAsync(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel)
        {
            Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null");

            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);

            await this.AsynchronousJsonWriter.StartObjectScopeAsync()
            .ConfigureAwait(false);

            if (isTopLevel)
            {
                await this.WriteContextUriPropertyAsync(ODataPayloadKind.EntityReferenceLink)
                .ConfigureAwait(false);
            }

            await this.AsynchronousODataAnnotationWriter.WriteInstanceAnnotationNameAsync(ODataAnnotationNames.ODataId)
            .ConfigureAwait(false);

            await this.AsynchronousJsonWriter.WriteValueAsync(this.UriToString(entityReferenceLink.Url))
            .ConfigureAwait(false);

            await this.InstanceAnnotationWriter.WriteInstanceAnnotationsAsync(entityReferenceLink.InstanceAnnotations)
            .ConfigureAwait(false);

            await this.AsynchronousJsonWriter.EndObjectScopeAsync()
            .ConfigureAwait(false);
        }
示例#4
0
 private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink entityReferenceLink)
 {
     WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);
     base.JsonWriter.StartObjectScope();
     base.JsonWriter.WriteName("uri");
     base.JsonWriter.WriteValue(base.UriToAbsoluteUriString(entityReferenceLink.Url));
     base.JsonWriter.EndObjectScope();
 }
        /// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="entityReferenceLink">The entity reference link to write out.</param>
        private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink entityReferenceLink)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null");

            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);

            this.JsonWriter.StartObjectScope();
            this.JsonWriter.WriteName(JsonConstants.ODataUriName);
            this.JsonWriter.WriteValue(this.UriToAbsoluteUriString(entityReferenceLink.Url));
            this.JsonWriter.EndObjectScope();
        }
        private void WriteEntityReferenceLink(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel)
        {
            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);
            string ns = (base.UseClientFormatBehavior && isTopLevel) ? "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" : base.MessageWriterSettings.WriterBehavior.ODataNamespace;

            base.XmlWriter.WriteStartElement(string.Empty, "uri", ns);
            if (isTopLevel)
            {
                base.XmlWriter.WriteAttributeString("xmlns", ns);
            }
            base.XmlWriter.WriteString(base.UriToUrlAttributeValue(entityReferenceLink.Url));
            base.XmlWriter.WriteEndElement();
        }
示例#7
0
        /// <summary>
        /// Writes a single Uri in response to a $ref query.
        /// </summary>
        /// <param name="entityReferenceLink">The entity reference link to write out.</param>
        /// <param name="isTopLevel">true if the entity reference link being written is at the top level of the payload.</param>
        private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel)
        {
            Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null");

            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);

            this.JsonWriter.StartObjectScope();

            if (isTopLevel)
            {
                this.WriteContextUriProperty(ODataPayloadKind.EntityReferenceLink);
            }

            this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataId);
            this.JsonWriter.WriteValue(this.UriToString(entityReferenceLink.Url));
            this.JsonWriter.EndObjectScope();
        }
示例#8
0
        /// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="entityReferenceLink">The entity reference link 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 link is being written, or null if none is available.</param>
        /// <param name="isTopLevel">true if the entity reference link being written is at the top level of the payload.</param>
        private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink entityReferenceLink, IEdmEntitySet entitySet, IEdmNavigationProperty navigationProperty, bool isTopLevel)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null");

            WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink);

            this.JsonWriter.StartObjectScope();

            if (isTopLevel)
            {
                Uri metadataUri;
                if (this.metadataUriBuilder.TryBuildEntityReferenceLinkMetadataUri(entityReferenceLink.SerializationInfo, entitySet, navigationProperty, out metadataUri))
                {
                    this.WriteMetadataUriProperty(metadataUri);
                }
            }

            this.JsonWriter.WriteName(JsonLightConstants.ODataEntityReferenceLinkUrlName);
            this.JsonWriter.WriteValue(this.UriToString(entityReferenceLink.Url));
            this.JsonWriter.EndObjectScope();
        }