Class AppDataBase<StorageFolder, StorageFile>
- Namespace
- SunamoPlatformUwpInterop.AppData
- Assembly
- SunamoPlatformUwpInterop.dll
Base class for application data management providing settings storage, folder management and initialization of application directories.
public abstract class AppDataBase<StorageFolder, StorageFile> : IAppDataBase<StorageFolder, StorageFile>
Type Parameters
StorageFolderThe type representing a storage folder.
StorageFileThe type representing a storage file.
- Inheritance
-
AppDataBase<StorageFolder, StorageFile>
- Implements
-
IAppDataBase<StorageFolder, StorageFile>
- Derived
- Inherited Members
- Extension Methods
Fields
FolderWithAppsFiles
The file name used to store the path to the folder containing application files.
public const string FolderWithAppsFiles = "folderWithAppsFiles.txt"
Field Value
rootFolder
After startup will be set up in AppData/Roaming. Then from folderWithAppsFilesPath the app can load an alternative path. For all apps either AppData/Roaming or the alternative path will be valid.
protected StorageFolder rootFolder
Field Value
- StorageFolder
rootFolderPa
The root folder for the parent application.
protected StorageFolder rootFolderPa
Field Value
- StorageFolder
Properties
BasePath
Gets or sets the base path for the application data.
public string? BasePath { get; set; }
Property Value
LoadedCommonSettings
Gets or sets the dictionary of loaded common settings.
public Dictionary<string, string>? LoadedCommonSettings { get; set; }
Property Value
LoadedSettingsBool
Gets or sets the dictionary of loaded boolean settings.
public Dictionary<string, bool>? LoadedSettingsBool { get; set; }
Property Value
LoadedSettingsDateTime
Gets or sets the dictionary of loaded DateTime settings.
public Dictionary<string, DateTime>? LoadedSettingsDateTime { get; set; }
Property Value
LoadedSettingsList
Gets or sets the dictionary of loaded list settings.
public Dictionary<string, List<string>>? LoadedSettingsList { get; set; }
Property Value
LoadedSettingsOther
Gets or sets the dictionary of loaded string settings.
public Dictionary<string, string>? LoadedSettingsOther { get; set; }
Property Value
RijndaelBytesEncrypt
Gets or sets the Rijndael encryption function for byte lists.
public static Func<List<byte>, List<byte>>? RijndaelBytesEncrypt { get; set; }
Property Value
RootFolder
Gets or sets the root folder for the application data. This path already includes ThisApp.Name. Use with caution and always ensure you are not setting it to empty string.
public StorageFolder RootFolder { get; set; }
Property Value
- StorageFolder
RootFolderPa
Gets or sets the root folder for the parent application.
public StorageFolder RootFolderPa { get; set; }
Property Value
- StorageFolder
SunamoFolder
Gets or sets the Sunamo folder path.
public string? SunamoFolder { get; set; }
Property Value
Methods
AppendAllText(AppFolders, string, string)
Appends text content to a file in the specified application folder.
public Task AppendAllText(AppFolders appFolders, string fileName, string value)
Parameters
appFoldersAppFoldersThe application folder category.
fileNamestringThe file name.
valuestringThe text to append.
Returns
AppendAllText(string, string)
Appends text content to the specified file path.
public Task AppendAllText(string filePath, string value)
Parameters
Returns
CreateAppFoldersIfDontExists(CreateAppFoldersIfDontExistsArgs)
Creates application folders if they do not exist and loads all specified settings. If a key is prefixed with '!', the value will be decrypted using the provided Rijndael function.
public void CreateAppFoldersIfDontExists(CreateAppFoldersIfDontExistsArgs args)
Parameters
argsCreateAppFoldersIfDontExistsArgsThe arguments specifying the application name, settings keys and encryption functions.
GetFileCommonSettings(string)
Gets the file path for common settings. Must return always string, not StorageFile. In .NET Standard there is no StorageFile class and it is impossible to get Path.
public abstract string GetFileCommonSettings(string key)
Parameters
keystringThe settings key.
Returns
- string
The file path for the common settings file.
GetFileInSubfolder(AppFolders, string, string, string)
Gets the file path in a subfolder within the specified application folder.
public abstract StorageFile GetFileInSubfolder(AppFolders appFolders, string subfolder, string fileName, string extension)
Parameters
appFoldersAppFoldersThe application folder category.
subfolderstringThe subfolder name.
fileNamestringThe file name without extension.
extensionstringThe file extension.
Returns
- StorageFile
The full file path.
GetFolder(AppFolders)
Gets the path for the specified application folder.
public abstract StorageFolder GetFolder(AppFolders appFolders)
Parameters
appFoldersAppFoldersThe application folder category.
Returns
- StorageFolder
The folder path.
GetFolderWithAppsFiles()
Gets the path to the file that stores the folder with application files configuration.
public string GetFolderWithAppsFiles()
Returns
- string
The path to the folder with apps files configuration file.
GetPathForSettingsFile(string)
Gets the path for a settings file with the given key.
public string GetPathForSettingsFile(string key)
Parameters
keystringThe settings key.
Returns
- string
The full file path to the settings file.
GetSunamoFolder()
Gets the Sunamo folder path. Must be here as Task because in UWP everything is async.
public abstract StorageFolder GetSunamoFolder()
Returns
- StorageFolder
The Sunamo folder path.
ReadFileOfSettingsBool(string)
Reads a boolean settings value for the specified key. If the file does not exist or has empty content, creates it with false value.
public bool ReadFileOfSettingsBool(string key)
Parameters
keystringThe settings key.
Returns
- bool
The boolean settings value.
ReadFileOfSettingsDateTime(string)
Reads a DateTime settings value for the specified key.
public DateTime ReadFileOfSettingsDateTime(string key)
Parameters
keystringThe settings key.
Returns
- DateTime
The DateTime settings value.
ReadFileOfSettingsExistingDirectoryOrFile(string)
Reads a settings file value for an existing directory or file key. If the file does not exist, creates it with empty content.
public string ReadFileOfSettingsExistingDirectoryOrFile(string key)
Parameters
keystringThe settings key.
Returns
- string
The settings value.
ReadFileOfSettingsWorker<T>(IDictionary<string, T>, string)
Reads a value from the specified settings dictionary.
public T ReadFileOfSettingsWorker<T>(IDictionary<string, T> settingsDictionary, string key)
Parameters
settingsDictionaryIDictionary<string, T>The dictionary to read from.
keystringThe settings key.
Returns
- T
The settings value.
Type Parameters
TThe type of the settings value.
ReadFolderWithAppsFilesOrDefault()
Reads the folder with apps files path or returns the default value.
public string? ReadFolderWithAppsFilesOrDefault()
Returns
- string
The folder path or default value.
RootFolderCommon(bool)
Gets the root folder path for common application data.
public abstract string RootFolderCommon(bool isInFolderCommon)
Parameters
isInFolderCommonboolWhether to return the Common subfolder path.
Returns
- string
The common root folder path.
SaveFile(AppFolders, string, string)
Saves a file with the specified contents to the given application folder.
public Task<StorageFile> SaveFile(AppFolders appFolders, string fileName, string value)
Parameters
appFoldersAppFoldersThe application folder category.
fileNamestringThe file name.
valuestringThe content to write.
Returns
- Task<StorageFile>
The storage file that was saved to.
SaveFileOfSettings(string, string)
Saves a string value to a settings file.
public Task SaveFileOfSettings(string fileName, string value)
Parameters
Returns
SaveFileOfSettingsBool(string, bool)
Saves a boolean value to a settings file.
public Task SaveFileOfSettingsBool(string key, bool value)
Parameters
Returns
SaveFileOfSettingsDateTime(string, DateTime)
Saves a DateTime value to a settings file.
public Task SaveFileOfSettingsDateTime(string key, DateTime dateTime)
Parameters
Returns
SaveFileOfSettingsList(string, IEnumerable<string>)
Saves a list of strings to a settings file.
public Task SaveFileOfSettingsList(string key, IEnumerable<string> enumerable)
Parameters
keystringThe settings key.
enumerableIEnumerable<string>The enumerable of strings to save.