2024-10-17 19:06:22 +00:00
|
|
|
using HermesSocketLibrary.db;
|
2024-12-31 18:31:21 +00:00
|
|
|
using HermesSocketLibrary.Requests.Messages;
|
|
|
|
using HermesSocketServer.Store.Internal;
|
2024-10-17 19:06:22 +00:00
|
|
|
using HermesSocketServer.Validators;
|
|
|
|
|
|
|
|
namespace HermesSocketServer.Store
|
|
|
|
{
|
2024-12-31 18:31:21 +00:00
|
|
|
public class VoiceStore : AutoSavedStore<string, TTSVoice>
|
2024-10-17 19:06:22 +00:00
|
|
|
{
|
2024-10-19 01:50:46 +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;
|
|
|
|
|
|
|
|
|
2024-12-31 18:31:21 +00:00
|
|
|
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
|
|
|
{
|
2024-10-19 01:50:46 +00:00
|
|
|
_idValidator = voiceIdValidator;
|
|
|
|
_nameValidator = voiceNameValidator;
|
2024-10-17 19:06:22 +00:00
|
|
|
_database = database;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-10-19 01:50:46 +00:00
|
|
|
public override async Task Load()
|
2024-10-17 19:06:22 +00:00
|
|
|
{
|
2024-10-19 01:50:46 +00:00
|
|
|
string sql = "SELECT id, name FROM \"TtsVoice\";";
|
|
|
|
await _database.Execute(sql, new Dictionary<string, object>(), (reader) =>
|
|
|
|
{
|
|
|
|
string id = reader.GetString(0);
|
2024-12-31 18:31:21 +00:00
|
|
|
_store.Add(id, new TTSVoice()
|
2024-10-19 01:50:46 +00:00
|
|
|
{
|
|
|
|
Id = id,
|
|
|
|
Name = reader.GetString(1),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
_logger.Information($"Loaded {_store.Count} TTS voices from database.");
|
2024-10-17 19:06:22 +00:00
|
|
|
}
|
|
|
|
|
2024-12-31 18:31:21 +00:00
|
|
|
protected override void OnInitialAdd(string key, TTSVoice value)
|
2024-10-17 19:06:22 +00:00
|
|
|
{
|
2024-10-19 01:50:46 +00:00
|
|
|
_idValidator.Check(value.Id);
|
|
|
|
_nameValidator.Check(value.Name);
|
2024-10-17 19:06:22 +00:00
|
|
|
}
|
|
|
|
|
2024-12-31 18:31:21 +00:00
|
|
|
protected override void OnInitialModify(string key, TTSVoice value)
|
2024-10-17 19:06:22 +00:00
|
|
|
{
|
2024-10-19 01:50:46 +00:00
|
|
|
_nameValidator.Check(value.Name);
|
2024-10-17 19:06:22 +00:00
|
|
|
}
|
|
|
|
|
2024-10-20 18:07:18 +00:00
|
|
|
protected override void OnInitialRemove(string key)
|
2024-10-17 19:06:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|