using System.Text.Json; using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces.Services; using Microsoft.Extensions.Logging; namespace MatrixRoomUtils.Bot.Bot; public class FileStorageProvider : IStorageProvider { private readonly ILogger _logger; public string TargetPath { get; } /// /// Creates a new instance of . /// /// public FileStorageProvider(string targetPath) { new Logger(new LoggerFactory()).LogInformation("test"); Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}"); TargetPath = targetPath; if(!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } } public async Task SaveObjectAsync(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), ObjectExtensions.ToJson(value)); public async Task LoadObjectAsync(string key) => JsonSerializer.Deserialize(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); public async Task ObjectExistsAsync(string key) => File.Exists(Path.Join(TargetPath, key)); public async Task> GetAllKeysAsync() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList(); public async Task DeleteObjectAsync(string key) => File.Delete(Path.Join(TargetPath, key)); }