resolve conflicts

This commit is contained in:
Jicheng Lu 2023-09-05 22:39:56 -05:00
parent dc755e33f9
commit 1981b0f000
3 changed files with 16 additions and 15 deletions

View file

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

View file

@ -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<KeyValueModel> _savedStates;
public ConversationStateService(ILogger<ConversationStateService> 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<KeyValueModel>();
foreach (var dic in _state)
foreach (var dic in _states)
{
states.Add(new KeyValueModel(dic.Key, dic.Value));
}

View file

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