Beispiel #1
0
        private void CreateSetupBlocks()
        {
            _blocks.AddRange(CookiePropertySetter.GetCookiePropertySetters(_type, _handler, _context));

            foreach (var behaviorInfo in RequestBehaviorInfo.GetInPriorityOrder())
            {
                AddBehaviorBlock(behaviorInfo);
            }
        }
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());
        }