about summary refs log tree commit diff
path: root/MatrixRoomUtils.Bot/FileStorageProvider.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-26 02:43:54 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-27 17:43:00 +0200
commit3ed00f732a284b5a3e96e52d4e3a71869135869b (patch)
tree308cdd5c9891a676dc55cbf0e0e998ab5a74b2d2 /MatrixRoomUtils.Bot/FileStorageProvider.cs
parentWorking state, refactored Rory&::LibMatrix (diff)
downloadMatrixUtils-3ed00f732a284b5a3e96e52d4e3a71869135869b.tar.xz
Dependency injection stuff
Diffstat (limited to 'MatrixRoomUtils.Bot/FileStorageProvider.cs')
-rw-r--r--MatrixRoomUtils.Bot/FileStorageProvider.cs31
1 files changed, 0 insertions, 31 deletions
diff --git a/MatrixRoomUtils.Bot/FileStorageProvider.cs b/MatrixRoomUtils.Bot/FileStorageProvider.cs
deleted file mode 100644

index 8d99828..0000000 --- a/MatrixRoomUtils.Bot/FileStorageProvider.cs +++ /dev/null
@@ -1,31 +0,0 @@ -using System.Text.Json; -using MatrixRoomUtils.Core.Extensions; -using MatrixRoomUtils.Core.Interfaces.Services; - -namespace MatrixRoomUtils.Bot; - -public class FileStorageProvider : IStorageProvider { - public string TargetPath { get; } - - /// <summary> - /// Creates a new instance of <see cref="FileStorageProvider" />. - /// </summary> - /// <param name="targetPath"></param> - public FileStorageProvider(string targetPath) { - Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}"); - TargetPath = targetPath; - if(!Directory.Exists(targetPath)) { - Directory.CreateDirectory(targetPath); - } - } - - public async Task SaveObject<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), ObjectExtensions.ToJson(value)); - - public async Task<T?> LoadObject<T>(string key) => JsonSerializer.Deserialize<T>(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); - - public async Task<bool> ObjectExists(string key) => File.Exists(Path.Join(TargetPath, key)); - - public async Task<List<string>> GetAllKeys() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList(); - - public async Task DeleteObject(string key) => File.Delete(Path.Join(TargetPath, key)); -} \ No newline at end of file