Exemplo n.º 1
0
        // 0) path => Blog.Admin
        // 1) path => Blog
        // 2) path => ""
        private static String addLayoutPrivate(String path, String actionContent, MvcContext ctx, Boolean isLastLayout)
        {
            // String content = layoutCacher.getByPath( path )
            // if( strUtil.HasText( content ) ) return HtmlCombiner.combinePage( content, actionContent );

            ControllerBase controller = ControllerFactory.FindLayoutController(path, ctx);

            if (controller == null)
            {
                return(actionContent);
            }

            ctx.controller.utils.addHidedLayouts(controller);   // 将controller中提到需要隐藏的控制器隐藏
            if (ctx.controller.utils.isHided(controller.GetType()))
            {
                return(actionContent);
            }

            // 检查缓存
            String cacheKey = null;

            if (MvcConfig.Instance.IsActionCache)
            {
                IActionCache actionCache = ControllerMeta.GetActionCache(controller.GetType(), "Layout");

                cacheKey = getCacheKey(actionCache, ctx);
                if (strUtil.HasText(cacheKey))
                {
                    Object cacheContent = checkCache(cacheKey);
                    if (cacheContent != null)
                    {
                        logger.Info("load from nsLayoutCache=" + cacheKey);

                        return(HtmlCombiner.combinePage(cacheContent.ToString(), actionContent));
                    }
                }
            }

            controller.utils.switchViewToLayout();

            ActionRunner.runLayoutAction(ctx, controller, controller.Layout);

            if (ctx.utils.isEnd())
            {
                return(controller.utils.getActionResult());
            }

            String actionResult = controller.utils.getActionResult();

            // 加入缓存
            if (MvcConfig.Instance.IsActionCache)
            {
                if (cacheKey != null)
                {
                    addContentToCache(cacheKey, actionResult);
                }
            }

            return(HtmlCombiner.combinePage(actionResult, actionContent));
        }
Exemplo n.º 2
0
        public override void Process(ProcessContext context)
        {
            MvcEventPublisher.Instance.BeginProcessAction(context.ctx);
            if (context.ctx.utils.isSkipCurrentProcessor())
            {
                return;
            }

            MvcContext ctx = context.ctx;

            ControllerBase controller = context.getController();


            // 检查缓存
            String cacheKey = null;

            if (MvcConfig.Instance.IsActionCache)
            {
                IActionCache actionCache = ControllerMeta.GetActionCache(controller.GetType(), ctx.route.action);

                cacheKey = getCacheKey(actionCache, ctx);
                if (strUtil.HasText(cacheKey))
                {
                    Object cacheContent = checkCache(cacheKey);
                    if (cacheContent != null)
                    {
                        logger.Info("load from actionCache=" + cacheKey);
                        context.setContent(cacheContent.ToString());
                        getPageMetaFromCache(ctx, cacheKey);
                        return;
                    }
                }
            }

            MethodInfo actionMethod = ctx.ActionMethodInfo; // context.getActionMethod();

            // 设值模板并载入全局变量
            setControllerView(controller, actionMethod);

            // 运行并处理post值
            ActionRunner.runAction(ctx, controller, actionMethod, controller.utils.runAction);
            String actionContent = controller.utils.getActionResult();

            // 加入缓存
            if (MvcConfig.Instance.IsActionCache)
            {
                if (strUtil.HasText(cacheKey))
                {
                    addContentToCache(cacheKey, actionContent);
                    // 加入PageMeta
                    addPageMetaToCache(ctx, cacheKey);
                }
            }

            actionContent = PostValueProcessor.ProcessPostValue(actionContent, ctx);

            if (ctx.utils.isAjax)
            {
                context.showEnd(actionContent);
            }
            else if (ctx.utils.isFrame())
            {
                int intNoLayout = ctx.utils.getNoLayout();

                if (intNoLayout == 0)
                {
                    String content = MvcUtil.getFrameContent(actionContent);
                    context.showEnd(content);
                }
                else
                {
                    context.setContent(actionContent);
                }
            }
            else if (ctx.utils.isEnd())
            {
                context.showEnd(actionContent);
            }
            else
            {
                context.setContent(actionContent);
            }

            updateActionCache(ctx);

            MvcEventPublisher.Instance.EndProcessAction(context.ctx);
        }
Exemplo n.º 3
0
        public override void Process(ProcessContext context)
        {
            MvcEventPublisher.Instance.BeginAddLayout(context.ctx);
            if (context.ctx.utils.isSkipCurrentProcessor())
            {
                return;
            }

            MvcContext     ctx        = context.ctx;
            ControllerBase controller = context.getController();

            if (controller.utils.isHided(controller.GetType()))
            {
                return;
            }

            int   intNoLayout = ctx.utils.getNoLayout();
            IList paths       = ctx.utils.getLayoutPath();

            if (intNoLayout >= paths.Count + 1)
            {
                return;
            }


            String actionContent = context.getContent();


            //检查缓存
            String cacheKey = null;

            if (MvcConfig.Instance.IsActionCache)
            {
                IActionCache actionCache = ControllerMeta.GetActionCache(controller.GetType(), "Layout");

                cacheKey = getCacheKey(actionCache, ctx);
                if (strUtil.HasText(cacheKey))
                {
                    Object cacheContent = checkCache(cacheKey);
                    if (cacheContent != null)
                    {
                        logger.Info("load from layoutCache=" + cacheKey);
                        context.setContent(HtmlCombiner.combinePage(cacheContent.ToString(), actionContent));
                        return;
                    }
                }
            }

            String layoutContent;

            if (controller.LayoutControllerType == null)
            {
                layoutContent = runCurrentLayout(controller, ctx, context, actionContent);
            }
            else
            {
                layoutContent = runOtherLayout(controller, ctx, context, actionContent);
            }

            // 加入缓存
            if (MvcConfig.Instance.IsActionCache)
            {
                if (strUtil.HasText(cacheKey))
                {
                    addContentToCache(cacheKey, layoutContent);
                }
            }

            if (ctx.utils.isEnd())
            {
                context.endMsgByText(layoutContent);
            }
            else
            {
                context.setContent(HtmlCombiner.combinePage(layoutContent, actionContent));
            }
        }