diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 06fc8e05..87e3ff7a 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -1,3 +1,6 @@ +using BotSharp.Abstraction.Repositories; +using BotSharp.Abstraction.Repositories.Records; + namespace BotSharp.Core.Conversations.Services; public partial class ConversationService : IConversationService @@ -12,7 +15,8 @@ public partial class ConversationService : IConversationService public IConversationStateService States => _state; - public ConversationService(IServiceProvider services, + public ConversationService( + IServiceProvider services, IUserIdentity user, ConversationSetting settings, IConversationStorage storage, diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index dbf36f25..a7f12136 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -1,3 +1,5 @@ +using BotSharp.Abstraction.Repositories; +using BotSharp.Abstraction.Repositories.Models; using System.IO; namespace BotSharp.Core.Conversations.Services; @@ -10,21 +12,21 @@ public class ConversationStateService : IConversationStateService, IDisposable private readonly ILogger _logger; private readonly IServiceProvider _services; private ConversationState _states; - private MyDatabaseSettings _dbSettings; + private BotSharpDatabaseSettings _dbSettings; private string _conversationId; private string _file; + private readonly IBotSharpRepository _db; private List _savedStates; public ConversationStateService(ILogger logger, IServiceProvider services, BotSharpDatabaseSettings dbSettings, - AgentSettings agentSettings, - IUserIdentity user, IBotSharpRepository db) { _logger = logger; _services = services; _dbSettings = dbSettings; + _db = db; _states = new ConversationState(); } @@ -46,24 +48,19 @@ public class ConversationStateService : IConversationStateService, IDisposable public ConversationState Load(string conversationId) { - _conversationId = conversationId; - } - - public ConversationState Load() - { - if (_state != null) + if (_states != null) { - return _state; + return _states; } - _state = new ConversationState(); _savedStates = _db.GetConversationState(_conversationId); if (_savedStates != null) { foreach (var data in _savedStates) { - _state[data.Key] = data.Value; + _states[data.Key] = data.Value; + _logger.LogInformation($"Loaded state: {data.Key}={data.Value}"); } } @@ -86,7 +83,7 @@ public class ConversationStateService : IConversationStateService, IDisposable var states = new List(); - foreach (var dic in _state) + foreach (var dic in _states) { states.Add(new KeyValueModel(dic.Key, dic.Value)); } diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index 2dc9675e..71b1d637 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -45,7 +45,7 @@ builder.Services.AddBotSharp(builder.Configuration); // Change below if you want to use other data storage. // builder.Services.UsingSqlServer(builder.Configuration); // Default is using File Storage -builder.Services.UsingFileRepository(builder.Configuration); +//builder.Services.UsingFileRepository(builder.Configuration); builder.Services.AddCors(options => {