public void Load() { try { var serialized = System.IO.File.ReadAllText(file); var json = JsonConvert.DeserializeObject <StorageJSON>(serialized); SettingsStorage.getInstance().update(json.settings); WordStorage.getInstance().LoadWords(json.words); } catch (Exception e) { Console.WriteLine("Could not load file because it doesn't exist"); } }
public void Save() { Console.WriteLine("Saving changes..."); var serialized = JsonConvert.SerializeObject(new StorageJSON() { settings = SettingsStorage.getInstance().getSettings(), words = WordStorage.getInstance().getWords() }); System.IO.Directory.CreateDirectory(folder); System.IO.File.WriteAllText(file, serialized); Console.WriteLine("Changes saved!"); }
public void Setup() { Load(); saveTimer = new System.Timers.Timer(); // save 5s after last change saveTimer.Interval = 1000 * 5; saveTimer.Elapsed += onSaveTimerExpire; var wordStorage = WordStorage.getInstance(); wordStorage.wordDeleted += (_) => { StartSaveTimer(); }; wordStorage.wordsUpdated += (_) => { StartSaveTimer(); }; wordStorage.wordUpdated += (_) => { StartSaveTimer(); }; SettingsStorage.getInstance().settingsUpdated += (_) => { StartSaveTimer(); }; }