diff --git a/LibMatrix/Interfaces/Services/IStorageProvider.cs b/LibMatrix/Interfaces/Services/IStorageProvider.cs
index 165e7df..f7e5488 100644
--- a/LibMatrix/Interfaces/Services/IStorageProvider.cs
+++ b/LibMatrix/Interfaces/Services/IStorageProvider.cs
@@ -1,3 +1,7 @@
+using System.Text.Json;
+using System.Text.Json.Serialization.Metadata;
+using LibMatrix.Responses;
+
namespace LibMatrix.Interfaces.Services;
public interface IStorageProvider {
@@ -17,6 +21,13 @@ public interface IStorageProvider {
Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject<T>(key, value)!");
throw new NotImplementedException();
}
+
+ public Task SaveObjectAsync<T>(string key, T value, JsonTypeInfo<T> jsonTypeInfo) {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObjectAsync<T>(key, value, typeInfo), using default implementation w/ MemoryStream!");
+ var ms = new MemoryStream();
+ JsonSerializer.Serialize(ms, value, jsonTypeInfo);
+ return SaveStreamAsync(key, ms);
+ }
// load
public Task<T?> LoadObjectAsync<T>(string key) {
@@ -24,6 +35,12 @@ public interface IStorageProvider {
throw new NotImplementedException();
}
+ public async Task<T?> LoadObjectAsync<T>(string key, JsonTypeInfo<T> jsonTypeInfo) {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject<T>(key, typeInfo), using default implementation!");
+ await using var stream = await LoadStreamAsync(key);
+ return JsonSerializer.Deserialize(stream!, jsonTypeInfo);
+ }
+
// check if exists
public Task<bool> ObjectExistsAsync(string key) {
Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement ObjectExists(key)!");
@@ -31,7 +48,7 @@ public interface IStorageProvider {
}
// get all keys
- public Task<List<string>> GetAllKeysAsync() {
+ public Task<IEnumerable<string>> GetAllKeysAsync() {
Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement GetAllKeys()!");
throw new NotImplementedException();
}
@@ -53,4 +70,18 @@ public interface IStorageProvider {
Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement LoadStream(key)!");
throw new NotImplementedException();
}
+
+ // copy
+ public async Task CopyObjectAsync(string sourceKey, string destKey) {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement CopyObject(sourceKey, destKey), using load + save!");
+ var data = await LoadObjectAsync<object>(sourceKey);
+ await SaveObjectAsync(destKey, data);
+ }
+
+ // move
+ public async Task MoveObjectAsync(string sourceKey, string destKey) {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement MoveObject(sourceKey, destKey), using copy + delete!");
+ await CopyObjectAsync(sourceKey, destKey);
+ await DeleteObjectAsync(sourceKey);
+ }
}
\ No newline at end of file
|