Ejemplo n.º 1
0
        /// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write to.</param>
        /// <param name="link">The associated entity 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>
        internal static void WriteAssociatedEntityLink(XmlWriter writer, ODataAssociatedEntityLink link, bool isTopLevel)
        {
            DebugUtils.CheckNoExternalCallers();

            // <uri ...
            writer.WriteStartElement(string.Empty, AtomConstants.ODataUriElementName, AtomConstants.ODataNamespace);

            if (isTopLevel)
            {
                // xmlns=
                writer.WriteAttributeString(AtomConstants.XmlnsNamespacePrefix, AtomConstants.ODataNamespace);
            }

            writer.WriteString(UriUtils.UriToString(link.Url));

            // </uri>
            writer.WriteEndElement();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="jsonWriter">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="baseUri">The base Uri used for writing.</param>
        /// <param name="link">The associated entity link to write out.</param>
        private static void WriteAssociatedEntityLink(JsonWriter jsonWriter, Uri baseUri, ODataAssociatedEntityLink link)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonWriter != null, "jsonWriter != null");
            Debug.Assert(link != null, "link != null");

            jsonWriter.StartObjectScope();
            jsonWriter.WriteName(JsonConstants.ODataUriName);
            jsonWriter.WriteValue(UriToAbsoluteUriString(link.Url, baseUri));
            jsonWriter.EndObjectScope();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes a single top-level Uri in response to a $links query.
        /// </summary>
        /// <param name="jsonWriter">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="baseUri">The base Uri used for writing.</param>
        /// <param name="link">The associated entity link to write out.</param>
        /// <param name="writingResponse">Flag indicating whether a request or a response is being written.</param>
        internal static void WriteAssociatedEntityLink(JsonWriter jsonWriter, Uri baseUri, ODataAssociatedEntityLink link, bool writingResponse)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonWriter != null, "jsonWriter != null");
            Debug.Assert(link != null, "link != null");

            ODataJsonWriterUtils.WriteDataWrapper(
                jsonWriter,
                writingResponse,
                () => WriteAssociatedEntityLink(jsonWriter, baseUri, link));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Write a top-level link to the given stream. This method creates an
        /// async buffered stream, writes the link to it and returns an <see cref="AsyncWriter"/>
        /// that can be used to flush and close/dispose the stream.
        /// </summary>
        /// <param name="stream">The stream to write the property to.</param>
        /// <param name="link">The associated entity link to write.</param>
        /// <returns>An <see cref="AsyncWriter"/> that can be used to flush and close/dispose the stream.</returns>
        private AsyncWriter WriteAssociatedEntityLinkImplementation(Stream stream, ODataAssociatedEntityLink link)
        {
            Debug.Assert(this.writerPayloadKind != ODataPayloadKind.Unsupported, "Expected payload kind, format and encoding to be set by now.");

            return this.WriteTopLevelContent(
                stream,
                (xmlWriter) => ODataAtomWriterUtils.WriteAssociatedEntityLink(xmlWriter, link, true),
                (jsonWriter) => ODataJsonWriterUtils.WriteAssociatedEntityLink(jsonWriter, this.settings.BaseUri, link, this.writingResponse),
                Strings.ODataMessageWriter_InvalidContentTypeForWritingLink,
                InternalErrorCodes.ODataMessageWriter_WriteAssociatedEntityLink);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes a singleton result of a $links query as the message payload.
        /// </summary>
        /// <param name="link">The link result to write as message payload.</param>
        /// <returns>A func which performs the actual writing given the stream to write to.</returns>
        private Func<Stream, AsyncWriter> WriteAssociatedEntityLinkImplementation(ODataAssociatedEntityLink link)
        {
            this.VerifyWriterNotUsed();
            ExceptionUtils.CheckArgumentNotNull(link, "link");

            // Set the content type header here since all headers have to be set before getting the stream
            this.SetOrVerifyHeaders(ODataPayloadKind.AssociatedEntityLink);

            return (stream) => this.WriteAssociatedEntityLinkImplementation(stream, link);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Asynchronously writes a singleton result of a $links query as the message payload.
 /// </summary>
 /// <param name="link">The link result to write as message payload.</param>
 /// <returns>A running task representing the writing of the link.</returns>
 public Task WriteAssociatedEntityLinkAsync(ODataAssociatedEntityLink link)
 {
     return this.WriteToStreamAsync(this.WriteAssociatedEntityLinkImplementation(link));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Writes a singleton result of a $links query as the message payload.
 /// </summary>
 /// <param name="link">The associated entity link to write as message payload.</param>
 public void WriteAssociatedEntityLink(ODataAssociatedEntityLink link)
 {
     this.WriteToStream(this.WriteAssociatedEntityLinkImplementation(link));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write to.</param>
        /// <param name="link">The associated entity 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>
        internal static void WriteAssociatedEntityLink(XmlWriter writer, ODataAssociatedEntityLink link, bool isTopLevel)
        {
            DebugUtils.CheckNoExternalCallers();

            // <uri ...
            writer.WriteStartElement(string.Empty, AtomConstants.ODataUriElementName, AtomConstants.ODataNamespace);

            if (isTopLevel)
            {
                // xmlns=
                writer.WriteAttributeString(AtomConstants.XmlnsNamespacePrefix, AtomConstants.ODataNamespace);
            }

            writer.WriteString(UriUtils.UriToString(link.Url));

            // </uri>
            writer.WriteEndElement();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Writes a single Uri in response to a $links query.
        /// </summary>
        /// <param name="jsonWriter">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="baseUri">The base Uri used for writing.</param>
        /// <param name="link">The associated entity link to write out.</param>
        private static void WriteAssociatedEntityLink(JsonWriter jsonWriter, Uri baseUri, ODataAssociatedEntityLink link)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonWriter != null, "jsonWriter != null");
            Debug.Assert(link != null, "link != null");

            jsonWriter.StartObjectScope();
            jsonWriter.WriteName(JsonConstants.ODataUriName);
            jsonWriter.WriteValue(UriToAbsoluteUriString(link.Url, baseUri));
            jsonWriter.EndObjectScope();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Writes a single top-level Uri in response to a $links query.
        /// </summary>
        /// <param name="jsonWriter">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="baseUri">The base Uri used for writing.</param>
        /// <param name="link">The associated entity link to write out.</param>
        /// <param name="writingResponse">Flag indicating whether a request or a response is being written.</param>
        internal static void WriteAssociatedEntityLink(JsonWriter jsonWriter, Uri baseUri, ODataAssociatedEntityLink link, bool writingResponse)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonWriter != null, "jsonWriter != null");
            Debug.Assert(link != null, "link != null");

            ODataJsonWriterUtils.WriteDataWrapper(
                jsonWriter,
                writingResponse,
                () => WriteAssociatedEntityLink(jsonWriter, baseUri, link));
        }