Exemplo n.º 1
0
        protected string _MCategoryTree(string moduleID)
        {
            //读取缓存
            string cacheKey = String.Format("{0}_site{1}_mtree_{2}", CacheSign.Category.ToString(), this.SiteId.ToString(), moduleID);
            BuiltCacheResultHandler <String> bh = () =>
            {
                //无缓存,则继续执行
                StringBuilder sb        = new StringBuilder(400);
                int           _moduleID = int.Parse(moduleID);
                //从模块加载
                if (CmsLogic.Module.GetModule(_moduleID) == null)
                {
                    return(TplMessage("不存在模块!ID:" + moduleID));
                }
                sb.Append("<div class=\"category_tree mtree\">");
                CategoryDto dto = new CategoryDto {
                    ID = 0
                };
                this.CategoryTree_Iterator(dto, sb, a => { return(a.ModuleId == _moduleID); }, true);
                sb.Append("</div>");
                return(sb.ToString());
            };

            return(Cms.Cache.GetCachedResult(cacheKey, bh, DateTime.Now.AddHours(Settings.OptiDefaultCacheHours)));
        }
Exemplo n.º 2
0
        private T GetCacheResult <T>(string cacheKey, BuiltCacheResultHandler <T> func, bool autoCache)
        {
            T data = default(T);

            object _data = this.Get(cacheKey);

            if (_data == null)
            {
                data = func();

                if (autoCache)
                {
                    this.Insert(cacheKey, data);
                }
            }
            else
            {
                data = (T)_data;
            }
            return(data);
        }
Exemplo n.º 3
0
        private T GetCacheResult <T>(string cacheKey, BuiltCacheResultHandler <T> func, bool autoCache,
                                     DateTime expiresTime)
        {
            var data = default(T);

            var _data = Get(cacheKey);

            if (_data == null)
            {
                data = func();

                if (autoCache)
                {
                    Insert(cacheKey, data, expiresTime);
                }
            }
            else
            {
                data = (T)_data;
            }

            return(data);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取缓存结果
 /// </summary>
 /// <param name="cacheKey"></param>
 /// <param name="func"></param>
 /// <returns></returns>
 public T GetCachedResult <T>(string cacheKey, BuiltCacheResultHandler <T> func)
 {
     return(dependCache.GetCachedResult <T>(cacheKey, func));
 }
Exemplo n.º 5
0
 /// <summary>
 /// 获取缓存结果
 /// </summary>
 /// <param name="cacheKey"></param>
 /// <param name="func"></param>
 /// <param name="expiresTime"></param>
 /// <returns></returns>
 public T GetCachedResult <T>(string cacheKey, BuiltCacheResultHandler <T> func, DateTime expiresTime)
 {
     return(_dependCache.GetCachedResult <T>(cacheKey, func, expiresTime));
 }
Exemplo n.º 6
0
        /// <summary>
        /// 左侧栏目树
        /// </summary>
        public void Tree()
        {
            var node = ServiceCall.Instance.SiteService.GetCategoryTreeWithRootNode(SiteId);

            BuiltCacheResultHandler <string> bh = () =>
            {
                var _treeHtml = "";
                var sb        = new StringBuilder();


                //var allCate = CmsLogic.Category.GetCategories();

                sb.Append(
                    "<dl><dt class=\"tree-title\"><img src=\"/public/mui/css/old/sys_themes/default/icon_trans.png\" width=\"24\" height=\"24\" class=\"tree-title\"/>")
                .Append(CurrentSite.Name ?? "默认站点").Append("</dt>");


                //从根目录起循环
                ServiceCall.Instance.SiteService.ItrCategoryTree(sb, SiteId, 1);

                //ItrTree(CmsLogic.Category.Root, sb,siteID);


                sb.Append("</dl>");

                _treeHtml = sb.ToString();


                _treeHtml = Regex.Replace(_treeHtml, "(<img[^>]+>)+<span([^>]+)>([^<]+)</span></dd></dl>", m =>
                {
                    var returnStr = m.Value.Replace("tree-item", "tree-item-last");

                    var mcs = Regex.Matches(m.Value, "<img class=\"tree-line\"[^>]+>");
                    if (mcs.Count > 0)
                    {
                        //returnStr = returnStr.Replace(mcs[mcs.Count - 1].Value, mcs[mcs.Count - 1].Value.Replace("tree-line", "tree-line-last"));
                    }

                    return(returnStr);
                });

                return(_treeHtml);
            };


            try
            {
                var json = JsonSerializer.Serialize(node);

                /*
                 * string treeHtml = CacheFactory.Singleton.GetResult<String>(
                 *  String.Format("{0}_{1}_admin_tree", CacheSign.Category.ToString(), this.SiteId.ToString()),
                 *  bh);
                 */

                RenderTemplate(ResourceMap.GetPageContent(ManagementPage.Category_LeftBar_Tree), new
                {
                    tree    = json,
                    treeFor = Request.Query("for")
                });
            }
            catch (Exception exc)
            {
                Response.WriteAsync("<script>parent.M.alert('站点栏目异常!这可能是由于数据不正确导致。<br />具体错误信息:");
                Response.WriteAsync(exc.Message);
                Response.WriteAsync("')</script>");
            }
        }
Exemplo n.º 7
0
 public T GetResult <T>(string cacheKey, BuiltCacheResultHandler <T> func)
 {
     return(GetCacheResult <T>(cacheKey, func, false));
 }