Exemple #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));
        }
Exemple #2
0
        private static Dictionary <String, List <IActionCache> > loadCachesByUpdate()
        {
            Dictionary <String, List <IActionCache> > dicResults = new Dictionary <String, List <IActionCache> >();

            List <Type> subControllers = new List <Type>();

            foreach (KeyValuePair <String, Type> kv in ObjectContext.Instance.TypeList)
            {
                if (kv.Value.IsAbstract)
                {
                    continue;
                }

                if (kv.Value.IsSubclassOf(typeof(ControllerBase)) && kv.Value.BaseType != typeof(ControllerBase))
                {
                    subControllers.Add(kv.Value);
                }

                if (rft.IsInterface(kv.Value, typeof(IActionCache)))
                {
                    IActionCache obj = (IActionCache)ObjectContext.GetByType(kv.Value);
                    addActions(dicResults, obj);
                }
            }

            return(processSubControllers(subControllers, dicResults));
        }
Exemple #3
0
        //---------------------------------------------------------------------------------------------------------


        private static Dictionary <String, IActionCache> loadIActionCaches()
        {
            Dictionary <String, IActionCache> results = new Dictionary <String, IActionCache>();

            Dictionary <String, ControllerMeta> metas = ControllerMeta.GetMetaDB();

            foreach (KeyValuePair <String, ControllerMeta> kv in metas)
            {
                ControllerMeta controller = kv.Value;

                foreach (KeyValuePair <String, ControllerAction> caKv in controller.ActionMaps)
                {
                    ControllerAction action = caKv.Value;

                    foreach (Attribute a in action.AttributeList)
                    {
                        CacheActionAttribute cachedInfo = a as CacheActionAttribute;
                        if (cachedInfo == null)
                        {
                            continue;
                        }

                        IActionCache obj = (IActionCache)ObjectContext.GetByType(cachedInfo.Type);

                        results.Add(controller.ControllerType.FullName + "_" + action.ActionName, obj);
                    }
                }
            }

            return(results);
        }
Exemple #4
0
        private void initCacheKey( IActionCache actionCache, MvcContext ctx )
        {
            if (actionCache == null) return ;
            if (ctx.HttpMethod.Equals( "GET" ) == false) return ;

            _cacheKey = actionCache.GetCacheKey( ctx, _actionName );
            if (strUtil.HasText( _cacheKey )) {
                _isActionCache = true;
            }
        }
Exemple #5
0
        //--------------------------------------------------------------------------


        private String getCacheKey(IActionCache actionCache, MvcContext ctx)
        {
            if (actionCache == null)
            {
                return(null);
            }
            if (ctx.HttpMethod.Equals("GET") == false)
            {
                return(null);
            }
            return(actionCache.GetCacheKey(ctx, ctx.route.action));
        }
Exemple #6
0
        private static bool subContains(List <IActionCache> subActionCaches, IActionCache ac)
        {
            foreach (IActionCache subAc in subActionCaches)
            {
                if (subAc.GetType() == ac.GetType())
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #7
0
        private void addPageCache(IActionCache ac, List <IPageCache> pageCaches)
        {
            List <IPageCache> relatedCaches = ControllerMeta.GetPageCacheByUpdate(ac.GetType());

            if (relatedCaches == null)
            {
                return;
            }

            foreach (IPageCache pc in relatedCaches)
            {
                if (pageCaches.Contains(pc) == false)
                {
                    pageCaches.Add(pc);
                }
            }
        }
Exemple #8
0
        private void initCacheKey(IActionCache actionCache, MvcContext ctx)
        {
            if (actionCache == null)
            {
                return;
            }
            if (ctx.HttpMethod.Equals("GET") == false)
            {
                return;
            }

            _cacheKey = actionCache.GetCacheKey(ctx, _actionName);
            if (strUtil.HasText(_cacheKey))
            {
                _isActionCache = true;
            }
        }
Exemple #9
0
        private static CacheInfo InitLayout(MvcContext ctx, ControllerBase controller, Boolean isLayout)
        {
            CacheInfo ci = new CacheInfo();

            if (MvcConfig.Instance.IsActionCache == false)
            {
                return(ci);
            }

            // 模拟的context环境下,不缓存
            if (ctx.web.GetType() != typeof(WebContext))
            {
                return(ci);
            }

            ci._actionName = isLayout ? "Layout" : ctx.route.action;

            IActionCache actionCache = ControllerMeta.GetActionCache(controller.GetType(), ci._actionName);

            ci.initCacheKey(actionCache, ctx);


            return(ci);
        }
 private String getCacheKey( IActionCache actionCache, MvcContext ctx )
 {
     if (actionCache == null) return null;
     if (ctx.HttpMethod.Equals( "GET" ) == false) return null;
     return actionCache.GetCacheKey( ctx, "Layout" );
 }
Exemple #11
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);
        }
Exemple #12
0
        private void addPageCache( IActionCache ac, List<IPageCache> pageCaches )
        {
            List<IPageCache> relatedCaches = ControllerMeta.GetPageCacheByUpdate( ac.GetType() );
            if (relatedCaches == null) return;

            foreach (IPageCache pc in relatedCaches) {
                if (pageCaches.Contains( pc ) == false) pageCaches.Add( pc );
            }
        }
Exemple #13
0
        private static bool subContains( List<IActionCache> subActionCaches, IActionCache ac )
        {
            foreach (IActionCache subAc in subActionCaches) {

                if (subAc.GetType() == ac.GetType()) return true;

            }

            return false;
        }
Exemple #14
0
        private static void addActions( Dictionary<String, List<IActionCache>> dic, IActionCache obj )
        {
            Dictionary<Type, String> actions = obj.GetRelatedActions();

            foreach (KeyValuePair<Type, String> kv in actions) {

                String[] arrActions = kv.Value.Split( '/' );
                foreach (String action in arrActions) {

                    String key = kv.Key.FullName + "_" + action;

                    List<IActionCache> clist = dic.ContainsKey( key ) ? dic[key] : new List<IActionCache>();
                    if( clist.Contains( obj)==false )
                        clist.Add( obj );

                    dic[key] = clist;
                }
            }
        }
Exemple #15
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));
            }
        }
Exemple #16
0
        private static void addActions(Dictionary <String, List <IActionCache> > dic, IActionCache obj)
        {
            Dictionary <Type, String> actions = obj.GetRelatedActions();

            foreach (KeyValuePair <Type, String> kv in actions)
            {
                String[] arrActions = kv.Value.Split('/');
                foreach (String action in arrActions)
                {
                    String key = kv.Key.FullName + "_" + action;

                    List <IActionCache> clist = dic.ContainsKey(key) ? dic[key] : new List <IActionCache>();
                    if (clist.Contains(obj) == false)
                    {
                        clist.Add(obj);
                    }

                    dic[key] = clist;
                }
            }
        }