Search Framework:
SettingsManager
Namespace: WealthLab.Core
Parent: Object

The SettingsManager can manage a set of values of varying type that are keyed by strings. It has a built-in mechanism to automatically save its contents to a file on the user's local machine. SettingsManager is thread-safe.

Constructors
SettingsManager
public SettingsManager(string fileName, bool encrypt = false)

Pass the file name on the local computer to save the settings contents in the fileName parameter. Typically you would use the IHost interface (accessed by using WLHost.Instance) and its DataFolder property to determine the location of the save file. If you pass true in the encrypt parameter, the contents of the file will be encrypted.



Data Access Members
Get
public string Get(string key, string defaultValue)
public bool Get(string key, bool defaultValue)
public int Get(string key, int defaultValue)
public double Get(string key, double defaultValue)
public DateTime Get(string key, DateTime defaultValue)
public WLColor Get(string key, WLColor value)

The various overloaded Get methods return settings values keyed by the string key parameter. The following data types are supported:

  • string
  • bool
  • int
  • double
  • DateTime
  • WLColor

Set
public void Set(string key, string value)
public void Set(string key, bool value)
public void Set(string key, int value)
public void Set(string key, double value)
public void Set(string key, DateTime value)
public void Set(string key, WLColor value)

The various overloaded Set methods let you set values keyed by the string key parameter. After setting a value, the SettingsManager will automatically save its contents to disk, at a rate controlled by the SaveThrottleSeconds property. It also contains a built-in static CleanUp routine that WL8 calls upon shutdown, ensuring that any pending saves are written to disk. The following data types are supported:

  • string
  • bool
  • int
  • double
  • DateTime
  • WLColor


Members
FileName
public string FileName

The name of the file on the local computer where the SettingsManager saves its contents. This is initially established in the constructor.


FullDictionary
public Dictionary<string, string> FullDictionary

Provides access to the Dictionary that contains the SettingsManager entries.


IsEncrypted
public bool IsEncrypted

Determine whether or not SettingsManager encrypts its contents when saving to disk. This property can also be set in a constructor parameter.


SaveThrottleSeconds
public int SaveThrottleSeconds

Determine the value, in seconds, that the SettingsManager will wait between saving its contents to disk. The default value is 1. The SettingsManager will save only when required, as it senses changed data, but this throttle ensures that it does not bog down the system with many repeated saves in situation where many settings values are set one after another.