public override void Process(ProcessContext context) { MvcEventPublisher.Instance.BeginAddLayout(context.ctx); if (context.ctx.utils.isSkipCurrentProcessor()) { return; } MvcContext ctx = context.ctx; ControllerBase controller = ctx.controller; 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(); //检查缓存 ActionCacheChecker ci = ActionCacheChecker.InitLayout(ctx); Object cacheContent = ci.GetCache(); if (cacheContent != null) { logger.Info("load from layoutCache=" + ci.CacheKey); context.setContent(HtmlCombiner.combinePage(cacheContent.ToString(), actionContent)); return; } String layoutContent = ControllerRunner.RunLayout(ctx); // 加入缓存 if (ci.IsActionCache) { ci.AddCache(layoutContent); } if (ctx.utils.isEnd()) { return; } context.setContent(HtmlCombiner.combinePage(layoutContent, actionContent)); }
// 0) path => Blog.Admin // 1) path => Blog // 2) path => "" private static String addLayoutPrivate(String path, String actionContent, MvcContext ctx, Boolean isLastLayout) { 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); } // 检查缓存 ActionCacheChecker ci = ActionCacheChecker.InitLayout(ctx, controller); Object cacheContent = ci.GetCache(); if (cacheContent != null) { logger.Info("load from nsLayoutCache=" + ci.CacheKey); return(HtmlCombiner.combinePage(cacheContent.ToString(), actionContent)); } controller.utils.switchViewToLayout(); ActionRunner.runLayoutAction(ctx, controller, controller.Layout); if (ctx.utils.isEnd()) { return(ctx.utils.getCurrentOutputString()); } String actionResult = controller.utils.getActionResult(); if (ci.IsActionCache) { ci.AddCache(actionResult); } return(HtmlCombiner.combinePage(actionResult, actionContent)); }
public override void Process(ProcessContext context) { MvcEventPublisher.Instance.BeginProcessAction(context.ctx); if (context.ctx.utils.isSkipCurrentProcessor()) { return; } MvcContext ctx = context.ctx; ControllerBase controller = ctx.controller; // 1) 检查 action 缓存 ActionCacheChecker xChecker = ActionCacheChecker.InitAction(ctx); Object cacheContent = xChecker.GetCache(); if (cacheContent != null) { logger.Info("load from actionCache=" + xChecker.CacheKey); context.setContent(cacheContent.ToString()); setPageMeta_FromCache(ctx, xChecker.CacheKey); return; } // 2) 运行 before action (获取所有的 ActionObserver) List <ActionObserver> actionObservers = ControllerMeta.GetActionObservers(controller.GetType(), ctx.route.action); if (actionObservers != null) { foreach (ActionObserver x in actionObservers) { ActionObserver ob = (ActionObserver)ObjectContext.CreateObject(x.GetType()); Boolean isContinue = ob.BeforeAction(ctx); if (!isContinue) { return; } } } // 3) 运行 action MethodInfo actionMethod = ctx.ActionMethodInfo; // context.getActionMethod(); // 设值模板并载入全局变量 setControllerView(controller, actionMethod); // 运行并处理post值 ActionRunner.runAction(ctx, controller, actionMethod, controller.utils.runAction); if (ctx.utils.isEnd()) { afterAction(ctx); return; } String actionContent = controller.utils.getActionResult(); // 4) 后续缓存处理 if (xChecker.IsActionCache) { xChecker.AddCache(actionContent); addPageMeta_ToCache(ctx, xChecker.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 { context.setContent(actionContent); } afterAction(ctx); }