/// <summary>
/// Writes a setting to the configuration.
/// </summary>
/// <param name="key">Key of item to write.</param>
/// <param name="value">Value of item to write.</param>
/// <returns>True if successful, otherwise false.</returns>
public static bool WriteSetting(string key, string value)
{
try
{
key = key.ToLower();
Trace.WriteLine(key + " : " + value);
string json = "";
if (File.Exists(Paths.CONFIG + ".gz"))
{
//json = File.ReadAllText(Paths.CONFIG);
json = GZip.DecompressString(File.ReadAllBytes(Paths.CONFIG + ".gz"));
}
var settings = JsonConvert.DeserializeObject <SerializableDictionary <string, string> >(json);
if (settings == null)
{
settings = new SerializableDictionary <string, string>();
}
settings[key] = value;
//File.WriteAllText(Paths.CONFIG, JsonConvert.SerializeObject(settings));
File.WriteAllBytes(Paths.CONFIG + ".gz", GZip.CompressString(JsonConvert.SerializeObject(settings)));
return(true);
}
catch (Exception ex)
{
Trace.WriteLine("Error writing app settings: " + ex.Message);
return(false);
}
}