示例#1
0
        public static IPipe <RequestContext> Build <TActivity, TArguments>(
            this IEnumerable <IPipeSpecification <ExecuteActivityContext <TActivity, TArguments> > > pipeSpecifications,
            IFilter <RequestContext <ExecuteActivityContext <TActivity, TArguments> > > consumeFilter)
            where TActivity : class, ExecuteActivity <TArguments>
            where TArguments : class
        {
            var builder = new ExecuteActivityPipeBuilder <TActivity, TArguments>();

            foreach (IPipeSpecification <ExecuteActivityContext <TActivity, TArguments> > specification in pipeSpecifications)
            {
                specification.Apply(builder);
            }

            ExecuteActivityPipeBuilder <TActivity, TArguments> builders = builder;

            if (builders == null)
            {
                throw new InvalidOperationException("Should not be null, ever");
            }

            return(Pipe.New <RequestContext>(cfg =>
            {
                cfg.UseDispatch(new RequestConverterFactory(), d =>
                {
                    d.Handle <ExecuteActivityContext <TActivity, TArguments> >(h =>
                    {
                        AddFilters(builders, h);

                        h.UseFilter(consumeFilter);
                    });
                });
            }));
        }
示例#2
0
        public static IPipe <ExecuteActivityContext <TActivity, TArguments> > Build <TActivity, TArguments>(
            this IEnumerable <IPipeSpecification <ExecuteActivityContext <TActivity, TArguments> > > pipeSpecifications,
            IFilter <ExecuteActivityContext <TActivity, TArguments> > consumeFilter)
            where TActivity : class, ExecuteActivity <TArguments>
            where TArguments : class
        {
            var builder = new ExecuteActivityPipeBuilder <TActivity, TArguments>();

            foreach (IPipeSpecification <ExecuteActivityContext <TActivity, TArguments> > specification in pipeSpecifications)
            {
                specification.Apply(builder);
            }

            ExecuteActivityPipeBuilder <TActivity, TArguments> builders = builder;

            if (builders == null)
            {
                throw new InvalidOperationException("Should not be null, ever");
            }

            return(Pipe.New <ExecuteActivityContext <TActivity, TArguments> >(x =>
            {
                foreach (IFilter <ExecuteActivityContext <TActivity, TArguments> > filter in builders.Filters)
                {
                    x.UseFilter(filter);
                }

                x.UseFilter(consumeFilter);
            }));
        }
示例#3
0
        static void AddFilters <TActivity, TArguments>(ExecuteActivityPipeBuilder <TActivity, TArguments> builders,
                                                       IPipeConfigurator <RequestContext <ExecuteActivityContext <TActivity, TArguments> > > h)
            where TActivity : class, ExecuteActivity <TArguments>
            where TArguments : class
        {
            foreach (IFilter <ExecuteActivityContext <TActivity, TArguments> > filter in builders.Filters)
            {
                var filterSpecification = new FilterPipeSpecification <ExecuteActivityContext <TActivity, TArguments> >(filter);

                var pipeSpecification = new SplitFilterPipeSpecification
                                        <RequestContext <ExecuteActivityContext <TActivity, TArguments> >, ExecuteActivityContext <TActivity, TArguments> >(
                    filterSpecification, (input, context) => input, context => context.Request);

                h.AddPipeSpecification(pipeSpecification);
            }
        }