From 0abaa2df945dd0c7b17bfc772b0d63fe6f0fbccb Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 20 Jul 2024 22:00:38 -0500 Subject: [PATCH] Upgrade EntityFrameworkCore.BootKit to v8.5 --- .../BotSharp.Core/BotSharp.Core.csproj | 2 +- .../BotSharp.Core/BotSharpCoreExtensions.cs | 2 +- .../Repository/DataContextHelper.cs | 60 ++++++++++--------- .../FileRepository/FileRepository.cs | 1 - .../Routing/Planning/SequentialPlanner.cs | 5 -- .../Controllers/LoggerController.cs | 4 -- .../Functions/LookupDictionaryFn.cs | 1 - 7 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 5fd9bc4c..75ab6185 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -170,7 +170,7 @@ - + diff --git a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs index 2dd2dc7f..61c45c58 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs @@ -28,7 +28,7 @@ public static class BotSharpCoreExtensions services.AddScoped(sp => { var myDatabaseSettings = sp.GetRequiredService(); - return DataContextHelper.GetDbContext(myDatabaseSettings, sp); + return DataContextHelper.GetSqlServerDbContext(myDatabaseSettings, sp); }); return services; diff --git a/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs b/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs index edcbced8..806e985f 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs @@ -1,14 +1,12 @@ using Microsoft.Data.SqlClient; -using MySqlConnector; using System.Data.Common; namespace BotSharp.Core.Repository; public static class DataContextHelper { - public static T GetDbContext(BotSharpDatabaseSettings settings, IServiceProvider serviceProvider) + public static T GetSqlServerDbContext(BotSharpDatabaseSettings settings, IServiceProvider serviceProvider) where T : Database, new() - where Tdb : DataContext { if (settings.Assemblies == null) throw new Exception("Please set assemblies."); @@ -18,32 +16,40 @@ public static class DataContextHelper var dc = new T(); if (typeof(T) == typeof(BotSharpDbContext)) { - if (typeof(Tdb).Name.StartsWith("DbContext4SqlServer")) + dc.BindDbContext(new DatabaseBind { - dc.BindDbContext(new DatabaseBind - { - ServiceProvider = serviceProvider, - MasterConnection = new SqlConnection(settings.BotSharp.Master), - SlaveConnections = settings.BotSharp.Slavers.Length == 0 ? - new List { new SqlConnection(settings.BotSharp.Master) } : - settings.BotSharp.Slavers.Select(x => new SqlConnection(x) as DbConnection) - .ToList(), - CreateDbIfNotExist = true - }); - } - else if (typeof(Tdb).Name.StartsWith("DbContext4Aurora") || - typeof(Tdb).Name.StartsWith("DbContext4MySql")) - { - dc.BindDbContext(new DatabaseBind - { - ServiceProvider = serviceProvider, - MasterConnection = new MySqlConnection(settings.BotSharp.Master), - SlaveConnections = settings.BotSharp.Slavers - .Select(x => new MySqlConnection(x) as DbConnection).ToList(), - CreateDbIfNotExist = true - }); - } + ServiceProvider = serviceProvider, + MasterConnection = new SqlConnection(settings.BotSharp.Master), + SlaveConnections = settings.BotSharp.Slavers.Length == 0 ? + new List { new SqlConnection(settings.BotSharp.Master) } : + settings.BotSharp.Slavers.Select(x => new SqlConnection(x) as DbConnection) + .ToList(), + CreateDbIfNotExist = true + }); } return dc; } + + /*public static T GetMySqlDbContext(BotSharpDatabaseSettings settings, IServiceProvider serviceProvider) + where T : Database, new() + { + if (settings.Assemblies == null) + throw new Exception("Please set assemblies."); + + AppDomain.CurrentDomain.SetData("Assemblies", settings.Assemblies); + + var dc = new T(); + if (typeof(T) == typeof(BotSharpDbContext)) + { + dc.BindDbContext(new DatabaseBind + { + ServiceProvider = serviceProvider, + MasterConnection = new MySqlConnection(settings.BotSharp.Master), + SlaveConnections = settings.BotSharp.Slavers + .Select(x => new MySqlConnection(x) as DbConnection).ToList(), + CreateDbIfNotExist = true + }); + } + return dc; + }*/ } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs index ed953c17..78bd5cc0 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs @@ -1,7 +1,6 @@ using System.IO; using FunctionDef = BotSharp.Abstraction.Functions.Models.FunctionDef; using BotSharp.Abstraction.Users.Models; -using MongoDB.Driver; using System.Text.Encodings.Web; using BotSharp.Abstraction.Plugins.Models; using BotSharp.Abstraction.Statistics.Settings; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs index b6f613e0..ac201f04 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs @@ -1,12 +1,7 @@ -using Amazon.SecurityToken.Model.Internal.MarshallTransformations; -using BotSharp.Abstraction.Agents.Models; -using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.MLTasks; -using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Templating; -using System.Drawing; namespace BotSharp.Core.Routing.Planning; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs index 0b914635..de07a482 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs @@ -1,9 +1,5 @@ using BotSharp.Abstraction.Loggers.Models; using Microsoft.AspNetCore.Hosting; -using SharpCompress.Compressors.Xz; -using System; -using System.IO; -using System.Net.Mime; namespace BotSharp.OpenAPI.Controllers; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs index 94607662..e09caa7b 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs @@ -1,4 +1,3 @@ -using Amazon.Runtime.Internal.Transform; using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.MLTasks; using BotSharp.Core.Infrastructures;