diff --git a/Bootstrap.DataAccess.SQLite/Exceptions.cs b/Bootstrap.DataAccess.SQLite/Exceptions.cs
index b7deceba..b904a49f 100644
--- a/Bootstrap.DataAccess.SQLite/Exceptions.cs
+++ b/Bootstrap.DataAccess.SQLite/Exceptions.cs
@@ -56,7 +56,7 @@ namespace Bootstrap.DataAccess.SQLite
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
- CacheManager.Clear(RetrieveExceptionsDataKey);
+ CacheManager.Clear(ExceptionsHelper.RetrieveExceptionsDataKey);
ClearExceptions();
}
}
@@ -66,31 +66,28 @@ namespace Bootstrap.DataAccess.SQLite
///
public override IEnumerable RetrieveExceptions()
{
- return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
+ string sql = "select * from Exceptions where LogTime > datetime('now', 'localtime', '-7 day') order by LogTime desc";
+ List exceptions = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select * from Exceptions where LogTime > datetime('now', 'localtime', '-7 day') order by LogTime desc";
- List exceptions = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ exceptions.Add(new Exceptions()
{
- exceptions.Add(new Exceptions()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- AppDomainName = (string)reader[1],
- ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
- UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
- UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
- ExceptionType = (string)reader[5],
- Message = (string)reader[6],
- StackTrace = (string)reader[7],
- LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue)
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ AppDomainName = (string)reader[1],
+ ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
+ UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
+ UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
+ ExceptionType = (string)reader[5],
+ Message = (string)reader[6],
+ StackTrace = (string)reader[7],
+ LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue)
+ });
}
- return exceptions;
- });
+ }
+ return exceptions;
}
}
}
diff --git a/Bootstrap.DataAccess.SQLite/Log.cs b/Bootstrap.DataAccess.SQLite/Log.cs
index b4aa4d38..5ed0a37d 100644
--- a/Bootstrap.DataAccess.SQLite/Log.cs
+++ b/Bootstrap.DataAccess.SQLite/Log.cs
@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
-using System.Linq;
namespace Bootstrap.DataAccess.SQLite
{
@@ -21,30 +20,26 @@ namespace Bootstrap.DataAccess.SQLite
///
public override IEnumerable RetrieveLogs(string tId = null)
{
- var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
+ string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')";
+ List logs = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')";
- List logs = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ logs.Add(new Log()
{
- logs.Add(new Log()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- CRUD = (string)reader[1],
- UserName = (string)reader[2],
- LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
- ClientIp = (string)reader[4],
- ClientAgent = (string)reader[5],
- RequestUrl = (string)reader[6]
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ CRUD = (string)reader[1],
+ UserName = (string)reader[2],
+ LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
+ ClientIp = (string)reader[4],
+ ClientAgent = (string)reader[5],
+ RequestUrl = (string)reader[6]
+ });
}
- return logs;
- });
- return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
+ }
+ return logs;
}
///
/// 删除日志信息
@@ -79,7 +74,7 @@ namespace Bootstrap.DataAccess.SQLite
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
- CacheManager.Clear(RetrieveLogsDataKey);
+ CacheManager.Clear(LogHelper.RetrieveLogsDataKey);
DeleteLogAsync();
return ret;
}
diff --git a/Bootstrap.DataAccess.SQLite/Message.cs b/Bootstrap.DataAccess.SQLite/Message.cs
index cc4db2e8..7d1c76fa 100644
--- a/Bootstrap.DataAccess.SQLite/Message.cs
+++ b/Bootstrap.DataAccess.SQLite/Message.cs
@@ -1,10 +1,8 @@
using Longbow;
-using Longbow.Cache;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
-using System.Linq;
namespace Bootstrap.DataAccess.SQLite
{
@@ -20,38 +18,33 @@ namespace Bootstrap.DataAccess.SQLite
///
protected override IEnumerable RetrieveMessages(string userName)
{
- var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key =>
+ string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
+ List messages = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
- List messages = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ messages.Add(new Message()
{
- messages.Add(new Message()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- Title = (string)reader[1],
- Content = (string)reader[2],
- From = (string)reader[3],
- To = (string)reader[4],
- SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
- Status = (string)reader[6],
- Mark = LgbConvert.ReadValue(reader[7], 0),
- IsDelete = LgbConvert.ReadValue(reader[8], 0),
- Label = (string)reader[9],
- LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
- FromIcon = (string)reader[11],
- FromDisplayName = (string)reader[12]
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ Title = (string)reader[1],
+ Content = (string)reader[2],
+ From = (string)reader[3],
+ To = (string)reader[4],
+ SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
+ Status = (string)reader[6],
+ Mark = LgbConvert.ReadValue(reader[7], 0),
+ IsDelete = LgbConvert.ReadValue(reader[8], 0),
+ Label = (string)reader[9],
+ LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
+ FromIcon = (string)reader[11],
+ FromDisplayName = (string)reader[12]
+ });
}
- return messages;
-
- });
- return messageRet.OrderByDescending(n => n.SendTime);
+ }
+ return messages;
}
}
}
diff --git a/Bootstrap.DataAccess.SQLite/Task.cs b/Bootstrap.DataAccess.SQLite/Task.cs
index f3b30ccf..a0924560 100644
--- a/Bootstrap.DataAccess.SQLite/Task.cs
+++ b/Bootstrap.DataAccess.SQLite/Task.cs
@@ -1,5 +1,4 @@
using Longbow;
-using Longbow.Cache;
using System;
using System.Collections.Generic;
using System.Data;
@@ -15,30 +14,27 @@ namespace Bootstrap.DataAccess.SQLite
///
public override IEnumerable RetrieveTasks()
{
- return CacheManager.GetOrAdd(RetrieveTasksDataKey, key =>
+ string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000";
+ List tasks = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000";
- List tasks = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ tasks.Add(new Task()
{
- tasks.Add(new Task()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- TaskName = (string)reader[1],
- AssignName = (string)reader[2],
- UserName = (string)reader[3],
- TaskTime = LgbConvert.ReadValue(reader[4], 0),
- TaskProgress = (double)reader[5],
- AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue),
- AssignDisplayName = (string)reader[7]
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ TaskName = (string)reader[1],
+ AssignName = (string)reader[2],
+ UserName = (string)reader[3],
+ TaskTime = LgbConvert.ReadValue(reader[4], 0),
+ TaskProgress = (double)reader[5],
+ AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue),
+ AssignDisplayName = (string)reader[7]
+ });
}
- return tasks;
- });
+ }
+ return tasks;
}
}
}
diff --git a/Bootstrap.DataAccess.SQLite/User.cs b/Bootstrap.DataAccess.SQLite/User.cs
index f3d34034..920e8b6b 100644
--- a/Bootstrap.DataAccess.SQLite/User.cs
+++ b/Bootstrap.DataAccess.SQLite/User.cs
@@ -1,5 +1,4 @@
using Bootstrap.Security;
-using Longbow.Cache;
using Longbow.Data;
using Longbow.Security.Cryptography;
using System;
@@ -8,7 +7,6 @@ using System.Data;
using System.Data.Common;
using System.Linq;
-
namespace Bootstrap.DataAccess.SQLite
{
///
@@ -245,29 +243,25 @@ namespace Bootstrap.DataAccess.SQLite
///
public override BootstrapUser RetrieveUserByUserName(string userName)
{
- var key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
- return CacheManager.GetOrAdd(key, k =>
+ BootstrapUser user = null;
+ var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName";
+ var db = DbAccessManager.DBAccess;
+ var cmd = db.CreateCommand(CommandType.Text, sql);
+ cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
+ using (DbDataReader reader = db.ExecuteReader(cmd))
{
- BootstrapUser user = null;
- var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName";
- var db = DbAccessManager.DBAccess;
- var cmd = db.CreateCommand(CommandType.Text, sql);
- cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
- using (DbDataReader reader = db.ExecuteReader(cmd))
+ if (reader.Read())
{
- if (reader.Read())
+ user = new BootstrapUser
{
- user = new BootstrapUser
- {
- UserName = (string)reader[0],
- DisplayName = (string)reader[1],
- Icon = (string)reader[2],
- Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
- };
- }
+ UserName = (string)reader[0],
+ DisplayName = (string)reader[1],
+ Icon = (string)reader[2],
+ Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
+ };
}
- return user;
- }, RetrieveUsersByNameDataKey);
+ }
+ return user;
}
}
}
diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs
index 9795104f..a40e20da 100644
--- a/Bootstrap.DataAccess/CacheCleanUtility.cs
+++ b/Bootstrap.DataAccess/CacheCleanUtility.cs
@@ -27,54 +27,54 @@ namespace Bootstrap.DataAccess
{
roleIds.ToList().ForEach(id =>
{
- cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByRoleIdDataKey, id));
- cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByRoleIdDataKey, id));
- cacheKeys.Add(string.Format("{0}-{1}", Menu.RetrieveMenusByRoleIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id));
});
- cacheKeys.Add(Role.RetrieveRolesDataKey + "*");
- cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
+ cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
+ cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
- corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
+ corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
}
if (userIds != null)
{
userIds.ToList().ForEach(id =>
{
- cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByUserIdDataKey, id));
- cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByUserIdDataKey, id));
- cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
- corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
+ cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
+ cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
+ corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
});
- cacheKeys.Add(User.RetrieveNewUsersDataKey + "*");
- cacheKeys.Add(User.RetrieveUsersDataKey + "*");
- corsKeys.Add(User.RetrieveUsersDataKey + "*");
+ cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
+ cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
+ corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
}
if (groupIds != null)
{
groupIds.ToList().ForEach(id =>
{
- cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByGroupIdDataKey, id));
- cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByGroupIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
});
- cacheKeys.Add(Group.RetrieveGroupsDataKey + "*");
- cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
- corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
+ cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
+ cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
+ corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
}
if (menuIds != null)
{
menuIds.ToList().ForEach(id =>
{
- cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByMenuIdDataKey, id));
+ cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
});
- cacheKeys.Add(Menu.RetrieveMenusByRoleIdDataKey + "*");
- cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
- corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
+ cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
+ cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
+ corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
}
if (dictIds != null)
{
cacheKeys.Add(Dict.RetrieveDictsDataKey + "*");
- cacheKeys.Add(Dict.RetrieveCategoryDataKey);
+ cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
corsKeys.Add(Dict.RetrieveDictsDataKey + "*");
}
if (cacheKey != null)
diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs
index 222e66c6..f6ec7bb1 100644
--- a/Bootstrap.DataAccess/Dict.cs
+++ b/Bootstrap.DataAccess/Dict.cs
@@ -1,6 +1,5 @@
using Bootstrap.Security;
using Bootstrap.Security.SQLServer;
-using Longbow.Cache;
using System;
using System.Collections.Generic;
using System.Data;
@@ -17,7 +16,6 @@ namespace Bootstrap.DataAccess
///
///
///
- public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
///
/// 缓存索引,BootstrapAdmin后台清理缓存时使用
///
@@ -92,20 +90,17 @@ namespace Bootstrap.DataAccess
///
public virtual IEnumerable RetrieveCategories()
{
- return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
+ var ret = new List();
+ string sql = "select distinct Category from Dicts";
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- var ret = new List();
- string sql = "select distinct Category from Dicts";
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
- {
- ret.Add((string)reader[0]);
- }
+ ret.Add((string)reader[0]);
}
- return ret;
- });
+ }
+ return ret;
}
///
///
diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs
index 477d23c8..1e0dd920 100644
--- a/Bootstrap.DataAccess/Exceptions.cs
+++ b/Bootstrap.DataAccess/Exceptions.cs
@@ -14,10 +14,6 @@ namespace Bootstrap.DataAccess
///
public class Exceptions
{
- ///
- ///
- ///
- protected const string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions";
///
///
///
@@ -97,7 +93,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
- CacheManager.Clear(RetrieveExceptionsDataKey);
+ CacheManager.Clear(ExceptionsHelper.RetrieveExceptionsDataKey);
ClearExceptions();
}
}
@@ -107,31 +103,28 @@ namespace Bootstrap.DataAccess
///
public virtual IEnumerable RetrieveExceptions()
{
- return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
+ string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
+ List exceptions = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
- List exceptions = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ exceptions.Add(new Exceptions()
{
- exceptions.Add(new Exceptions()
- {
- Id = (int)reader[0],
- AppDomainName = (string)reader[1],
- ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
- UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
- UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
- ExceptionType = (string)reader[5],
- Message = (string)reader[6],
- StackTrace = (string)reader[7],
- LogTime = (DateTime)reader[8],
- });
- }
+ Id = (int)reader[0],
+ AppDomainName = (string)reader[1],
+ ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
+ UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
+ UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
+ ExceptionType = (string)reader[5],
+ Message = (string)reader[6],
+ StackTrace = (string)reader[7],
+ LogTime = (DateTime)reader[8],
+ });
}
- return exceptions;
- });
+ }
+ return exceptions;
}
}
}
diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs
index dd465c30..91075a6d 100644
--- a/Bootstrap.DataAccess/Group.cs
+++ b/Bootstrap.DataAccess/Group.cs
@@ -1,5 +1,4 @@
using Longbow;
-using Longbow.Cache;
using Longbow.Data;
using System;
using System.Collections.Generic;
@@ -15,10 +14,6 @@ namespace Bootstrap.DataAccess
///
public class Group
{
- public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups";
- public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId";
- public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId";
- public const string RetrieveGroupsByUserNameDataKey = "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName";
///
/// 获得/设置 群组主键ID
///
@@ -45,26 +40,22 @@ namespace Bootstrap.DataAccess
///
public virtual IEnumerable RetrieveGroups(int id = 0)
{
- var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
+ string sql = "select * from Groups";
+ List groups = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select * from Groups";
- List groups = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ groups.Add(new Group()
{
- groups.Add(new Group()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- GroupName = (string)reader[1],
- Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ GroupName = (string)reader[1],
+ Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
+ });
}
- return groups;
- });
- return id == 0 ? ret : ret.Where(t => id == t.Id);
+ }
+ return groups;
}
///
/// 删除群组信息
@@ -112,29 +103,24 @@ namespace Bootstrap.DataAccess
///
public virtual IEnumerable RetrieveGroupsByUserId(int userId)
{
- string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
- var ret = CacheManager.GetOrAdd(key, k =>
+ string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
+ List groups = new List();
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
- List groups = new List();
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ groups.Add(new Group()
{
- groups.Add(new Group()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- GroupName = (string)reader[1],
- Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
- Checked = (string)reader[3]
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ GroupName = (string)reader[1],
+ Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
+ Checked = (string)reader[3]
+ });
}
- return groups;
- }, RetrieveGroupsByUserIdDataKey);
- return ret;
+ }
+ return groups;
}
///
/// 保存用户部门关系
@@ -189,28 +175,24 @@ namespace Bootstrap.DataAccess
///
public virtual IEnumerable RetrieveGroupsByRoleId(int roleId)
{
- string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
- return CacheManager.GetOrAdd(k, key =>
+ List groups = new List();
+ string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
+ DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
+ cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
+ using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
- List groups = new List();
- string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
- DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
- cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
- using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
+ groups.Add(new Group()
{
- groups.Add(new Group()
- {
- Id = LgbConvert.ReadValue(reader[0], 0),
- GroupName = (string)reader[1],
- Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
- Checked = (string)reader[3]
- });
- }
+ Id = LgbConvert.ReadValue(reader[0], 0),
+ GroupName = (string)reader[1],
+ Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
+ Checked = (string)reader[3]
+ });
}
- return groups;
- }, RetrieveGroupsByRoleIdDataKey);
+ }
+ return groups;
}
///
/// 根据角色ID以及选定的部门ID,保到角色部门表
@@ -260,27 +242,23 @@ namespace Bootstrap.DataAccess
///
///
///
- ///
///
public virtual IEnumerable RetrieveGroupsByUserName(string userName)
{
- return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r =>
+ var entities = new List();
+ var db = DbAccessManager.DBAccess;
+ using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName"))
{
- var entities = new List();
- var db = DbAccessManager.DBAccess;
- using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName"))
+ cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
+ using (DbDataReader reader = db.ExecuteReader(cmd))
{
- cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
- using (DbDataReader reader = db.ExecuteReader(cmd))
+ while (reader.Read())
{
- while (reader.Read())
- {
- entities.Add((string)reader[0]);
- }
+ entities.Add((string)reader[0]);
}
}
- return entities;
- }, RetrieveGroupsByUserNameDataKey);
+ }
+ return entities;
}
}
}
diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs
index 1d23e168..b3a98c5c 100644
--- a/Bootstrap.DataAccess/Helper/DictHelper.cs
+++ b/Bootstrap.DataAccess/Helper/DictHelper.cs
@@ -1,4 +1,5 @@
using Bootstrap.Security;
+using Longbow.Cache;
using Longbow.Data;
using System.Collections.Generic;
@@ -9,6 +10,7 @@ namespace Bootstrap.DataAccess
///
public static class DictHelper
{
+ public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
///
///
///
@@ -38,7 +40,7 @@ namespace Bootstrap.DataAccess
/// 获取字典分类名称
///
///
- public static IEnumerable RetrieveCategories() => DbAdapterManager.Create().RetrieveCategories();
+ public static IEnumerable RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbAdapterManager.Create().RetrieveCategories());
///
///
///
diff --git a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs
index 363a9754..85e7ec3e 100644
--- a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs
+++ b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs
@@ -1,4 +1,5 @@
-using Longbow.Data;
+using Longbow.Cache;
+using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -10,6 +11,10 @@ namespace Bootstrap.DataAccess
///
public static class ExceptionsHelper
{
+ ///
+ ///
+ ///
+ public const string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions";
///
///
///
@@ -21,6 +26,6 @@ namespace Bootstrap.DataAccess
/// 查询一周内所有异常
///
///
- public static IEnumerable RetrieveExceptions() => DbAdapterManager.Create().RetrieveExceptions();
+ public static IEnumerable RetrieveExceptions() => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbAdapterManager.Create().RetrieveExceptions());
}
}
diff --git a/Bootstrap.DataAccess/Helper/GroupHelper.cs b/Bootstrap.DataAccess/Helper/GroupHelper.cs
index 8aec4d4c..1a296e07 100644
--- a/Bootstrap.DataAccess/Helper/GroupHelper.cs
+++ b/Bootstrap.DataAccess/Helper/GroupHelper.cs
@@ -1,20 +1,30 @@
-using Longbow.Data;
+using Longbow.Cache;
+using Longbow.Data;
using System.Collections.Generic;
+using System.Linq;
namespace Bootstrap.DataAccess
{
///
- /// author:liuchun
- /// date:2016.10.22
+ ///
///
public static class GroupHelper
{
+ public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups";
+ public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId";
+ public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId";
+ public const string RetrieveGroupsByUserNameDataKey = "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName";
///
/// 查询所有群组信息
///
///
///
- public static IEnumerable RetrieveGroups(int id = 0) => DbAdapterManager.Create().RetrieveGroups(id);
+ public static IEnumerable RetrieveGroups(int id = 0)
+ {
+ var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create().RetrieveGroups(id));
+ return id == 0 ? ret : ret.Where(t => id == t.Id);
+ }
+
///
/// 删除群组信息
///
@@ -31,7 +41,8 @@ namespace Bootstrap.DataAccess
///
///
///
- public static IEnumerable RetrieveGroupsByUserId(int userId) => DbAdapterManager.Create().RetrieveGroupsByUserId(userId);
+ public static IEnumerable RetrieveGroupsByUserId(int userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey);
+
///
/// 保存用户部门关系
///
@@ -44,7 +55,7 @@ namespace Bootstrap.DataAccess
///
///
///
- public static IEnumerable RetrieveGroupsByRoleId(int roleId) => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId);
+ public static IEnumerable RetrieveGroupsByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey);
///
/// 根据角色ID以及选定的部门ID,保到角色部门表
///
@@ -52,5 +63,11 @@ namespace Bootstrap.DataAccess
///
///
public static bool SaveGroupsByRoleId(int id, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByRoleId(id, groupIds);
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IEnumerable RetrieveGroupsByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbAdapterManager.Create().RetrieveGroupsByUserName(userName), RetrieveGroupsByUserNameDataKey);
}
}
diff --git a/Bootstrap.DataAccess/Helper/LogHelper.cs b/Bootstrap.DataAccess/Helper/LogHelper.cs
index 9de1770b..1acff065 100644
--- a/Bootstrap.DataAccess/Helper/LogHelper.cs
+++ b/Bootstrap.DataAccess/Helper/LogHelper.cs
@@ -1,16 +1,30 @@
-using Longbow.Data;
+using Longbow.Cache;
+using Longbow.Data;
+using System;
using System.Collections.Generic;
+using System.Linq;
namespace Bootstrap.DataAccess
{
+ ///
+ ///
+ ///
public static class LogHelper
{
+ ///
+ ///
+ ///
+ public const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs";
///
/// 查询所有日志信息
///
///
///
- public static IEnumerable RetrieveLogs(string tId = null) => DbAdapterManager.Create().RetrieveLogs(tId);
+ public static IEnumerable RetrieveLogs(string tId = null)
+ {
+ var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create().RetrieveLogs(tId));
+ return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
+ }
///
/// 保存新增的日志信息
///
diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs
index 3db2e986..9eec85aa 100644
--- a/Bootstrap.DataAccess/Helper/MenuHelper.cs
+++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs
@@ -1,4 +1,5 @@
using Bootstrap.Security;
+using Longbow.Cache;
using Longbow.Data;
using System.Collections.Generic;
@@ -9,6 +10,18 @@ namespace Bootstrap.DataAccess
///
public static class MenuHelper
{
+ ///
+ ///
+ ///
+ public const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId";
+ ///
+ ///
+ ///
+ public const string RetrieveMenusDataKey = "BootstrapMenu-RetrieveMenusByUserName";
+ ///
+ ///
+ ///
+ public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus";
///
///
///
@@ -30,9 +43,12 @@ namespace Bootstrap.DataAccess
///
///
///
- ///
+ ///
///
- public static IEnumerable RetrieveMenusByRoleId(int id) => DbAdapterManager.Create