示例#1
0
        Task IFilter <ExecuteContext <T> > .Send(ExecuteContext <T> context, IPipe <ExecuteContext <T> > next)
        {
            var transformContext = new ConsumeTransformContext <T>(context, context.Arguments);

            var initializeTask = _initializer.Initialize(_initializer.Create(transformContext), context.Arguments);

            if (initializeTask.IsCompleted)
            {
                var arguments = initializeTask.Result.Message;

                return(next.Send(ReferenceEquals(arguments, context.Arguments)
                    ? context
                    : new ExecuteContextProxy <T>(context, arguments)));
            }

            async Task SendAsync()
            {
                var initializeContext = await initializeTask.ConfigureAwait(false);

                await next.Send(ReferenceEquals(initializeContext.Message, context.Arguments)
                                ?context
                                : new ExecuteContextProxy <T>(context, initializeContext.Message)).ConfigureAwait(false);
            }

            return(SendAsync());
        }
示例#2
0
        Task IFilter <ConsumeContext <T> > .Send(ConsumeContext <T> context, IPipe <ConsumeContext <T> > next)
        {
            var transformContext = new ConsumeTransformContext <T>(context, context.Message);

            var initializeTask = _initializer.Initialize(_initializer.Create(transformContext), context.Message);

            if (initializeTask.IsCompleted)
            {
                var message = initializeTask.Result.Message;

                return(next.Send(ReferenceEquals(message, context.Message)
                    ? context
                    : new MessageConsumeContext <T>(context, message)));
            }

            async Task SendAsync()
            {
                var initializeContext = await initializeTask.ConfigureAwait(false);

                await next.Send(ReferenceEquals(initializeContext.Message, context.Message)
                                ?context
                                : new MessageConsumeContext <T>(context, initializeContext.Message)).ConfigureAwait(false);
            }

            return(SendAsync());
        }
        Task IFilter <ConsumeContext <T> > .Send(ConsumeContext <T> context, IPipe <ConsumeContext <T> > next)
        {
            var transformContext = new ConsumeTransformContext <T>(context);

            TransformResult <T> result = _transform.ApplyTo(transformContext);

            if (result.IsNewValue)
            {
                var transformedContext = new MessageConsumeContext <T>(context, result.Value);

                return(next.Send(transformedContext));
            }

            return(next.Send(context));
        }