Exemple #1
0
        private static async Task RunClientAsync(
            ILogger logger,
            RoxisClientArguments arguments,
            CancellationToken cancellationToken = default)
        {
            var tracingContext = new Context(logger);
            var context        = new OperationContext(tracingContext, cancellationToken);

            var command        = CommandExtensions.FromString(arguments.Command, arguments.Parameters).ThrowIfFailure();
            var commandRequest = new CommandRequest(new[] { command });

            var client = new RoxisClient(arguments.Client);
            await client.StartupAsync(context).ThrowIfFailureAsync();

            var commandResponse = await client.ExecuteAsync(context, commandRequest).ThrowIfFailureAsync();

            var jsonSerializerOptions = new JsonSerializerOptions()
            {
                WriteIndented = true,
            };

            jsonSerializerOptions.Converters.Add(new ByteStringConverter());

            foreach (var result in commandResponse.Results)
            {
                context.TraceInfo(JsonSerializer.Serialize(result, result.GetType(), jsonSerializerOptions), component: nameof(Client));
            }

            await client.ShutdownAsync(context).ThrowIfFailureAsync();
        }