Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> <!-- 👉 It is imperative to resolve ONE ISSUE PER PR and avoid making multiple changes unless the changes interrelate with each other --> <!-- 📝 Please always keep the "☑️ Allow edits by maintainers" button checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 --> ## Fixes #3903 <!-- Add the relevant issue number after the "#" mentioned above (for ex: "## Fixes #1234") which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more options below that apply to this PR. --> <!-- - Bugfix --> - Feature <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> The ObjectStorage helper interfaces and implementations currently live in the `*.Uwp` package. This means that they are not consumable from NetStandard projects, such as the `CommunityToolkit.Graph` package. In addition, the `IObjectStorageHelper` is a mixture of support for both dictionary style settings storage, with some file storage features as well. Currently, supporting both file and folder scenarios is odd/difficult for storage endpoints that don't operate in a similar manner to `Windows.Storage.ApplicationData`. Lastly, the support for file storage in `IObjectStorageHelper` is not complete and missing some basic CRUD operations that can make it difficult to work with in real-world application scenarios. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> I've done a few things: 1. Deprecated the existing structures in the `Microsoft.Toolkit.Uwp/Helpers/ObjectStorage` folder: - `BaseObjectStorageHelper` - `IObjectSerializer` - `IObjectStorageHelper` - `LocalObjectStorageHelper` - `SystemSerializer` 2. Migrated some of the previous structures up into the `Microsoft.Toolkit/Helpers/ObjectStorage` folder so that they are consumable from NetStandard: - `IObjectSerializer` - `SystemSerializer` 3. Created new interfaces to replace the functionality defined in the now defunct `IObjectStorageHelper`: - `ISettingsStorageHelper` - Interop with values as key/value pairs, like a dictionary. - `IFileStorageHelper` - Interop with a file system to store values in files and folders. 4. Replaced the functionality provided by `BaseObjectStorageHelper` and `LocalObjectStorageHelper` with an implementation of `ISettingsStorageHelper` and `IFileStorageHelper`: - `ApplicationDataStorageHelper` - Interop with local settings and files through `Windows.Storage.ApplicationData`. Use it like so: ``` ApplicationDataStorageHelper appDataStorageHelper = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer()); // Save and Read simple objects string keySimpleObject = "simple"; appDataStorageHelper.Save(keySimpleObject, 42); appDataStorageHelper.TryRead<string>(keySimpleObject, out string result); // Save and Read complex objects string complexObjectKey = "complexObject"; await appDataStorageHelper.SaveFileAsync(complexObjectKey, new MyComplexObject()); var complexObject = await appDataStorageHelper.ReadFileAsync<MyComplexObject>(complexObjectKey); // Complex object example public class MyComplexObject { public string MyContent { get; set; } public List<string> MyContents { get; set; } public List<MyComplexObject> MyObjects { get; set; } } ``` Altogether, this provides a transition path from the previous ObjectStorage constructs to a more granular set of interfaces with identical signatures plus enhanced support for file and folder CRUD operations. ## PR Checklist Please check if your PR fulfills the following requirements: - [x] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [x] Sample in sample app has been added / updated (for bug fixes / features) - [x] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [x] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [x] Tests for the changes have been added (for bug fixes / features) (if applicable) - [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [x] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information Looking for feedback!
- Loading branch information