diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-09-05 06:28:52 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-09-05 06:28:52 +0200 |
commit | cf455ed8de20bbee011289223e7d8d5775dfd69e (patch) | |
tree | cbdfdbc207af64a105b4d21941a6f0e71ca65e9d /ExampleBots/MediaModeratorPoC/Bot/FileStorageProvider.cs | |
parent | Add start of Media Moderator PoC bot (diff) | |
download | LibMatrix-cf455ed8de20bbee011289223e7d8d5775dfd69e.tar.xz |
Media moderator PoC works, abstract command handling to library
Diffstat (limited to 'ExampleBots/MediaModeratorPoC/Bot/FileStorageProvider.cs')
-rw-r--r-- | ExampleBots/MediaModeratorPoC/Bot/FileStorageProvider.cs | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/ExampleBots/MediaModeratorPoC/Bot/FileStorageProvider.cs b/ExampleBots/MediaModeratorPoC/Bot/FileStorageProvider.cs deleted file mode 100644 index d5b991a..0000000 --- a/ExampleBots/MediaModeratorPoC/Bot/FileStorageProvider.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Text.Json; -using ArcaneLibs.Extensions; -using LibMatrix.Interfaces.Services; -using Microsoft.Extensions.Logging; - -namespace MediaModeratorPoC.Bot; - -public class FileStorageProvider : IStorageProvider { - private readonly ILogger<FileStorageProvider> _logger; - - public string TargetPath { get; } - - /// <summary> - /// Creates a new instance of <see cref="FileStorageProvider" />. - /// </summary> - /// <param name="targetPath"></param> - public FileStorageProvider(string targetPath) { - new Logger<FileStorageProvider>(new LoggerFactory()).LogInformation("test"); - Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}"); - TargetPath = targetPath; - if(!Directory.Exists(targetPath)) { - Directory.CreateDirectory(targetPath); - } - } - - public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson()); - - public async Task<T?> LoadObjectAsync<T>(string key) => JsonSerializer.Deserialize<T>(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); - - public Task<bool> ObjectExistsAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key))); - - public Task<List<string>> GetAllKeysAsync() => Task.FromResult(Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList()); - - public Task DeleteObjectAsync(string key) { - File.Delete(Path.Join(TargetPath, key)); - return Task.CompletedTask; - } -} |