using HermesSocketLibrary.db; using HermesSocketLibrary.Requests.Messages; using HermesSocketServer.Store.Internal; using HermesSocketServer.Validators; namespace HermesSocketServer.Store { public class VoiceStore : AutoSavedStore { private readonly VoiceIdValidator _idValidator; private readonly VoiceNameValidator _nameValidator; 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) { _idValidator = voiceIdValidator; _nameValidator = voiceNameValidator; _database = database; _logger = logger; } public override async Task Load() { string sql = "SELECT id, name FROM \"TtsVoice\";"; await _database.Execute(sql, new Dictionary(), (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."); } protected override void OnInitialAdd(string key, TTSVoice value) { _idValidator.Check(value.Id); _nameValidator.Check(value.Name); } protected override void OnInitialModify(string key, TTSVoice value) { _nameValidator.Check(value.Name); } protected override void OnInitialRemove(string key) { } } }