Example #1
0
 public void EndQueryExecute(IQueryContext context)
 {
     using (var stream = new MemoryStream())
     {
         var resultSerializer = new JsonQueryResultSerializer();
         var str = resultSerializer.Serialize(
             (IReadOnlyQueryResult)context.Result);
         _logger.LogInformation(str, null);
     }
 }
        public static string ToJson(
            this IExecutionResult result,
            bool withIndentations = true)
        {
            if (result is null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result is IReadOnlyQueryResult queryResult)
            {
                if (withIndentations)
                {
                    return _serializerIndented.Serialize(queryResult);
                }
                return _serializer.Serialize(queryResult);
            }

            // TODO : resources / throw helper
            throw new NotSupportedException(
                "Only query results are supported.");
        }
    private async Task WriteResultAsync(
        IQueryResult result,
        Stream outputStream,
        CancellationToken cancellationToken)
    {
        using var writer = new ArrayWriter();
        _payloadSerializer.Serialize(result, writer);

        await WriteResultHeaderAsync(outputStream, cancellationToken)
        .ConfigureAwait(false);

        // The payload is sent, followed by a CRLF.
        await outputStream.WriteAsync(
            writer.GetInternalBuffer(), 0, writer.Length, cancellationToken)
        .ConfigureAwait(false);

        await outputStream.WriteAsync(CrLf, 0, CrLf.Length, cancellationToken)
        .ConfigureAwait(false);
    }
        public static string ToJson(
            this IExecutionResult result,
            bool withIndentations)
        {
            if (result is null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result is IReadOnlyQueryResult queryResult)
            {
                if (withIndentations)
                {
                    return(_serializerIndented.Serialize(queryResult));
                }
                return(_serializer.Serialize(queryResult));
            }

            throw new NotSupportedException(
                      CoreResources.ToJson_OnlyQueryResultsSupported);
        }