/// <summary>
        /// Generates a compiled method to run a Handler.
        /// </summary>
        /// <returns>A compiled delegate to run the Handler asynchronously.</returns>
        public Func<IContext, Task> BuildAsyncRunMethod()
        {
            var blocks = new List<object>();

            blocks.AddRange(CreateBlocks(GetSetupBehaviorInfos()));

            var second = new HandlerBlock(_handlerType, GetRunMethod());
            blocks.Add(second);

            blocks.AddRange(CreateBlocks(GetResponseBehaviorInfos()));

            var outputs = GetOutputBehaviorInfos().ToList();
            if (outputs.Count > 0)
            {
                blocks.AddRange(CreateBlocks(outputs));
            }
            else
            {
                var writeViewBlock = new PipelineBlock();
                writeViewBlock.Add(typeof(WriteView).GetMethod("Impl", BindingFlags.Static | BindingFlags.Public));
                blocks.Add(writeViewBlock);
            }

            var call = BuildCallExpression(blocks);

            var setCookieProperties = CookiePropertySetter.GetCookiePropertySetters(_handlerType, _handler, _context);
            var setPropertyCookies = PropertyCookieSetter.GetPropertyCookieSetters(_handlerType, _handler, _context);

            var createHandler = BuildCreateHandlerExpression();

            var lambdaBlock = Expression.Block(new[] { _handler }, new[] { createHandler, call });

            var lambda = Expression.Lambda(lambdaBlock, _context);
            return (Func<IContext, Task>) lambda.Compile();
        }
Beispiel #2
0
        /// <summary>
        /// Generates a compiled method to run a Handler.
        /// </summary>
        /// <returns>A compiled delegate to run the Handler asynchronously.</returns>
        public Func <IContext, HandlerInfo, Task> BuildAsyncRunMethod(string httpMethod)
        {
            var blocks = new List <object>();

            blocks.AddRange(CreateBlocks(GetSetupBehaviorInfos()));
            var setCookieProperties = CookiePropertySetter.GetCookiePropertySetters(_handlerType, _handler, _context);

            blocks.AddRange(setCookieProperties);

            var second = new HandlerBlock(_handlerType, GetRunMethod(httpMethod));

            blocks.Add(second);
            var setPropertyCookies = PropertyCookieSetter.GetPropertyCookieSetters(_handlerType, _handler, _context);

            blocks.AddRange(setPropertyCookies);

            var redirectBehavior = new ResponseBehaviorInfo(typeof(object), typeof(Redirect2), Priority.High)
            {
                Universal = true
            };

            blocks.AddRange(CreateBlocks(GetResponseBehaviorInfos(redirectBehavior)));

            var outputs = GetOutputBehaviorInfos().ToList();

            if (outputs.Count > 0)
            {
                blocks.AddRange(CreateBlocks(outputs));
            }
            else
            {
                var writeViewBlock = new PipelineBlock();
                writeViewBlock.Add(typeof(WriteView).GetMethod("Impl", BindingFlags.Static | BindingFlags.Public));
                blocks.Add(writeViewBlock);
            }

            var call = BuildCallExpression(blocks);


            var createHandler = BuildCreateHandlerExpression();

            var lambdaBlock = Expression.Block(new[] { _handler }, new[] { createHandler, call });

            var lambda = Expression.Lambda(lambdaBlock, _context, _handlerInfoVariable);

            return((Func <IContext, HandlerInfo, Task>)lambda.Compile());
        }