示例#1
0
        public async Task <TResponse> Execute(IAsyncStreamReader <TRequest> requestStream, ServerCallContext context)
        {
            IncreaseActiveConnectionCount();
            try
            {
                var result = ExecuteInternal(ci => ci.AsyncClientStreamingCall(
                                                 _method,
                                                 _target,
                                                 CallOptionsHelper.Rewrite(context)));

                SessionHelper.HandleIfError(result, _logger);

                using var streamingCall = result.Value;
                var rewriteResult = await RewriteStream(requestStream, streamingCall.RequestStream);

                await streamingCall.RequestStream.CompleteAsync();

                var response = await streamingCall.ResponseAsync;
                SessionHelper.HandleIfError(rewriteResult, _logger);
                return(response);
            }
            finally
            {
                FinalizeConnection();
            }
        }
示例#2
0
        public async Task Execute(IAsyncStreamReader <TRequest> requestStream, IServerStreamWriter <TResponse> responseStream, ServerCallContext context)
        {
            IncreaseActiveConnectionCount();
            try
            {
                var result = ExecuteInternal(ci => ci.AsyncDuplexStreamingCall(
                                                 _method,
                                                 _target,
                                                 CallOptionsHelper.Rewrite(context)));
                SessionHelper.HandleIfError(result, _logger);

                using var streamSource = result.Value;
                var requestRewriteTask  = RewriteStream(requestStream, streamSource.RequestStream);
                var responseRewriteTask = RewriteStream(streamSource.ResponseStream, responseStream);

                await Task.WhenAny(requestRewriteTask, responseRewriteTask);

                await streamSource.RequestStream.CompleteAsync();

                SessionHelper.HandleIfError(await requestRewriteTask, _logger);
                SessionHelper.HandleIfError(await responseRewriteTask, _logger);
            }
            finally
            {
                FinalizeConnection();
            }
        }
示例#3
0
        public async Task <TResponse> Execute(TRequest request, ServerCallContext context)
        {
            IncreaseActiveConnectionCount();
            try
            {
                var result = ExecuteInternal(ci => ci.AsyncUnaryCall(_method,
                                                                     _target,
                                                                     CallOptionsHelper.Rewrite(context),
                                                                     request));
                var response = await result.Value;
                SessionHelper.HandleIfError(result, _logger);

                return(response);
            }
            finally
            {
                FinalizeConnection();
            }
        }
示例#4
0
        public async Task Execute(TRequest request, IServerStreamWriter <TResponse> responseStream, ServerCallContext context)
        {
            IncreaseActiveConnectionCount();
            try
            {
                var result = ExecuteInternal(ci => ci.AsyncServerStreamingCall(
                                                 _method,
                                                 _target,
                                                 CallOptionsHelper.Rewrite(context),
                                                 request));
                SessionHelper.HandleIfError(result, _logger);

                using var serverStreamingCall = result.Value;
                var rewriteResult = await RewriteStream(serverStreamingCall.ResponseStream, responseStream);

                SessionHelper.HandleIfError(rewriteResult, _logger);
            }
            finally
            {
                FinalizeConnection();
            }
        }