From ee6e4d61fb04a47fdaaba521613911f8723a3f81 Mon Sep 17 00:00:00 2001 From: hchen2020 <101423@smsassist.com> Date: Fri, 21 Jul 2023 17:17:16 -0500 Subject: [PATCH] Add custom agent data directory. --- .../BotSharp.Abstraction/Agents/Settings/AgentSettings.cs | 6 ++++++ .../BotSharp.Core/Agents/Services/AgentService.cs | 6 ++++-- .../BotSharp.Core/BotSharpServiceCollectionExtensions.cs | 6 +++++- src/Infrastructure/BotSharp.Core/Using.cs | 4 +++- 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs new file mode 100644 index 00000000..f51e1941 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Abstraction.Agents.Settings; + +public class AgentSettings +{ + public string DataDir { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs index 6a53d291..55238f8d 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs @@ -6,16 +6,18 @@ public partial class AgentService : IAgentService { private readonly IServiceProvider _services; private readonly IUserIdentity _user; + private readonly AgentSettings _settings; - public AgentService(IServiceProvider services, IUserIdentity user) + public AgentService(IServiceProvider services, IUserIdentity user, AgentSettings settings) { _services = services; _user = user; + _settings = settings; } public string GetAgentDataDir(string agentId) { - var dir = Path.Combine("data", agentId); + var dir = Path.Combine(_settings.DataDir, agentId); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); diff --git a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs index 1e02d17c..cb8a3545 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs @@ -1,6 +1,6 @@ -using BotSharp.Abstraction.Conversations.Settings; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; + namespace BotSharp.Core; public static class BotSharpServiceCollectionExtensions @@ -12,6 +12,10 @@ public static class BotSharpServiceCollectionExtensions services.AddScoped(); + var agentSettings = new AgentSettings(); + config.Bind("Agent", agentSettings); + services.AddSingleton((IServiceProvider x) => agentSettings); + var convsationSettings = new ConversationSetting(); config.Bind("Conversation", convsationSettings); services.AddSingleton((IServiceProvider x) => convsationSettings); diff --git a/src/Infrastructure/BotSharp.Core/Using.cs b/src/Infrastructure/BotSharp.Core/Using.cs index 304bcf8c..45712028 100644 --- a/src/Infrastructure/BotSharp.Core/Using.cs +++ b/src/Infrastructure/BotSharp.Core/Using.cs @@ -18,4 +18,6 @@ global using BotSharp.Core.Agents.Services; global using BotSharp.Core.Conversations.Services; global using BotSharp.Core.Infrastructures; global using BotSharp.Core.Plugins; -global using BotSharp.Core.Users.Services; \ No newline at end of file +global using BotSharp.Core.Users.Services; +global using BotSharp.Abstraction.Agents.Settings; +global using BotSharp.Abstraction.Conversations.Settings; \ No newline at end of file