Пример #1
0
        public Task <Result <CommandResponse> > ExecuteAsync(OperationContext context, CommandRequest request)
        {
            return(context.PerformOperationAsync(Tracer, async() =>
            {
                var requestAsBytes = _serializationPool.Serialize(request, (value, writer) => value.Serialize(writer));
                var requestAsProto = new Grpc.Request()
                {
                    Request_ = Google.Protobuf.ByteString.CopyFrom((byte[])requestAsBytes),
                };

                var callOptions = new CallOptions()
                                  .WithCancellationToken(context.Token)
                                  .WithHeaders(new Metadata()
                {
                    { "X-Cache-Client-Version", "0.0" },
                    { "X-Cache-Operation-Id", context.TracingContext.TraceId },
                });

                Contract.AssertNotNull(_client);
                var asyncUnaryCall = _client.ExecuteAsync(requestAsProto, callOptions);

                Grpc.Reply responseAsProto = await asyncUnaryCall;
                var responseAsBytes = responseAsProto.Reply_.ToByteArray();
                var response = _serializationPool.Deserialize(responseAsBytes, reader => CommandResponse.Deserialize(reader));
                Contract.AssertNotNull(response);

                return new Result <CommandResponse>(response);
            }, traceErrorsOnly: true));
        }