Beispiel #1
0
        /// <inheritdoc/>
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            ClientRpcScope <TRequest, TResponse> rpcScope = null;

            try
            {
                rpcScope = new ClientRpcScope <TRequest, TResponse>(context, this.options);
                var responseContinuation     = continuation(rpcScope.Context);
                var clientRequestStreamProxy = new ClientStreamWriterProxy <TRequest>(
                    responseContinuation.RequestStream,
                    rpcScope.RecordRequest,
                    onException: rpcScope.CompleteWithException);

                var responseAsync = responseContinuation.ResponseAsync.ContinueWith(
                    responseTask =>
                {
                    try
                    {
                        var response = responseTask.Result;
                        rpcScope.RecordResponse(response);
                        rpcScope.Complete();
                        return(response);
                    }
                    catch (AggregateException ex)
                    {
                        rpcScope.CompleteWithException(ex.InnerException);
                        throw ex.InnerException;
                    }
                });

                return(new AsyncClientStreamingCall <TRequest, TResponse>(
                           clientRequestStreamProxy,
                           responseAsync,
                           responseContinuation.ResponseHeadersAsync,
                           responseContinuation.GetStatus,
                           responseContinuation.GetTrailers,
                           responseContinuation.WithBestEffortDispose(rpcScope)));
            }
            catch (Exception e)
            {
                rpcScope?.CompleteWithException(e);
                throw;
            }
            finally
            {
                rpcScope?.RestoreParentActivity();
            }
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            ClientRpcScope <TRequest, TResponse> rpcScope = null;

            try
            {
                rpcScope = new ClientRpcScope <TRequest, TResponse>(context, this.options);
                var responseContinuation = continuation(rpcScope.Context);

                var requestStreamProxy = new ClientStreamWriterProxy <TRequest>(
                    responseContinuation.RequestStream,
                    rpcScope.RecordRequest,
                    onException: rpcScope.CompleteWithException);

                var responseStreamProxy = new AsyncStreamReaderProxy <TResponse>(
                    responseContinuation.ResponseStream,
                    rpcScope.RecordResponse,
                    rpcScope.Complete,
                    rpcScope.CompleteWithException);

                return(new AsyncDuplexStreamingCall <TRequest, TResponse>(
                           requestStreamProxy,
                           responseStreamProxy,
                           responseContinuation.ResponseHeadersAsync,
                           responseContinuation.GetStatus,
                           responseContinuation.GetTrailers,
                           responseContinuation.WithBestEffortDispose(rpcScope)));
            }
            catch (Exception e)
            {
                rpcScope?.CompleteWithException(e);
                throw;
            }
            finally
            {
                rpcScope?.RestoreParentActivity();
            }
        }