コード例 #1
0
        /// <summary>
        /// Asynchronously writes the envelope for the inner HTTP message.
        /// </summary>
        /// <param name="responseMessage">The response message to write the envelope.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        private async Task WriteInnerEnvelopeAsync(ODataAsynchronousResponseMessage responseMessage)
        {
            // Write response line.
            string statusMessage = HttpUtils.GetStatusMessage(responseMessage.StatusCode);

            await this.rawOutputContext.TextWriter.WriteLineAsync(
                string.Concat(ODataConstants.HttpVersionInAsync, " ", responseMessage.StatusCode, " ", statusMessage))
            .ConfigureAwait(false);

            // Write headers.
            if (responseMessage.Headers != null)
            {
                foreach (var headerPair in responseMessage.Headers)
                {
                    await this.rawOutputContext.TextWriter.WriteLineAsync(string.Concat(headerPair.Key, ": ", headerPair.Value))
                    .ConfigureAwait(false);
                }
            }

            // Write CRLF.
            await this.rawOutputContext.TextWriter.WriteLineAsync()
            .ConfigureAwait(false);

            // Flush the writer since we won't be able to access it anymore.
            await this.rawOutputContext.TextWriter.FlushAsync()
            .ConfigureAwait(false);
        }
コード例 #2
0
        /// <summary>
        /// Creates an <see cref="ODataAsynchronousResponseMessage"/> for writing an operation of an async response - implementation of the actual functionality.
        /// </summary>
        /// <returns>The message that can be used to write the response.</returns>
        private ODataAsynchronousResponseMessage CreateResponseMessageImplementation()
        {
            var responseMessage = ODataAsynchronousResponseMessage.CreateMessageForWriting(rawOutputContext.OutputStream, this.WriteInnerEnvelope, this.container);

            responseMessageCreated = true;

            return(responseMessage);
        }
コード例 #3
0
        /// <summary>
        /// Returns an <see cref="ODataAsynchronousResponseMessage"/> for reading the content of an async response - implementation of the actual functionality.
        /// </summary>
        /// <returns>The message that can be used to read the response.</returns>
        private ODataAsynchronousResponseMessage CreateResponseMessageImplementation()
        {
            int statusCode;
            IDictionary <string, string> headers;

            this.ReadInnerEnvelope(out statusCode, out headers);

            return(ODataAsynchronousResponseMessage.CreateMessageForReading(this.rawInputContext.Stream, statusCode, headers, this.container));
        }
コード例 #4
0
        /// <summary>
        /// Returns an <see cref="ODataAsynchronousResponseMessage"/> for reading the content of an async response - implementation of the actual functionality.
        /// </summary>
        /// <returns>
        /// A task that represents the asynchronous read operation.
        /// The value of the TResult parameter contains the message that can be used to read the response.
        /// </returns>
        private async Task <ODataAsynchronousResponseMessage> CreateResponseMessageImplementationAsync()
        {
            Tuple <int, Dictionary <string, string> > readInnerEnvelopeResult = await this.ReadInnerEnvelopeAsync()
                                                                                .ConfigureAwait(false);

            int statusCode = readInnerEnvelopeResult.Item1;
            Dictionary <string, string> headers = readInnerEnvelopeResult.Item2;

            return(ODataAsynchronousResponseMessage.CreateMessageForReading(this.rawInputContext.Stream, statusCode, headers, this.container));
        }
コード例 #5
0
        /// <summary>
        /// Asynchronously creates an <see cref="ODataAsynchronousResponseMessage"/> for writing an operation of an async response - implementation of the actual functionality.
        /// </summary>
        /// <returns>A task that represents the asynchronous operation.
        /// The value of the TResult parameter contains an <see cref="ODataAsynchronousResponseMessage"/>
        /// that can be used to write the response.</returns>
        private async Task <ODataAsynchronousResponseMessage> CreateResponseMessageImplementationAsync()
        {
            var responseMessage = await ODataAsynchronousResponseMessage.CreateMessageForWritingAsync(
                rawOutputContext.OutputStream,
                this.WriteInnerEnvelopeAsync,
                this.container).ConfigureAwait(false);

            responseMessageCreated = true;

            return(responseMessage);
        }
コード例 #6
0
        /// <summary>
        /// Writes the envelope for the inner HTTP message.
        /// </summary>
        /// <param name="responseMessage">The response message to write the envelope.</param>
        private void WriteInnerEnvelope(ODataAsynchronousResponseMessage responseMessage)
        {
            // Write response line.
            string statusMessage = HttpUtils.GetStatusMessage(responseMessage.StatusCode);

            this.rawOutputContext.TextWriter.WriteLine("{0} {1} {2}", ODataConstants.HttpVersionInAsync, responseMessage.StatusCode, statusMessage);

            // Write headers.
            if (responseMessage.Headers != null)
            {
                foreach (var headerPair in responseMessage.Headers)
                {
                    string headerName  = headerPair.Key;
                    string headerValue = headerPair.Value;
                    this.rawOutputContext.TextWriter.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}: {1}", headerName, headerValue));
                }
            }

            // Write CRLF.
            this.rawOutputContext.TextWriter.WriteLine();

            // Flush the writer since we won't be able to access it anymore.
            this.rawOutputContext.TextWriter.Flush();
        }