aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Settings
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-07-11 12:37:11 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-07-11 12:37:11 +0300
commitbd49bdcb109a227130d7db6856e659b435d16530 (patch)
treedb55cfdc5dae423ccdba5c7efb1162d33bdcdc48 /Software/Visual_Studio/Tango.Settings
parentd65e5f1a23374de2872a73034e430e4a70ee4269 (diff)
downloadTango-bd49bdcb109a227130d7db6856e659b435d16530.tar.gz
Tango-bd49bdcb109a227130d7db6856e659b435d16530.zip
Embedded Tango.AnimatedGif !
Diffstat (limited to 'Software/Visual_Studio/Tango.Settings')
-rw-r--r--Software/Visual_Studio/Tango.Settings/SettingsManager.cs17
1 files changed, 16 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Settings/SettingsManager.cs b/Software/Visual_Studio/Tango.Settings/SettingsManager.cs
index cd8b97c92..88a3f59e1 100644
--- a/Software/Visual_Studio/Tango.Settings/SettingsManager.cs
+++ b/Software/Visual_Studio/Tango.Settings/SettingsManager.cs
@@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.Logging;
namespace Tango.Settings
{
@@ -37,6 +38,7 @@ namespace Tango.Settings
private List<SettingsBase> _settingsCollection;
private JsonSerializerSettings _jsonSettings;
+ private LogManager _logManager;
private bool _loaded;
/// <summary>
@@ -54,6 +56,7 @@ namespace Tango.Settings
/// </summary>
private SettingsManager()
{
+ _logManager = LogManager.Default;
FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Settings", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName) + ".json");
Folder = Path.GetDirectoryName(FilePath);
Directory.CreateDirectory(Folder);
@@ -88,12 +91,21 @@ namespace Tango.Settings
/// <returns></returns>
public T GetOrCreate<T>() where T : SettingsBase
{
- EnsureLoaded();
+ try
+ {
+ _logManager.Log("Retrieving settings for " + typeof(T).Name);
+ EnsureLoaded();
+ }
+ catch (Exception ex)
+ {
+ _logManager.Log(ex, "Error deserializing settings for " + typeof(T).Name);
+ }
var settings = _settingsCollection.SingleOrDefault(x => x.GetType() == typeof(T)) as T;
if (settings == null)
{
+ _logManager.Log("Settings for " + typeof(T).Name + " were not found. Initializing default settings.");
settings = Activator.CreateInstance<T>();
settings.SaveAction = Save;
_settingsCollection.Add(settings);
@@ -109,6 +121,8 @@ namespace Tango.Settings
{
if (File.Exists(FilePath))
{
+ _logManager.Log("Loading settings from " + FilePath + "...");
+
_settingsCollection = JsonConvert.DeserializeObject<List<SettingsBase>>(File.ReadAllText(FilePath), _jsonSettings);
foreach (var settings in _settingsCollection)
@@ -135,6 +149,7 @@ namespace Tango.Settings
{
EnsureLoaded();
+ _logManager.Log("Saving settings to " + FilePath + "...");
String json = JsonConvert.SerializeObject(_settingsCollection, _jsonSettings);
File.WriteAllText(FilePath, json);
}