hermes-server/Store/VoiceStore.cs

55 lines
1.8 KiB
C#
Raw Normal View History

2024-10-17 19:06:22 +00:00
using HermesSocketLibrary.db;
using HermesSocketLibrary.Requests.Messages;
using HermesSocketServer.Store.Internal;
2024-10-17 19:06:22 +00:00
using HermesSocketServer.Validators;
namespace HermesSocketServer.Store
{
public class VoiceStore : AutoSavedStore<string, TTSVoice>
2024-10-17 19:06:22 +00:00
{
private readonly VoiceIdValidator _idValidator;
private readonly VoiceNameValidator _nameValidator;
2024-10-17 19:06:22 +00:00
private readonly Database _database;
private readonly Serilog.ILogger _logger;
public VoiceStore(VoiceIdValidator voiceIdValidator, VoiceNameValidator voiceNameValidator, [FromKeyedServices("Voice")] DatabaseTable table, Database database, Serilog.ILogger logger)
: base(table, database, logger)
2024-10-17 19:06:22 +00:00
{
_idValidator = voiceIdValidator;
_nameValidator = voiceNameValidator;
2024-10-17 19:06:22 +00:00
_database = database;
_logger = logger;
}
public override async Task Load()
2024-10-17 19:06:22 +00:00
{
string sql = "SELECT id, name FROM \"TtsVoice\";";
await _database.Execute(sql, new Dictionary<string, object>(), (reader) =>
{
string id = reader.GetString(0);
_store.Add(id, new TTSVoice()
{
Id = id,
Name = reader.GetString(1),
});
});
_logger.Information($"Loaded {_store.Count} TTS voices from database.");
2024-10-17 19:06:22 +00:00
}
protected override void OnInitialAdd(string key, TTSVoice value)
2024-10-17 19:06:22 +00:00
{
_idValidator.Check(value.Id);
_nameValidator.Check(value.Name);
2024-10-17 19:06:22 +00:00
}
protected override void OnInitialModify(string key, TTSVoice value)
2024-10-17 19:06:22 +00:00
{
_nameValidator.Check(value.Name);
2024-10-17 19:06:22 +00:00
}
protected override void OnInitialRemove(string key)
2024-10-17 19:06:22 +00:00
{
}
}
}