diff --git a/BotSharp.Core/AgentStorageFactory.cs b/BotSharp.Core/AgentStorageFactory.cs new file mode 100644 index 00000000..b2377eb5 --- /dev/null +++ b/BotSharp.Core/AgentStorageFactory.cs @@ -0,0 +1,30 @@ +using BotSharp.Core; +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace BotSharp.Core +{ + public class AgentStorageFactory : IAgentStorageFactory where TAgent : AgentBase + { + private readonly Func> func; + private readonly IPlatformSettings platformSetting; + + public AgentStorageFactory(IPlatformSettings setting, Func> serviceAccessor) + { + this.func = serviceAccessor; + this.platformSetting = setting; + } + + public async Task> Get() + { + IAgentStorage storage = null; + string storageName = this.platformSetting.AgentStorage; + storage = func(storageName); + return storage as IAgentStorage; + } + } +} diff --git a/BotSharp.Core/Engines/BotTrainer.cs b/BotSharp.Core/Engines/BotTrainer.cs index e93d8b4d..f8c76cb2 100644 --- a/BotSharp.Core/Engines/BotTrainer.cs +++ b/BotSharp.Core/Engines/BotTrainer.cs @@ -40,7 +40,7 @@ namespace BotSharp.Core.Engines // Get NLP Provider var config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration"); var assemblies = (string[])AppDomain.CurrentDomain.GetData("Assemblies"); - var platform = config.GetSection($"platform").Value; + var platform = config.GetSection($"platformModuleName").Value; var engine = config.GetSection($"{platform}:botEngine").Value; string providerName = config.GetSection($"{engine}:Provider").Value; var provider = TypeHelper.GetInstance(providerName, assemblies) as INlpProvider; diff --git a/BotSharp.Core/IAgentStorageFactory.cs b/BotSharp.Core/IAgentStorageFactory.cs deleted file mode 100644 index 2f8b520b..00000000 --- a/BotSharp.Core/IAgentStorageFactory.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BotSharp.Platform.Abstraction; -using BotSharp.Platform.Models; -using System.Threading.Tasks; - -namespace BotSharp.Core -{ - public interface IAgentStorageFactory - { - Task> Get() where TAgent : AgentBase; - } -} diff --git a/BotSharp.Core/NLUSetting.cs b/BotSharp.Core/NLUSetting.cs deleted file mode 100644 index 594989e6..00000000 --- a/BotSharp.Core/NLUSetting.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BotSharp.Core -{ - public class NLUSetting - { - - public string BotEngine { get; set; } - - public string AgentStorage { get; set; } - } - -} diff --git a/BotSharp.Core/PlatformBuilderBase.cs b/BotSharp.Core/PlatformBuilderBase.cs index 12f1e60d..a18443ee 100644 --- a/BotSharp.Core/PlatformBuilderBase.cs +++ b/BotSharp.Core/PlatformBuilderBase.cs @@ -18,9 +18,9 @@ namespace BotSharp.Core { public IAgentStorage Storage { get; set; } - private readonly IAgentStorageFactory agentStorageFactory; + private readonly IAgentStorageFactory agentStorageFactory; - public PlatformBuilderBase(IAgentStorageFactory agentStorageFactory) + public PlatformBuilderBase(IAgentStorageFactory agentStorageFactory) { this.agentStorageFactory = agentStorageFactory; } @@ -111,7 +111,7 @@ namespace BotSharp.Core { if (Storage == null) { - Storage = await agentStorageFactory.Get(); + Storage = await agentStorageFactory.Get(); } return Storage; } diff --git a/BotSharp.Core/PlatformSettingsBase.cs b/BotSharp.Core/PlatformSettingsBase.cs new file mode 100644 index 00000000..a2d00268 --- /dev/null +++ b/BotSharp.Core/PlatformSettingsBase.cs @@ -0,0 +1,26 @@ +using BotSharp.Platform.Abstraction; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core +{ + public class PlatformSettingsBase : IPlatformSettings + { + /// + /// Set default settings + /// + public PlatformSettingsBase() + { + BotEngine = "BotSharpNLU"; + AgentStorage = "AgentStorageInMemory"; + } + + public string BotEngine { get; set; } + + public string AgentStorage { get; set; } + } + +} diff --git a/BotSharp.Platform.Abstraction/IAgentStorageFactory.cs b/BotSharp.Platform.Abstraction/IAgentStorageFactory.cs new file mode 100644 index 00000000..9f5a2bfb --- /dev/null +++ b/BotSharp.Platform.Abstraction/IAgentStorageFactory.cs @@ -0,0 +1,11 @@ +using BotSharp.Platform.Abstraction; +using BotSharp.Platform.Models; +using System.Threading.Tasks; + +namespace BotSharp.Platform.Abstraction +{ + public interface IAgentStorageFactory where TAgent : AgentBase + { + Task> Get(); + } +} diff --git a/BotSharp.Platform.Abstraction/IPlatformSettings.cs b/BotSharp.Platform.Abstraction/IPlatformSettings.cs new file mode 100644 index 00000000..dafe4fbb --- /dev/null +++ b/BotSharp.Platform.Abstraction/IPlatformSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Platform.Abstraction +{ + public interface IPlatformSettings + { + string BotEngine { get; set; } + + string AgentStorage { get; set; } + } +} diff --git a/BotSharp.sln b/BotSharp.sln index ab3e395f..cf958925 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -22,6 +22,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Abstracti EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Models", "BotSharp.Platform.Models\BotSharp.Platform.Models.csproj", "{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Dialogflow", "..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj", "{02CCD2C2-6211-444A-BE22-D7EB67919E11}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Articulate", "..\botsharp-articulate\BotSharp.Platform.Articulate\BotSharp.Platform.Articulate.csproj", "{11C313EC-FA33-43C2-A2F7-4C658521F51C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Rasa", "..\botsharp-rasa\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj", "{64BD6368-9991-4372-A96A-D95A8044176D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -116,6 +122,42 @@ Global {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|Any CPU.Build.0 = Release|Any CPU {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.ActiveCfg = Release|Any CPU {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.Build.0 = Release|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Debug|x64.ActiveCfg = Debug|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Debug|x64.Build.0 = Debug|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.DIALOGFLOW|x64.ActiveCfg = DIALOGFLOW|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.DIALOGFLOW|x64.Build.0 = DIALOGFLOW|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Release|Any CPU.Build.0 = Release|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Release|x64.ActiveCfg = Release|Any CPU + {02CCD2C2-6211-444A-BE22-D7EB67919E11}.Release|x64.Build.0 = Release|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Debug|x64.ActiveCfg = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Debug|x64.Build.0 = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Release|Any CPU.Build.0 = Release|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Release|x64.ActiveCfg = Release|Any CPU + {11C313EC-FA33-43C2-A2F7-4C658521F51C}.Release|x64.Build.0 = Release|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Debug|x64.ActiveCfg = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Debug|x64.Build.0 = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Release|Any CPU.Build.0 = Release|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Release|x64.ActiveCfg = Release|Any CPU + {64BD6368-9991-4372-A96A-D95A8044176D}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE