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

            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
                    : context.CreateProxy(message)));
            }

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

                await next.Send(ReferenceEquals(initializeContext.Message, context.Message)
                                ?context
                                : context.CreateProxy(initializeContext.Message)).ConfigureAwait(false);
            }

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

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

            if (result.IsNewValue)
            {
                var transformedContext = context.CreateProxy(result.Value);

                return(next.Send(transformedContext));
            }

            return(next.Send(context));
        }