@ -12,18 +12,44 @@ public interface IAppSettingsProvider
/// <summary>
/// <summary>
/// Retrieves the app settings from the persistant location and loads them into memory.
/// Retrieves the app settings from the persistant location and loads them into memory.
/// Loading settings will override the currently stored settings in the memory.
/// Loading settings will override the currently stored settings in the memory.
/// If loading happens and there were already settings in the memory, a <see cref="LogWorthyEvent"/> is generated.
/// </summary>
/// </summary>
voidLoad();
voidLoad();
/// <summary>
/// <summary>
/// Saves the app settings to the persistant location.
/// Saves the app settings to the persistant location.
/// If the saving does not work, logs the exception as a <see cref="LogWorthyEvent"/> but does not throw an exception.
/// Rationale: A User is happier if the app is useable and does not remember settings than if the app always throws an exception on startup.
/// </summary>
/// </summary>
voidSave();
voidSave();
/// <summary>
/// Creates a new setting or overwrites the value of an existing setting in the memory (not persistent location). Settings are identified by key.
/// Informs about issues using the <see cref="LogWorthyEvent"/>.
/// </summary>
/// <param name="key">key of the setting, must not be empty or null</param>
/// <param name="value">value of the setting, must not be empty or null</param>
/// <returns>true if the setting is successfully written or overwritten</returns>
boolWriteSetting(stringkey,stringvalue);
boolWriteSetting(stringkey,stringvalue);
/// <summary>
/// Tries to read a setting from the memory (not persistent location). Settings are identified by key.
/// Informs about issues using the <see cref="LogWorthyEvent"/>.
/// If no setting with the given <paramref name="key"/> is found, the <paramref name="value"/> is set to <see cref="String.Empty"/>.
/// </summary>
/// <param name="key">key of the setting, must not be empty or null</param>
/// <param name="value">the found value or an empty string if no setting is found</param>
/// <returns>true when the setting exists and could be read successfully</returns>
boolTryReadSetting(stringkey,outstringvalue);
boolTryReadSetting(stringkey,outstringvalue);
/// <summary>
/// Tries to read a setting from the memory (not persistent location). Settings are identified by key.
/// Informs about issues using the <see cref="LogWorthyEvent"/>.
/// If no setting with the given <paramref name="key"/> is found, the setting is created with the given <paramref name="defaultValue"/>. <paramref name="value"/> is also set to <paramref name="defaultValue"/>.
/// </summary>
/// <param name="key">key of the setting, must not be empty or null</param>
/// <param name="value">the found value or an empty string if no setting is found</param>
/// <param name="defaultValue">the default value to initialize the setting with if it does not exist yet. must not be empty or null</param>
/// <returns>true when the setting could be read or was created successfully</returns>
message:$"'{nameof(WriteSetting)}'() cancelled because {foundSettings.Count} settings with the key '{key}' were found. Expected none or exactly one."));
message:$"'{nameof(WriteSetting)}()' cancelled because {foundSettings.Count} settings with the key '{key}' were found. Expected none or exactly one."));
returnfalse;// cancel
returnfalse;// cancel
}
}
@ -82,7 +96,7 @@ public class XmlAppSettingsProvider : IAppSettingsProvider