diff --git a/BotSharp.Core/AgentStorageFactory.cs b/BotSharp.Core/AgentStorage/AgentStorageFactory.cs similarity index 96% rename from BotSharp.Core/AgentStorageFactory.cs rename to BotSharp.Core/AgentStorage/AgentStorageFactory.cs index b2377eb5..aaaf3976 100644 --- a/BotSharp.Core/AgentStorageFactory.cs +++ b/BotSharp.Core/AgentStorage/AgentStorageFactory.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -namespace BotSharp.Core +namespace BotSharp.Core.AgentStorage { public class AgentStorageFactory : IAgentStorageFactory where TAgent : AgentBase { diff --git a/BotSharp.Core/AgentStorageInMemory.cs b/BotSharp.Core/AgentStorage/AgentStorageInMemory.cs similarity index 97% rename from BotSharp.Core/AgentStorageInMemory.cs rename to BotSharp.Core/AgentStorage/AgentStorageInMemory.cs index 854e3782..a3671b45 100644 --- a/BotSharp.Core/AgentStorageInMemory.cs +++ b/BotSharp.Core/AgentStorage/AgentStorageInMemory.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BotSharp.Core +namespace BotSharp.Core.AgentStorage { /// /// Save agent instance into memory. diff --git a/BotSharp.Core/AgentStorageInRedis.cs b/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs similarity index 98% rename from BotSharp.Core/AgentStorageInRedis.cs rename to BotSharp.Core/AgentStorage/AgentStorageInRedis.cs index e76b64c2..dc7ee711 100644 --- a/BotSharp.Core/AgentStorageInRedis.cs +++ b/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BotSharp.Core +namespace BotSharp.Core.AgentStorage { public class AgentStorageInRedis : IAgentStorage where TAgent : AgentBase diff --git a/BotSharp.Core/AgentStorage/AgentStorageServiceRegister.cs b/BotSharp.Core/AgentStorage/AgentStorageServiceRegister.cs new file mode 100644 index 00000000..535bb2d1 --- /dev/null +++ b/BotSharp.Core/AgentStorage/AgentStorageServiceRegister.cs @@ -0,0 +1,43 @@ +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core.AgentStorage +{ + public class AgentStorageServiceRegister + { + public static void Register(IServiceCollection services) + where TAgent : AgentBase + { + services.AddSingleton, AgentStorageFactory>(); + + services.AddSingleton>(); + services.AddSingleton>(); + + services.AddSingleton(factory => + { + Func> accesor = key => + { + if (key.Equals("AgentStorageInRedis")) + { + return factory.GetService>(); + } + else if (key.Equals("AgentStorageInMemory")) + { + return factory.GetService>(); + } + else + { + throw new ArgumentException($"Not Support key : {key}"); + } + }; + + return accesor; + }); + } + } +} diff --git a/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs b/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs index 62b11c0d..3a8cb6c8 100644 --- a/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs +++ b/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs @@ -20,14 +20,6 @@ namespace Microsoft.Extensions.DependencyInjection var platform = configuration.GetValue("platformModuleName"); var module = options.Modules.Find(x => x.Name == platform); - var engine = configuration.GetValue($"{platform}:BotEngine"); - - Formatter[] settings = new Formatter[] - { - new Formatter(platform, Color.Yellow), - new Formatter(module.Name, Color.Yellow), - new Formatter(engine, Color.Yellow), - }; // load platform emulator dynamically Console.WriteLine(); @@ -37,12 +29,19 @@ namespace Microsoft.Extensions.DependencyInjection { Assembly library = AssemblyLoadContext.Default.LoadFromAssemblyPath(platformDllPath); action(library); - Console.WriteLineFormatted("Loaded {0} platform emulator from {1} assembly which is using {2} engine.", Color.White, settings); + + Formatter[] settings = new Formatter[] + { + new Formatter(platform, Color.Yellow), + new Formatter(platformDllPath, Color.Yellow) + }; + Console.WriteLineFormatted("Loaded {0} platform emulator from {1} assembly.", Color.White, settings); } else { - Console.WriteLine($"Can't load {module.Type} assembly."); + Console.WriteLine($"Can't load {module.Type} assembly from {platformDllPath}."); } + Console.WriteLine(); } } diff --git a/BotSharp.Core/PlatformConfigServiceRegister.cs b/BotSharp.Core/PlatformConfigServiceRegister.cs new file mode 100644 index 00000000..6535eb11 --- /dev/null +++ b/BotSharp.Core/PlatformConfigServiceRegister.cs @@ -0,0 +1,32 @@ +using BotSharp.Platform.Abstraction; +using Colorful; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; +using Console = Colorful.Console; + +namespace BotSharp.Core +{ + public class PlatformConfigServiceRegister + { + public static void Register(string section, IServiceCollection services, IConfiguration config) + where ISettings : IPlatformSettings, new() + { + var setting = new ISettings(); + config.GetSection(section).Bind(setting); + services.AddSingleton(setting); + + Formatter[] settings = new Formatter[] + { + new Formatter(setting.BotEngine, Color.Yellow), + new Formatter(setting.AgentStorage, Color.Yellow) + }; + + Console.WriteLineFormatted("NLU engine: {0}, Agent Storage: {1}.", Color.White, settings); + Console.WriteLine(); + } + } +} diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index 2fb92b46..d8b4f596 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -79,6 +79,7 @@ + @@ -86,15 +87,9 @@ PreserveNewest - - PreserveNewest - PreserveNewest - - PreserveNewest - PreserveNewest diff --git a/BotSharp.WebHost/Settings/ArticulateAi.json b/BotSharp.WebHost/Settings/ArticulateAi.json deleted file mode 100644 index 81cff34e..00000000 --- a/BotSharp.WebHost/Settings/ArticulateAi.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "articulateAi": { - "botEngine": "BotSharpNLU", - - "agentStorage": "AgentStorageInRedis" - } -} diff --git a/BotSharp.WebHost/Settings/DialogflowAi.json b/BotSharp.WebHost/Settings/DialogflowAi.json index 5b5c6c4b..72181242 100644 --- a/BotSharp.WebHost/Settings/DialogflowAi.json +++ b/BotSharp.WebHost/Settings/DialogflowAi.json @@ -1,7 +1,6 @@ { + // if you want to override platform setting, please set corresponding value, otherwise you don't need this section. "dialogflowAi": { - "botEngine": "BotSharpNLU", - - "agentStorage": "AgentStorageInMemory" + "botEngine": "BotSharpNLU" } } diff --git a/BotSharp.WebHost/Settings/RasaAi.json b/BotSharp.WebHost/Settings/RasaAi.json deleted file mode 100644 index 8c246b86..00000000 --- a/BotSharp.WebHost/Settings/RasaAi.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "rasaAi": { - "botEngine": "BotSharpNLU", - - "agentStorage": "AgentStorageInMemory" - } -} diff --git a/BotSharp.WebHost/Settings/app.json b/BotSharp.WebHost/Settings/app.json index 1cb66df0..583f0eec 100644 --- a/BotSharp.WebHost/Settings/app.json +++ b/BotSharp.WebHost/Settings/app.json @@ -8,7 +8,7 @@ "dataDir": "D:\\Projects\\BotSharp\\Data" }, - "moduleBasePath": "D:\\Projects", + "moduleBasePath": "C:\\Users\\haipi\\Documents\\Projects", "modules": [ { "Name": "DialogflowAi", diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index f4dea5fc..7952625f 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -98,9 +98,11 @@ namespace BotSharp.WebHost c.DocumentTitle = info.Title; c.InjectStylesheet(Configuration.GetValue("Swagger:Stylesheet")); + Console.WriteLine(); Console.WriteLine($"{info.Title} [{info.Version}] {info.License.Name}"); Console.WriteLine($"{info.Description}"); - Console.WriteLine($"{info.Contact.Name}"); + Console.WriteLine($"{info.Contact.Name}, {DateTime.UtcNow.ToString()}"); + Console.WriteLine(); }); app.Use(async (context, next) =>