예제 #1
0
 public void bindCbbExitsTemplate()
 {
     cbb_exitsTemplate.SelectedIndexChanged -= cbb_exitsTemplate_SelectedIndexChanged;
     templateList = TemplateCache.getCache().Where(t => t.classId == cbb_classId).ToList();
     cbb_exitsTemplate.DisplayMember         = "templateName";
     cbb_exitsTemplate.ValueMember           = "id";
     cbb_exitsTemplate.DataSource            = templateList;
     cbb_exitsTemplate.SelectedValue         = 0;
     cbb_exitsTemplate.SelectedIndexChanged += cbb_exitsTemplate_SelectedIndexChanged;
 }
예제 #2
0
        /// <summary>
        /// 获取模板页面
        /// </summary>
        /// <param name="tempate"></param>
        /// <returns></returns>
        protected string getTemplate()
        {
            string html = null;

            this.ViewBag.parms = this.RouteData.DataTokens;

            #region 模板
            string template = "index.cshtml";
            //模板
            object viewTemp = null;
            this.RouteData.Values.TryGetValue("view", out viewTemp);
            if (viewTemp != null)
            {
                template = viewTemp.ToString();
            }
            bool isWap        = false;
            var  templatePath = string.Format("~/views/{0}/", this.config.Home);
            if (Fetch.isMobile() && this.config.EnabledWap)
            {
                if (Fetch.fileExist(Fetch.getMapPath(templatePath + template.Replace(".cshtml", ".mobile.cshtml"))))
                {
                    template = template.Replace(".cshtml", ".mobile.cshtml");
                    isWap    = true;
                }
            }
            templatePath += template;
            #endregion

            if (this.RouteData.Values.ContainsKey("cachetime"))
            {
                var cachetime = this.RouteData.Values["cachetime"];
                int cache     = (int)cachetime;
                if (cache > 0)
                {
                    string cacheKey = Fetch.getRawUrl().ToLower();
                    html = TemplateCache.getCache(cacheKey, cache, isWap);
                    if (html == null)
                    {
                        html = getHTML(templatePath);
                        TemplateCache.setCache(cacheKey, html, cache, isWap);
                    }
                }
            }

            if (html == null)
            {
                html = getHTML(templatePath);
            }
            return(html);
        }
예제 #3
0
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public JsonResult getCache(string key)
        {
            ///缓存文件夹
            var cachePath = this.config.SitePath + "cache/";

            if (!string.IsNullOrEmpty(key))
            {
                cachePath += Utils.replace(key, "__", "/") + "/";
            }
            string template = Fetch.getMapPath(cachePath);

            var cacheList = new List <Entity.CacheFileInfo>();

            if (Directory.Exists(template))
            {
                //目录
                var directionList = new DirectoryInfo(template).GetDirectories();
                if (directionList != null && directionList.Count() > 0)
                {
                    foreach (var dir in directionList)
                    {
                        cacheList.Add(new Entity.CacheFileInfo()
                        {
                            Cachekey  = dir.Name,
                            CacheType = 0,
                            Size      = ""
                        });
                    }
                }

                //缓存文件
                var fileList = new DirectoryInfo(template).GetFiles("*.cshtml");
                if (fileList != null && fileList.Count() > 0)
                {
                    foreach (var file in fileList)
                    {
                        cacheList.Add(new Entity.CacheFileInfo()
                        {
                            Cachekey  = file.Name,
                            CacheType = 1,
                            Size      = (file.Length / 1024).ToString("0.00K")
                        });
                    }
                }
            }

            if (string.IsNullOrEmpty(key))
            {
                //字典缓存
                var cachelist = TemplateCache.getCache();

                if (cachelist != null && cachelist.Count() > 0)
                {
                    foreach (var cache in cachelist)
                    {
                        cacheList.Add(new Entity.CacheFileInfo()
                        {
                            Cachekey  = cache.Key,
                            CacheType = 2,
                            Size      = (Encoding.Default.GetByteCount(cache.Value.CacheContent) / 1024).ToString("0.00K")
                        });
                    }
                }
            }
            return(this.getResult(Entity.Error.请求成功, "请求成功", cacheList));
        }