diff --git a/Bootstrap.Admin/Controllers/DictsController.cs b/Bootstrap.Admin/Controllers/DictsController.cs index d7824ca8..d9266630 100644 --- a/Bootstrap.Admin/Controllers/DictsController.cs +++ b/Bootstrap.Admin/Controllers/DictsController.cs @@ -1,5 +1,6 @@ using Bootstrap.Admin.Models; using Bootstrap.DataAccess; +using Bootstrap.Security; using Longbow.Security.Principal; using Longbow.Web.Mvc; using Newtonsoft.Json.Linq; @@ -17,7 +18,7 @@ namespace Bootstrap.Admin.Controllers /// /// [HttpGet] - public QueryData Get([FromUri]QueryDictOption value) + public QueryData Get([FromUri]QueryDictOption value) { return value.RetrieveData(); } @@ -27,7 +28,7 @@ namespace Bootstrap.Admin.Controllers /// /// [HttpGet] - public Dict Get(int id) + public BootstrapDict Get(int id) { return DictHelper.RetrieveDicts().FirstOrDefault(t => t.Id == id); } @@ -36,7 +37,7 @@ namespace Bootstrap.Admin.Controllers /// /// [HttpPost] - public bool Post([FromBody]Dict value) + public bool Post([FromBody]BootstrapDict value) { return DictHelper.SaveDict(value); } @@ -46,9 +47,9 @@ namespace Bootstrap.Admin.Controllers /// [HttpPost] [AllowAnonymous] - public IEnumerable Post(int id, [FromBody]JObject value) + public IEnumerable Post(int id, [FromBody]JObject value) { - IEnumerable ret = new List(); + IEnumerable ret = new List(); dynamic json = value; switch ((string)json.type) { diff --git a/Bootstrap.Admin/Models/QueryDictOption.cs b/Bootstrap.Admin/Models/QueryDictOption.cs index 1eb49ee4..ce1af316 100644 --- a/Bootstrap.Admin/Models/QueryDictOption.cs +++ b/Bootstrap.Admin/Models/QueryDictOption.cs @@ -1,4 +1,5 @@ using Bootstrap.DataAccess; +using Bootstrap.Security; using Longbow.Web.Mvc; using System.Linq; @@ -22,7 +23,7 @@ namespace Bootstrap.Admin.Models /// 字典表查询 /// /// - public QueryData RetrieveData() + public QueryData RetrieveData() { var data = DictHelper.RetrieveDicts(); if (!string.IsNullOrEmpty(Category)) @@ -37,7 +38,7 @@ namespace Bootstrap.Admin.Models { data = data.Where(t => t.Define.ToString() == Define); } - var ret = new QueryData(); + var ret = new QueryData(); ret.total = data.Count(); // 通过option.Sort属性判断对那列进行排序 switch (Sort) diff --git a/Bootstrap.Admin/Web.config b/Bootstrap.Admin/Web.config index 39cec93f..2b2b3b1b 100644 --- a/Bootstrap.Admin/Web.config +++ b/Bootstrap.Admin/Web.config @@ -48,8 +48,11 @@ + + + diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 504c03f7..a14e2bb4 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -59,7 +59,6 @@ - diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index f0bc968c..e5935fb1 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -1,4 +1,5 @@ -using Longbow.Caching.Configuration; +using Longbow.Caching; +using Longbow.Caching.Configuration; using Longbow.ExceptionManagement; using System; using System.Collections.Generic; @@ -79,16 +80,16 @@ namespace Bootstrap.DataAccess cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*"); } - var section = CacheListSection.GetSection(); - section.Items.Where(item => item.Enabled).AsParallel().ForAll(ele => + cacheKeys.AsParallel().ForAll(key => CacheManager.Clear(k => key.EndsWith("*") ? k.Contains(key.TrimEnd('*')) : k.Equals(key))); + System.Threading.Tasks.Task.Factory.StartNew(() => { - System.Threading.Tasks.Task.Factory.StartNew(() => + var section = CacheListSection.GetSection(); + section.Items.Where(item => item.Enabled).Skip(1).AsParallel().ForAll(ele => { try { var client = new WebClient(); cacheKeys.ForEach(k => client.OpenRead(new Uri(string.Format(ele.Url, k)))); - } catch (Exception ex) { diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs deleted file mode 100644 index 3f56bb7b..00000000 --- a/Bootstrap.DataAccess/Dict.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Bootstrap.DataAccess -{ - /// - /// 字典表实体 - /// - public class Dict - { - /// - /// 字典主键 数据库自增 - /// - public int Id { get; set; } - /// - /// 分类 - /// - public string Category { get; set; } - /// - /// 名称 - /// - public string Name { get; set; } - /// - /// 代号 - /// - public string Code { get; set; } - /// - /// 1表示系统使用,0表示用户自定义 默认为1 - /// - public int Define { get; set; } - } -} diff --git a/Bootstrap.DataAccess/DictHelper.cs b/Bootstrap.DataAccess/DictHelper.cs index 4aa4eecd..4054ff02 100644 --- a/Bootstrap.DataAccess/DictHelper.cs +++ b/Bootstrap.DataAccess/DictHelper.cs @@ -1,4 +1,5 @@ -using Longbow.Caching; +using Bootstrap.Security; +using Longbow.Caching; using Longbow.Caching.Configuration; using Longbow.ExceptionManagement; using System; @@ -15,39 +16,18 @@ namespace Bootstrap.DataAccess /// public static class DictHelper { + /// + /// + /// internal const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts"; private const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; /// - /// 查询所有字典信息 + /// /// /// - public static IEnumerable RetrieveDicts() + public static IEnumerable RetrieveDicts() { - return CacheManager.GetOrAdd(RetrieveDictsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveDictsDataKey), key => - { - string sql = "select ID, Category, Name, Code, Define from Dicts"; - List dicts = new List(); - DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); - try - { - using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - dicts.Add(new Dict() - { - Id = (int)reader[0], - Category = (string)reader[1], - Name = (string)reader[2], - Code = (string)reader[3], - Define = (int)reader[4] - }); - } - } - } - catch (Exception ex) { ExceptionManager.Publish(ex); } - return dicts; - }, CacheSection.RetrieveDescByKey(RetrieveDictsDataKey)); + return BootstrapDict.RetrieveDicts(); } /// /// 删除字典中的数据 @@ -80,7 +60,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveDict(Dict p) + public static bool SaveDict(BootstrapDict p) { bool ret = false; if (p.Category.Length > 50) p.Category = p.Category.Substring(0, 50); @@ -129,7 +109,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", category)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } - CacheManager.Clear(key => key.Contains(RetrieveDictsDataKey)); + CacheCleanUtility.ClearCache(dictIds: string.Empty); ret = true; } catch (DbException ex) @@ -142,11 +122,11 @@ namespace Bootstrap.DataAccess /// 获取字典分类名称 /// /// - public static IEnumerable RetrieveCategories() + public static IEnumerable RetrieveCategories() { return CacheManager.GetOrAdd(RetrieveCategoryDataKey, CacheSection.RetrieveIntervalByKey(RetrieveCategoryDataKey), key => { - var ret = new List(); + var ret = new List(); string sql = "select distinct Category from Dicts"; DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); try @@ -155,7 +135,7 @@ namespace Bootstrap.DataAccess { while (reader.Read()) { - ret.Add(new Dict() { Category = (string)reader[0] }); + ret.Add(new BootstrapDict() { Category = (string)reader[0] }); } } } @@ -170,7 +150,7 @@ namespace Bootstrap.DataAccess public static string RetrieveWebTitle() { var settings = RetrieveDicts(); - return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "后台管理系统" }).Code; + return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code; } /// /// @@ -179,13 +159,13 @@ namespace Bootstrap.DataAccess public static string RetrieveWebFooter() { var settings = RetrieveDicts(); - return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "2016 © 通用后台管理系统" }).Code; + return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code; } /// /// /// /// - public static IEnumerable RetrieveWebCss() + public static IEnumerable RetrieveWebCss() { var data = RetrieveDicts(); return data.Where(d => d.Category == "网站样式"); @@ -194,7 +174,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveActiveCss() + public static IEnumerable RetrieveActiveCss() { var data = RetrieveDicts(); return data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0 && !d.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase)); @@ -203,10 +183,10 @@ namespace Bootstrap.DataAccess /// 获取头像路径 /// /// - public static Dict RetrieveIconFolderPath() + public static BootstrapDict RetrieveIconFolderPath() { var data = RetrieveDicts(); - return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new Dict() { Code = "~/Content/images/uploader/" }; + return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Content/images/uploader/" }; } /// /// 获得默认的前台首页地址,默认为~/Home/Index @@ -215,7 +195,7 @@ namespace Bootstrap.DataAccess public static string RetrieveHomeUrl() { var settings = RetrieveDicts(); - return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "~/Home/Index" }).Code; + return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code; } /// ///