예제 #1
0
        static void Main(string[] args)
        {
            Controller controller   = new Controller();
            MethodInfo actionMethod = typeof(Controller).GetMethod("Get");

            CancellationToken cancellationToken = new CancellationToken();

            List <IActionFilter> filters = new List <IActionFilter>()
            {
                new FirstActionFilter(),
                new SecondActionFilter()
            };
            ActionContext context = new ActionContext()
            {
                Controller = controller,
                Action     = actionMethod,
                Arguments  = new object[0]
            };
            ActionInvoker invoker = new ActionInvoker(context.Action);

            Func <Task <ResponseMessage> > result = () =>
            {
                return(invoker.Invoke(context, cancellationToken));
            };

            for (int i = 0; i <= filters.Count - 1; i++)
            {
                IActionFilter filter = filters[i];

                Func <Func <Task <ResponseMessage> >, IActionFilter, Func <Task <ResponseMessage> > > chainContinuation =
                    (continuation, innerFilter) =>
                {
                    return(() =>
                    {
                        return innerFilter.ExecuteActionFilterAsync(context, cancellationToken, continuation);
                    });
                };
                result = chainContinuation(result, filter);
            }
            //string res = continuation()().Result.Message;
            result.Invoke();
            Console.ReadKey();
        }
예제 #2
0
파일: Program.cs 프로젝트: BarlowDu/WebAPI
        static void Main(string[] args)
        {
            Controller controller = new Controller();
            MethodInfo actionMethod = typeof(Controller).GetMethod("Get");

            CancellationToken cancellationToken = new CancellationToken();

            List<IActionFilter> filters = new List<IActionFilter>() {
            new FirstActionFilter(),
            new SecondActionFilter()
            };
            ActionContext context = new ActionContext()
            {
                Controller = controller,
                Action = actionMethod,
                Arguments = new object[0]
            };
            ActionInvoker invoker = new ActionInvoker(context.Action);

            Func<Task<ResponseMessage>> result = () =>
            {
                return invoker.Invoke(context, cancellationToken);
            };

            for (int i = 0; i <= filters.Count - 1; i++)
            {
                IActionFilter filter = filters[i];

                Func<Func<Task<ResponseMessage>>, IActionFilter, Func<Task<ResponseMessage>>> chainContinuation =
                    (continuation, innerFilter) =>
                    {
                        return () =>
                        {
                            return innerFilter.ExecuteActionFilterAsync(context, cancellationToken, continuation);
                        };
                    };
                result = chainContinuation(result, filter);
            }
            //string res = continuation()().Result.Message;
            result.Invoke();
            Console.ReadKey();
        }