From 3601834fe869765f9cda2d6c99e8818b2854dc8f Mon Sep 17 00:00:00 2001 From: Nick Randolph Date: Sat, 3 Jun 2023 00:02:36 +1000 Subject: [PATCH 1/2] chore(docs): Xml docs --- src/Uno.Extensions.Storage/IDataFolderProvider.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Uno.Extensions.Storage/IDataFolderProvider.cs b/src/Uno.Extensions.Storage/IDataFolderProvider.cs index 9e0227ce13..8d27cd0271 100644 --- a/src/Uno.Extensions.Storage/IDataFolderProvider.cs +++ b/src/Uno.Extensions.Storage/IDataFolderProvider.cs @@ -1,6 +1,12 @@ namespace Uno.Extensions.Storage; +/// +/// Interface for providing the data folder path for the application +/// public interface IDataFolderProvider { + /// + /// The path to the application data folder + /// string? AppDataPath { get; } } From 978680332c4de2124719cde2b89e9765b5296c0f Mon Sep 17 00:00:00 2001 From: Nick Randolph Date: Mon, 5 Jun 2023 12:49:07 +1000 Subject: [PATCH 2/2] chore(docs): Xml docs for storage --- .../AppConfiguration.cs | 2 +- src/Uno.Extensions.Storage.UI/GlobalUsings.cs | 4 +- .../HostBuilderExtensions.cs | 29 ++++++---- .../ServiceCollectionExtensions.cs | 13 +---- .../KeyValueStorageConfiguration.cs | 24 +------- .../KeyValueStorageConfigurationExtensions.cs | 16 +++++ .../KeyValueStorageExtensions.cs | 58 ++++++++++++++++--- .../KeyValueStorageSettings.cs | 12 ++++ .../StorageExtensions.cs | 13 ++++- 9 files changed, 116 insertions(+), 55 deletions(-) create mode 100644 src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfigurationExtensions.cs create mode 100644 src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageSettings.cs diff --git a/src/Uno.Extensions.Configuration/AppConfiguration.cs b/src/Uno.Extensions.Configuration/AppConfiguration.cs index 30f688586f..7c046a0a88 100644 --- a/src/Uno.Extensions.Configuration/AppConfiguration.cs +++ b/src/Uno.Extensions.Configuration/AppConfiguration.cs @@ -1,6 +1,6 @@ namespace Uno.Extensions.Configuration; -public class AppConfiguration +internal static class AppConfiguration { public const string Prefix = "appsettings"; public const string FileName = $"{Prefix}.json"; diff --git a/src/Uno.Extensions.Storage.UI/GlobalUsings.cs b/src/Uno.Extensions.Storage.UI/GlobalUsings.cs index b6fb7a65b1..0ecbc79f87 100644 --- a/src/Uno.Extensions.Storage.UI/GlobalUsings.cs +++ b/src/Uno.Extensions.Storage.UI/GlobalUsings.cs @@ -2,6 +2,7 @@ global using System.Collections.Generic; global using System.IO; global using System.Linq; +global using System.Reflection; global using System.Threading; global using System.Threading.Tasks; global using Microsoft.Extensions.DependencyInjection; @@ -9,6 +10,7 @@ global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Options; global using Uno.Extensions.Configuration; +global using Uno.Extensions.DependencyInjection; global using Uno.Extensions.Logging; global using Uno.Extensions.Serialization; global using Uno.Extensions.Storage; @@ -18,7 +20,7 @@ global using Windows.Storage; #if WINUI -global using Microsoft.UI.Dispatching; + global using Microsoft.UI.Dispatching; global using Microsoft.UI.Xaml; global using Microsoft.UI.Xaml.Controls; global using Microsoft.UI.Xaml.Controls.Primitives; diff --git a/src/Uno.Extensions.Storage.UI/HostBuilderExtensions.cs b/src/Uno.Extensions.Storage.UI/HostBuilderExtensions.cs index 3eba98c636..4df48b997a 100644 --- a/src/Uno.Extensions.Storage.UI/HostBuilderExtensions.cs +++ b/src/Uno.Extensions.Storage.UI/HostBuilderExtensions.cs @@ -1,23 +1,32 @@ - - -using Uno.Extensions.Configuration; - -namespace Uno.Extensions; +namespace Uno.Extensions; +/// +/// Extensions for working with . +/// public static class HostBuilderExtensions { + /// + /// Registers storage services. + /// + /// The host builder instance to register with + /// Callback for configuring services + /// The updated host builder instance public static IHostBuilder UseStorage( this IHostBuilder hostBuilder, Action configure) - { - return hostBuilder.UseStorage((context, builder) => configure.Invoke(builder)); - } + => hostBuilder.UseStorage((context, builder) => configure.Invoke(builder)); + /// + /// Registers storage services + /// + /// The host builder instance to register with + /// Callback for configuring services + /// public static IHostBuilder UseStorage( - this IHostBuilder builder, + this IHostBuilder hostBuilder, Action? configure = default) { - return builder + return hostBuilder .UseConfiguration( configure: configBuilder => { diff --git a/src/Uno.Extensions.Storage.UI/ServiceCollectionExtensions.cs b/src/Uno.Extensions.Storage.UI/ServiceCollectionExtensions.cs index b13d06d27d..ea7557e91e 100644 --- a/src/Uno.Extensions.Storage.UI/ServiceCollectionExtensions.cs +++ b/src/Uno.Extensions.Storage.UI/ServiceCollectionExtensions.cs @@ -1,17 +1,10 @@ -using System.Reflection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Uno.Extensions.DependencyInjection; +namespace Uno.Extensions; -namespace Uno.Extensions; - -public static class ServiceCollectionExtensions +internal static class ServiceCollectionExtensions { - public static IServiceCollection AddFileStorage(this IServiceCollection services) - { - return services + => services .AddSingleton(); - } private static TKeyValueStorage CreateKeyValueStorage( this IServiceProvider sp, diff --git a/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfiguration.cs b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfiguration.cs index d932861a9f..79bc22a639 100644 --- a/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfiguration.cs +++ b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfiguration.cs @@ -1,28 +1,6 @@ namespace Uno.Extensions.Storage.KeyValueStorage; -public record KeyValueStorageConfiguration : KeyValueStorageSettings +internal record KeyValueStorageConfiguration : KeyValueStorageSettings { public IDictionary Providers { get; init; } = new Dictionary(); - - -} - -internal static class KeyValueStorageConfigurationExtensions -{ - public static KeyValueStorageSettings GetSettingsOrDefault(this KeyValueStorageConfiguration? config, string name) - { - if (config?.Providers.TryGetValue(name, out var settings) ?? false) - { - return settings; - } - - // If there isn't a match for settings for the supplied name, return - // the default settings - return config ?? new KeyValueStorageSettings(); - } -} - -public record KeyValueStorageSettings -{ - public bool DisableInMemoryCache { get; init; } } diff --git a/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfigurationExtensions.cs b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfigurationExtensions.cs new file mode 100644 index 0000000000..6726812893 --- /dev/null +++ b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageConfigurationExtensions.cs @@ -0,0 +1,16 @@ +namespace Uno.Extensions.Storage.KeyValueStorage; + +internal static class KeyValueStorageConfigurationExtensions +{ + public static KeyValueStorageSettings GetSettingsOrDefault(this KeyValueStorageConfiguration? config, string name) + { + if (config?.Providers.TryGetValue(name, out var settings) ?? false) + { + return settings; + } + + // If there isn't a match for settings for the supplied name, return + // the default settings + return config ?? new KeyValueStorageSettings(); + } +} diff --git a/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageExtensions.cs b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageExtensions.cs index 1296fdae3f..b67ec7c9de 100644 --- a/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageExtensions.cs +++ b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageExtensions.cs @@ -1,13 +1,30 @@ namespace Uno.Extensions.Storage.KeyValueStorage; +/// +/// Extensions for working with . +/// public static class KeyValueStorageExtensions { + /// + /// Determines if the storage contains the specified key. + /// + /// The storage instance + /// The key to search for + /// CancellationToken to cancel operation + /// True if storage contains key public static async ValueTask ContainsKey(this IKeyValueStorage storage, string key, CancellationToken ct) { var keys = await storage.GetKeysAsync(ct); return keys.Contains(key); } + /// + /// Gets a value from the storage as a string + /// + /// The storage instance + /// The key to retrieve + /// CancellationToken to cancel operation + /// The value, or null if key not in storage public static async ValueTask GetStringAsync( this IKeyValueStorage storage, string key, @@ -21,16 +38,28 @@ public static async ValueTask ContainsKey(this IKeyValueStorage storage, s return default; } + /// + /// Retrieves all key/value pairs from the storage. + /// + /// The storage instance + /// CancellationToken to cancel operation + /// Dictionary of key-value pairs public static ValueTask> GetAllValuesAsync( this IKeyValueStorage storage, CancellationToken ct) - { - return GetAllValuesAsync(storage, _ => true, ct); - } + => GetAllValuesAsync(storage, _ => true, ct); + + /// + /// Retrieves all key/value pairs from the storage that match the predicate. + /// + /// The storage instance + /// The predicate to invoke to determine if pair should be returned + /// CancellationToken to cancel operation + /// Dictionary of key-value pairs public static async ValueTask> GetAllValuesAsync( - this IKeyValueStorage storage, - Func predicate, - CancellationToken ct) + this IKeyValueStorage storage, + Func predicate, + CancellationToken ct) { var dict = new Dictionary(); var keys = await storage.GetKeysAsync(ct); @@ -45,13 +74,24 @@ public static async ValueTask> GetAllValuesAsync( return dict; } + /// + /// Clear all values from the storage. + /// + /// The storage instance + /// CancellationToken to cancel operation + /// Task to await public static ValueTask ClearAllAsync( this IKeyValueStorage storage, CancellationToken ct) - { - return ClearAllAsync(storage, _ => true, ct); - } + => ClearAllAsync(storage, _ => true, ct); + /// + /// Clear all values from storage that match the predicate. + /// + /// The storage instance + /// The predicate to invoke to determine if pair should be cleared + /// CancellationToken to cancel operation + /// Task to await public static async ValueTask ClearAllAsync( this IKeyValueStorage storage, Func predicate, diff --git a/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageSettings.cs b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageSettings.cs new file mode 100644 index 0000000000..9b039d014b --- /dev/null +++ b/src/Uno.Extensions.Storage/KeyValueStorage/KeyValueStorageSettings.cs @@ -0,0 +1,12 @@ +namespace Uno.Extensions.Storage.KeyValueStorage; + +/// +/// Record for storing settings for a key value storage provider. +/// +public record KeyValueStorageSettings +{ + /// + /// Gets or sets whether in-memory cache should be disabled. + /// + public bool DisableInMemoryCache { get; init; } +} diff --git a/src/Uno.Extensions.Storage/StorageExtensions.cs b/src/Uno.Extensions.Storage/StorageExtensions.cs index 249ff1d90d..520b36cf39 100644 --- a/src/Uno.Extensions.Storage/StorageExtensions.cs +++ b/src/Uno.Extensions.Storage/StorageExtensions.cs @@ -1,11 +1,22 @@ namespace Uno.Extensions.Storage; +/// +/// Extensions for working with . +/// public static class StorageExtensions { + /// + /// Reads the contents of a file and deserializes to the specified type + /// + /// The type to deserialize to + /// The storage instance + /// The serializer to use + /// The relative path of the file to read from + /// The instance read, or null if file isn't found public static async Task ReadPackageFileAsync(this IStorage storage, ISerializer serializer, string fileName) { using var stream = await storage.OpenPackageFileAsync(fileName); - if(stream is null) + if (stream is null) { return default; }