예제 #1
0
        /// <summary>
        /// Write an array of documents as a JSON array from a compiled query
        /// to the HttpContext
        /// </summary>
        /// <param name="session"></param>
        /// <param name="query"></param>
        /// <param name="context"></param>
        /// <param name="contentType"></param>
        /// <typeparam name="TDoc"></typeparam>
        /// <typeparam name="TOut"></typeparam>
        public static async Task WriteArray <TDoc, TOut>(this IQuerySession session, ICompiledQuery <TDoc, TOut> query, HttpContext context, string contentType = "application/json")
        {
            var stream = new MemoryStream();
            await session.StreamJsonMany(query, stream, context.RequestAborted).ConfigureAwait(false);

            context.Response.StatusCode    = 200;
            context.Response.ContentLength = stream.Length;
            context.Response.ContentType   = contentType;

            stream.Position = 0;
            await stream.CopyToAsync(context.Response.Body).ConfigureAwait(false);
        }