share AgentStorageFactory

This commit is contained in:
botsharp2018 2018-10-11 08:24:50 -05:00
parent c69bfbd38e
commit 3bfe8d26e1
9 changed files with 126 additions and 32 deletions

View file

@ -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<TAgent> : IAgentStorageFactory<TAgent> where TAgent : AgentBase
{
private readonly Func<string, IAgentStorage<TAgent>> func;
private readonly IPlatformSettings platformSetting;
public AgentStorageFactory(IPlatformSettings setting, Func<string, IAgentStorage<TAgent>> serviceAccessor)
{
this.func = serviceAccessor;
this.platformSetting = setting;
}
public async Task<IAgentStorage<TAgent>> Get()
{
IAgentStorage<TAgent> storage = null;
string storageName = this.platformSetting.AgentStorage;
storage = func(storageName);
return storage as IAgentStorage<TAgent>;
}
}
}

View file

@ -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;

View file

@ -1,11 +0,0 @@
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using System.Threading.Tasks;
namespace BotSharp.Core
{
public interface IAgentStorageFactory
{
Task<IAgentStorage<TAgent>> Get<TAgent>() where TAgent : AgentBase;
}
}

View file

@ -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; }
}
}

View file

@ -18,9 +18,9 @@ namespace BotSharp.Core
{
public IAgentStorage<TAgent> Storage { get; set; }
private readonly IAgentStorageFactory agentStorageFactory;
private readonly IAgentStorageFactory<TAgent> agentStorageFactory;
public PlatformBuilderBase(IAgentStorageFactory agentStorageFactory)
public PlatformBuilderBase(IAgentStorageFactory<TAgent> agentStorageFactory)
{
this.agentStorageFactory = agentStorageFactory;
}
@ -111,7 +111,7 @@ namespace BotSharp.Core
{
if (Storage == null)
{
Storage = await agentStorageFactory.Get<TAgent>();
Storage = await agentStorageFactory.Get();
}
return Storage;
}

View file

@ -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
{
/// <summary>
/// Set default settings
/// </summary>
public PlatformSettingsBase()
{
BotEngine = "BotSharpNLU";
AgentStorage = "AgentStorageInMemory";
}
public string BotEngine { get; set; }
public string AgentStorage { get; set; }
}
}

View file

@ -0,0 +1,11 @@
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using System.Threading.Tasks;
namespace BotSharp.Platform.Abstraction
{
public interface IAgentStorageFactory<TAgent> where TAgent : AgentBase
{
Task<IAgentStorage<TAgent>> Get();
}
}

View file

@ -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; }
}
}

View file

@ -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