diff --git a/Bootstrap.Admin/Startup.cs b/Bootstrap.Admin/Startup.cs index 705fe57a..0dba8b4f 100644 --- a/Bootstrap.Admin/Startup.cs +++ b/Bootstrap.Admin/Startup.cs @@ -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() { "*" }); }); var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"]) .SetApplicationName(Configuration["ApplicationName"]) .PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"])); diff --git a/Bootstrap.Client.DataAccess/DbAccessManager.cs b/Bootstrap.Client.DataAccess/DbAccessManager.cs index 05cde266..8679cdcc 100644 --- a/Bootstrap.Client.DataAccess/DbAccessManager.cs +++ b/Bootstrap.Client.DataAccess/DbAccessManager.cs @@ -1,5 +1,4 @@ using Longbow.Data; -using System; namespace Bootstrap.Client.DataAccess { @@ -8,10 +7,9 @@ namespace Bootstrap.Client.DataAccess /// public static class DbAccessManager { - private static readonly Lazy _db = new Lazy(() => DbAccessFactory.CreateDB("sql"), true); /// /// /// - public static IDbAccess DbAccess { get { return _db.Value; } } + public static IDbAccess DbAccess { get { return DbAdapterManager.CreateDB(); } } } } diff --git a/Bootstrap.Client/Startup.cs b/Bootstrap.Client/Startup.cs index dbca522c..e4677a26 100644 --- a/Bootstrap.Client/Startup.cs +++ b/Bootstrap.Client/Startup.cs @@ -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"])); diff --git a/Bootstrap.DataAccess.SQLite/Exceptions.cs b/Bootstrap.DataAccess.SQLite/Exceptions.cs index 845cc9b0..f78ec8a7 100644 --- a/Bootstrap.DataAccess.SQLite/Exceptions.cs +++ b/Bootstrap.DataAccess.SQLite/Exceptions.cs @@ -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(); diff --git a/Bootstrap.DataAccess.SQLite/User.cs b/Bootstrap.DataAccess.SQLite/User.cs index 827a0441..33921e6b 100644 --- a/Bootstrap.DataAccess.SQLite/User.cs +++ b/Bootstrap.DataAccess.SQLite/User.cs @@ -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() : new List() { p.Id }); diff --git a/Bootstrap.DataAccess/DbAccessManager.cs b/Bootstrap.DataAccess/DbAccessManager.cs index dc65a26c..61cb11f7 100644 --- a/Bootstrap.DataAccess/DbAccessManager.cs +++ b/Bootstrap.DataAccess/DbAccessManager.cs @@ -1,5 +1,4 @@ using Longbow.Data; -using System; namespace Bootstrap.DataAccess { @@ -8,13 +7,12 @@ namespace Bootstrap.DataAccess /// public static class DbAccessManager { - private static readonly Lazy db = new Lazy(() => DbAccessFactory.CreateDB("ba"), true); /// /// /// public static IDbAccess DBAccess { - get { return db.Value; } + get { return DbAdapterManager.CreateDB("ba"); } } } } diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs index a75324e1..9d2654ca 100644 --- a/Bootstrap.DataAccess/Exceptions.cs +++ b/Bootstrap.DataAccess/Exceptions.cs @@ -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(); diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs index 30f95b73..eacbd355 100644 --- a/Bootstrap.DataAccess/Group.cs +++ b/Bootstrap.DataAccess/Group.cs @@ -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() : new List() { p.Id }); diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 731fe2fd..f547a2ae 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -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)); diff --git a/Bootstrap.DataAccess/Role.cs b/Bootstrap.DataAccess/Role.cs index f1d01eab..d64b5cef 100644 --- a/Bootstrap.DataAccess/Role.cs +++ b/Bootstrap.DataAccess/Role.cs @@ -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() : new List { p.Id }); diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index ced31227..40d24578 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -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() : new List() { 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}*");