diff --git a/Bootstrap.Admin/appsettings.Development.json b/Bootstrap.Admin/appsettings.Development.json
index 7f0e4a37..c0f1015d 100644
--- a/Bootstrap.Admin/appsettings.Development.json
+++ b/Bootstrap.Admin/appsettings.Development.json
@@ -26,14 +26,14 @@
"CorsItems": [
{
"Enabled": true,
- "Name": "ba",
+ "Key": "ba",
"Url": "CacheList.axd",
"Desc": "后台管理数据缓存接口",
"Self": true
},
{
"Enabled": true,
- "Name": "APP",
+ "Key": "APP",
"Url": "http://localhost:49185/CacheList.axd",
"Desc": "测试系统",
"Self": false
diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json
index c9261eac..a7b799be 100644
--- a/Bootstrap.Admin/appsettings.json
+++ b/Bootstrap.Admin/appsettings.json
@@ -15,22 +15,21 @@
"ConnectionStrings": {
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
},
+ "MongoDB": "BootstrapAdmin",
"DB": [
{
"Enabled": true
},
{
"Enabled": true,
- "Widget": "Bootstrap.DataAccess.MySQL",
- "DBProviderFactory": "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data",
+ "ProviderName": "MySql",
"ConnectionStrings": {
"ba": "Server=10.211.55.2;Database=BA;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"
}
},
{
"Enabled": true,
- "Widget": "Bootstrap.DataAccess.SQLite",
- "DBProviderFactory": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite",
+ "ProviderName": "Sqlite",
"ConnectionStrings": {
"ba": "Data Source=BootstrapAdmin.db;"
}
@@ -39,7 +38,7 @@
"Enabled": true,
"Widget": "Bootstrap.DataAccess.MongoDB",
"ConnectionStrings": {
- "ba": "mongodb://10.211.55.2:27017;Data Source=BootstrapAdmin"
+ "ba": "mongodb://10.211.55.2:27017"
}
}
],
@@ -63,14 +62,14 @@
"CorsItems": [
{
"Enabled": true,
- "Name": "ba",
+ "Key": "ba",
"Url": "CacheList.axd",
"Desc": "后台管理数据缓存接口",
"Self": true
},
{
"Enabled": true,
- "Name": "Pallet",
+ "Key": "Pallet",
"Url": "http://localhost/WebConsole/CacheList.axd",
"Desc": "托盘组垛系统",
"Self": false
diff --git a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs b/Bootstrap.DataAccess.MongoDB/DbManager.cs
similarity index 90%
rename from Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs
rename to Bootstrap.DataAccess.MongoDB/DbManager.cs
index 99684f3e..fb3cc457 100644
--- a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs
+++ b/Bootstrap.DataAccess.MongoDB/DbManager.cs
@@ -5,15 +5,13 @@ using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
-using System;
-using System.Linq;
namespace Bootstrap.DataAccess.MongoDB
{
///
///
///
- public static class MongoDbAccessManager
+ internal static class DbManager
{
private static IMongoDatabase _db = null;
private static bool _register = false;
@@ -122,14 +120,8 @@ namespace Bootstrap.DataAccess.MongoDB
private static void InitDb()
{
- var connectString = DbAdapterManager.GetConnectionString("ba");
- if (string.IsNullOrEmpty(connectString)) throw new InvalidOperationException("Please set the BA default value in configuration file.");
-
- var seq = connectString.SpanSplit(";", StringSplitOptions.RemoveEmptyEntries);
- if (seq.Count != 2) throw new InvalidOperationException("ConnectionString invalid in configuration file. It should be mongodb://127.0.0.1:27017;Data Source=BootstrapAdmin");
-
- var client = new MongoClient(seq[0]);
- _db = client.GetDatabase(seq[1].SpanSplit("=", StringSplitOptions.RemoveEmptyEntries).LastOrDefault());
+ var client = new MongoClient(Longbow.Data.DbManager.GetConnectionString());
+ _db = client.GetDatabase(ConfigurationManager.AppSettings["MongoDB"]);
}
private static void InitClassMap()
diff --git a/Bootstrap.DataAccess.MongoDB/Dict.cs b/Bootstrap.DataAccess.MongoDB/Dict.cs
index 44bdc06c..61a45d77 100644
--- a/Bootstrap.DataAccess.MongoDB/Dict.cs
+++ b/Bootstrap.DataAccess.MongoDB/Dict.cs
@@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
///
///
- public override IEnumerable RetrieveDicts() => MongoDbAccessManager.Dicts.Find(FilterDefinition.Empty).ToList();
+ public override IEnumerable RetrieveDicts() => DbManager.Dicts.Find(FilterDefinition.Empty).ToList();
///
///
@@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
list.Add(new DeleteOneModel(Builders.Filter.Eq(md => md.Id, id)));
}
- MongoDbAccessManager.Dicts.BulkWrite(list);
+ DbManager.Dicts.BulkWrite(list);
return true;
}
@@ -42,12 +42,12 @@ namespace Bootstrap.DataAccess.MongoDB
if (p.Id == "0")
{
p.Id = null;
- MongoDbAccessManager.Dicts.InsertOne(p);
+ DbManager.Dicts.InsertOne(p);
return true;
}
else
{
- MongoDbAccessManager.Dicts.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Category, p.Category)
+ DbManager.Dicts.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Category, p.Category)
.Set(md => md.Define, p.Define)
.Set(md => md.Name, p.Name)
.Set(md => md.Code, p.Code));
@@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override bool SaveSettings(BootstrapDict dict)
{
- MongoDbAccessManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders.Update.Set(md => md.Code, dict.Code));
+ DbManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders.Update.Set(md => md.Code, dict.Code));
return true;
}
}
diff --git a/Bootstrap.DataAccess.MongoDB/Exceptions.cs b/Bootstrap.DataAccess.MongoDB/Exceptions.cs
index 8cb0570d..b126b2be 100644
--- a/Bootstrap.DataAccess.MongoDB/Exceptions.cs
+++ b/Bootstrap.DataAccess.MongoDB/Exceptions.cs
@@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
System.Threading.Tasks.Task.Run(() =>
{
- MongoDbAccessManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7));
+ DbManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7));
});
}
@@ -24,7 +24,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override IEnumerable Retrieves()
{
- return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
+ return DbManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
}
///
@@ -47,7 +47,7 @@ namespace Bootstrap.DataAccess.MongoDB
UserId = additionalInfo?["UserId"],
UserIp = additionalInfo?["UserIp"]
};
- MongoDbAccessManager.Exceptions.InsertOne(excep);
+ DbManager.Exceptions.InsertOne(excep);
ClearExceptions();
return true;
}
diff --git a/Bootstrap.DataAccess.MongoDB/Group.cs b/Bootstrap.DataAccess.MongoDB/Group.cs
index 1440b693..a0c61f9e 100644
--- a/Bootstrap.DataAccess.MongoDB/Group.cs
+++ b/Bootstrap.DataAccess.MongoDB/Group.cs
@@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override IEnumerable Retrieves()
{
- return MongoDbAccessManager.Groups.Find(FilterDefinition.Empty).ToList();
+ return DbManager.Groups.Find(FilterDefinition.Empty).ToList();
}
///
@@ -33,7 +33,7 @@ namespace Bootstrap.DataAccess.MongoDB
if (p.Id == "0")
{
p.Id = null;
- MongoDbAccessManager.Groups.InsertOne(new Group() {
+ DbManager.Groups.InsertOne(new Group() {
GroupName = p.GroupName,
Description = p.Description,
Roles = new List()
@@ -42,7 +42,7 @@ namespace Bootstrap.DataAccess.MongoDB
}
else
{
- MongoDbAccessManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.GroupName, p.GroupName).Set(md => md.Description, p.Description));
+ DbManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.GroupName, p.GroupName).Set(md => md.Description, p.Description));
return true;
}
}
@@ -59,7 +59,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
list.Add(new DeleteOneModel(Builders.Filter.Eq(g => g.Id, id)));
}
- MongoDbAccessManager.Groups.BulkWrite(list);
+ DbManager.Groups.BulkWrite(list);
return true;
}
@@ -84,7 +84,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override bool SaveByUserId(string userId, IEnumerable groupIds)
{
- MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Groups, groupIds));
+ DbManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Groups, groupIds));
return true;
}
@@ -108,23 +108,23 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override bool SaveByRoleId(string roleId, IEnumerable groupIds)
{
- var groups = MongoDbAccessManager.Groups.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList();
+ var groups = DbManager.Groups.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList();
// Remove roles
groups.ForEach(p =>
{
var roles = p.Roles == null ? new List() : p.Roles.ToList();
roles.Remove(roleId);
- MongoDbAccessManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles));
+ DbManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles));
});
- groups = MongoDbAccessManager.Groups.Find(md => groupIds.Contains(md.Id)).ToList();
+ groups = DbManager.Groups.Find(md => groupIds.Contains(md.Id)).ToList();
// Add roles
groups.ForEach(p =>
{
var roles = p.Roles == null ? new List() : p.Roles.ToList();
roles.Add(roleId);
- MongoDbAccessManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles));
+ DbManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles));
});
return true;
}
diff --git a/Bootstrap.DataAccess.MongoDB/Log.cs b/Bootstrap.DataAccess.MongoDB/Log.cs
index af8b8974..18fd848f 100644
--- a/Bootstrap.DataAccess.MongoDB/Log.cs
+++ b/Bootstrap.DataAccess.MongoDB/Log.cs
@@ -13,13 +13,13 @@ namespace Bootstrap.DataAccess.MongoDB
///
///
///
- public override IEnumerable Retrieves() => MongoDbAccessManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList();
+ public override IEnumerable Retrieves() => DbManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList();
///
/// 删除日志信息
///
///
///
- private static void DeleteLogAsync() => System.Threading.Tasks.Task.Run(() => MongoDbAccessManager.Logs.DeleteMany(log => log.LogTime < DateTime.Now.AddDays(-7)));
+ private static void DeleteLogAsync() => System.Threading.Tasks.Task.Run(() => DbManager.Logs.DeleteMany(log => log.LogTime < DateTime.Now.AddDays(-7)));
///
///
///
@@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.MongoDB
public override bool Save(DataAccess.Log log)
{
log.LogTime = DateTime.Now;
- MongoDbAccessManager.Logs.InsertOne(log);
+ DbManager.Logs.InsertOne(log);
return true;
}
}
diff --git a/Bootstrap.DataAccess.MongoDB/Menu.cs b/Bootstrap.DataAccess.MongoDB/Menu.cs
index b793eb6f..82b07be4 100644
--- a/Bootstrap.DataAccess.MongoDB/Menu.cs
+++ b/Bootstrap.DataAccess.MongoDB/Menu.cs
@@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
var dicts = DictHelper.RetrieveDicts().Where(m => m.Category == "菜单");
- var menus = MongoDbAccessManager.Menus.Find(FilterDefinition.Empty).ToList();
+ var menus = DbManager.Menus.Find(FilterDefinition.Empty).ToList();
menus.ForEach(m =>
{
m.CategoryName = dicts.FirstOrDefault(d => d.Code == m.Category)?.Name;
@@ -38,7 +38,7 @@ namespace Bootstrap.DataAccess.MongoDB
if (p.Id == "0")
{
p.Id = null;
- MongoDbAccessManager.Menus.InsertOne(p);
+ DbManager.Menus.InsertOne(p);
return true;
}
else
@@ -52,7 +52,7 @@ namespace Bootstrap.DataAccess.MongoDB
.Set(md => md.Target, p.Target)
.Set(md => md.IsResource, p.IsResource)
.Set(md => md.Application, p.Application);
- MongoDbAccessManager.Menus.UpdateOne(md => md.Id == p.Id, update);
+ DbManager.Menus.UpdateOne(md => md.Id == p.Id, update);
return true;
}
}
@@ -69,7 +69,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
list.Add(new DeleteOneModel(Builders.Filter.Eq(g => g.Id, id)));
}
- MongoDbAccessManager.Menus.BulkWrite(list);
+ DbManager.Menus.BulkWrite(list);
return true;
}
@@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
///
///
- public override IEnumerable