コード例 #1
0
ファイル: DeepInterceptor.cs プロジェクト: mxProject/Misc
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="streamReader"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private IAsyncStreamReader <TRequest> CreateServerStreamReader <TRequest>(IAsyncStreamReader <TRequest> streamReader, ServerCallContext context)
            where TRequest : class
        {
            Task <bool> onMoveNext(IAsyncStreamReader <TRequest> reader, CancellationToken cancellationToken)
            {
                bool result = false;

                async Task <TRequest> func()
                {
                    result = await reader.MoveNext(cancellationToken).ConfigureAwait(false);

                    return(result ? reader.Current : default(TRequest));
                }

                InterceptServerMoveNextRequest(func, context);

                return(Task.FromResult(result));
            }

            void onDispose(IAsyncStreamReader <TRequest> reader)
            {
                reader.Dispose();
            }

            return(streamReader.Wrap(onMoveNext, onDispose));
        }
コード例 #2
0
ファイル: DeepInterceptor.cs プロジェクト: mxProject/Misc
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TRequest"></typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <param name="streamReader"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private IAsyncStreamReader <TResponse> CreateClientStreamReader <TRequest, TResponse>(IAsyncStreamReader <TResponse> streamReader, ClientInterceptorContext <TRequest, TResponse> context)
            where TRequest : class
            where TResponse : class
        {
            async Task <bool> onMoveNext(IAsyncStreamReader <TResponse> reader, CancellationToken cancellationToken)
            {
                bool result = false;

                async Task <bool> func()
                {
                    result = await reader.MoveNext(cancellationToken).ConfigureAwait(false);

                    return(result);
                }

                await InterceptClientMoveNextResponse(func, context).ConfigureAwait(false);

                return(result);
            }

            void onDispose(IAsyncStreamReader <TResponse> reader)
            {
                reader.Dispose();
            }

            return(streamReader.Wrap(onMoveNext, onDispose));
        }