about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs
blob: f723c57c8a99c4ff479818f28bc32b85d33d7c7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// using System.Text.Json;
// using ArcaneLibs.Extensions;
// using LibMatrix.Interfaces.Services;
//
// namespace LibMatrix.Utilities.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 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;
//     }
// }