重构代码:根据Longbow.Data组件变化,更改DbAccessFactory为DbAdapterManager
This commit is contained in:
parent
b0111b8431
commit
8dd9c3e773
|
@ -19,6 +19,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Bootstrap.Admin
|
namespace Bootstrap.Admin
|
||||||
|
@ -45,7 +46,7 @@ namespace Bootstrap.Admin
|
||||||
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
|
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
|
||||||
services.AddConfigurationManager();
|
services.AddConfigurationManager();
|
||||||
services.AddCacheManager();
|
services.AddCacheManager();
|
||||||
services.AddDBAccessFactory();
|
services.AddDbAdapter(() => { CacheManager.Clear(); CacheManager.CorsClear(new List<string>() { "*" }); });
|
||||||
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
||||||
.SetApplicationName(Configuration["ApplicationName"])
|
.SetApplicationName(Configuration["ApplicationName"])
|
||||||
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Bootstrap.Client.DataAccess
|
namespace Bootstrap.Client.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -8,10 +7,9 @@ namespace Bootstrap.Client.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DbAccessManager
|
public static class DbAccessManager
|
||||||
{
|
{
|
||||||
private static readonly Lazy<IDbAccess> _db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("sql"), true);
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IDbAccess DbAccess { get { return _db.Value; } }
|
public static IDbAccess DbAccess { get { return DbAdapterManager.CreateDB(); } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Bootstrap.Client
|
||||||
services.AddLogging(builder => builder.AddFileLogger());
|
services.AddLogging(builder => builder.AddFileLogger());
|
||||||
services.AddConfigurationManager();
|
services.AddConfigurationManager();
|
||||||
services.AddCacheManager();
|
services.AddCacheManager();
|
||||||
services.AddDBAccessFactory();
|
services.AddDbAdapter();
|
||||||
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
||||||
.SetApplicationName(Configuration["ApplicationName"])
|
.SetApplicationName(Configuration["ApplicationName"])
|
||||||
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
||||||
|
|
|
@ -50,11 +50,11 @@ namespace Bootstrap.DataAccess.SQLite
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAdapterManager.ToDBValue(additionalInfo["UserId"])));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAdapterManager.ToDBValue(additionalInfo["UserIp"])));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
|
||||||
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
CacheManager.Clear(RetrieveExceptionsDataKey);
|
CacheManager.Clear(RetrieveExceptionsDataKey);
|
||||||
ClearExceptions();
|
ClearExceptions();
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace Bootstrap.DataAccess.SQLite
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy)));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
||||||
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -8,13 +7,12 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DbAccessManager
|
public static class DbAccessManager
|
||||||
{
|
{
|
||||||
private static readonly Lazy<IDbAccess> db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("ba"), true);
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IDbAccess DBAccess
|
public static IDbAccess DBAccess
|
||||||
{
|
{
|
||||||
get { return db.Value; }
|
get { return DbAdapterManager.CreateDB("ba"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,11 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAdapterManager.ToDBValue(additionalInfo["UserId"])));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAdapterManager.ToDBValue(additionalInfo["UserIp"])));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
|
||||||
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
CacheManager.Clear(RetrieveExceptionsDataKey);
|
CacheManager.Clear(RetrieveExceptionsDataKey);
|
||||||
ClearExceptions();
|
ClearExceptions();
|
||||||
|
|
|
@ -99,7 +99,7 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
|
||||||
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
|
|
|
@ -60,8 +60,8 @@ namespace Bootstrap.DataAccess
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAdapterManager.ToDBValue(p.Icon)));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAdapterManager.ToDBValue(p.Url)));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||||
|
|
|
@ -176,7 +176,7 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
|
||||||
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
||||||
|
|
|
@ -211,7 +211,7 @@ namespace Bootstrap.DataAccess
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy)));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
||||||
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
|
@ -479,7 +479,7 @@ namespace Bootstrap.DataAccess
|
||||||
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
||||||
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAdapterManager.ToDBValue(cssName)));
|
||||||
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
|
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
|
|
Loading…
Reference in New Issue