/// <summary>
        /// Adds a new stream to this <see cref="StreamingResponse"/> containing the passed in body.
        /// Noop on empty body or null response.
        /// </summary>
        /// <param name="response">The <see cref="StreamingResponse"/> instance to attach this body to.</param>
        /// <param name="body">A string containing the data to insert into the stream.</param>
        public static void SetBody(this StreamingResponse response, string body)
        {
            if (response == null || string.IsNullOrWhiteSpace(body))
            {
                return;
            }

            response.AddStream(new StringContent(body, Encoding.UTF8));
        }
        /// <summary>
        /// Adds a new stream to this <see cref="StreamingResponse"/> containing the passed in body.
        /// Noop on null body or null response.
        /// </summary>
        /// <param name="response">The <see cref="StreamingResponse"/> instance to attach this body to.</param>
        /// <param name="body">An object containing the data to insert into the stream.</param>
        public static void SetBody(this StreamingResponse response, object body)
        {
            if (response == null || body == null)
            {
                return;
            }

            var json = JsonConvert.SerializeObject(body, SerializationSettings.BotSchemaSerializationSettings);

            response.AddStream(new StringContent(json, Encoding.UTF8, SerializationSettings.ApplicationJson));
        }
Exemple #3
0
        /// <summary>
        /// Creates a response using the passed in statusCode and optional body.
        /// </summary>
        /// <param name="statusCode">The <see cref="HttpStatusCode"/> to set on the <see cref="StreamingResponse"/>.</param>
        /// <param name="body">An optional body containing additional information.</param>
        /// <returns>A response with the appropriate statuscode and passed in body.</returns>
        public static StreamingResponse CreateResponse(HttpStatusCode statusCode, HttpContent body = null)
        {
            var response = new StreamingResponse()
            {
                StatusCode = (int)statusCode,
            };

            if (body != null)
            {
                response.AddStream(body);
            }

            return(response);
        }