重构代码:根据Longbow.Data组件变化,更改DbAccessFactory为DbAdapterManager

This commit is contained in:
Argo-MacBookPro 2018-10-21 21:08:35 +08:00 committed by Argo Zhang
parent b0111b8431
commit 8dd9c3e773
11 changed files with 18 additions and 21 deletions

View File

@ -19,6 +19,7 @@ using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
namespace Bootstrap.Admin
@ -45,7 +46,7 @@ namespace Bootstrap.Admin
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
services.AddConfigurationManager();
services.AddCacheManager();
services.AddDBAccessFactory();
services.AddDbAdapter(() => { CacheManager.Clear(); CacheManager.CorsClear(new List<string>() { "*" }); });
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
.SetApplicationName(Configuration["ApplicationName"])
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));

View File

@ -1,5 +1,4 @@
using Longbow.Data;
using System;
namespace Bootstrap.Client.DataAccess
{
@ -8,10 +7,9 @@ namespace Bootstrap.Client.DataAccess
/// </summary>
public static class DbAccessManager
{
private static readonly Lazy<IDbAccess> _db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("sql"), true);
/// <summary>
///
/// </summary>
public static IDbAccess DbAccess { get { return _db.Value; } }
public static IDbAccess DbAccess { get { return DbAdapterManager.CreateDB(); } }
}
}

View File

@ -46,7 +46,7 @@ namespace Bootstrap.Client
services.AddLogging(builder => builder.AddFileLogger());
services.AddConfigurationManager();
services.AddCacheManager();
services.AddDBAccessFactory();
services.AddDbAdapter();
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
.SetApplicationName(Configuration["ApplicationName"])
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));

View File

@ -50,11 +50,11 @@ namespace Bootstrap.DataAccess.SQLite
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
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("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAdapterManager.ToDBValue(additionalInfo["UserId"])));
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("@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);
CacheManager.Clear(RetrieveExceptionsDataKey);
ClearExceptions();

View File

@ -52,7 +52,7 @@ namespace Bootstrap.DataAccess.SQLite
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
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));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });

View File

@ -1,5 +1,4 @@
using Longbow.Data;
using System;
namespace Bootstrap.DataAccess
{
@ -8,13 +7,12 @@ namespace Bootstrap.DataAccess
/// </summary>
public static class DbAccessManager
{
private static readonly Lazy<IDbAccess> db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("ba"), true);
/// <summary>
///
/// </summary>
public static IDbAccess DBAccess
{
get { return db.Value; }
get { return DbAdapterManager.CreateDB("ba"); }
}
}
}

View File

@ -91,11 +91,11 @@ namespace Bootstrap.DataAccess
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
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("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAdapterManager.ToDBValue(additionalInfo["UserId"])));
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("@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);
CacheManager.Clear(RetrieveExceptionsDataKey);
ClearExceptions();

View File

@ -99,7 +99,7 @@ namespace Bootstrap.DataAccess
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
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;
}
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });

View File

@ -60,8 +60,8 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
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("@Url", DbAccessFactory.ToDBValue(p.Url)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAdapterManager.ToDBValue(p.Icon)));
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("@Target", p.Target));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));

View File

@ -176,7 +176,7 @@ namespace Bootstrap.DataAccess
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
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;
}
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });

View File

@ -211,7 +211,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
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));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
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";
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));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");