/// <summary> /// Saves the program state to the disk in JSON format. /// </summary> /// <param name="path"> Path on the disk with the file name, where the file should be saved.</param> /// <param name="userMemento">Memento holding ready to serialize user state.</param> /// <param name="wordMemento">Memento holding ready to serialize word storage.</param> /// <returns>True if save, false otherwise.</returns> public static bool SaveToDisk(NPath path, UserStateMemento userMemento, WordStoreMemento wordMemento) { path.CreateFile(); var temporaryData = new TemporaryData { mWordStore = wordMemento.GetData(), mUserState = userMemento.GetData() }; try { path.WriteAllText(JsonConvert.SerializeObject(temporaryData, Formatting.Indented)); } catch (Exception exception) { Log.Error("Error while saving: {0}: {1}", exception.Source, exception.Message); return(false); } return(true); }
/// <summary> /// Replaces the user state with the one stores in a given memento. /// </summary> public void OverwriteUserState(UserStateMemento memento) { mUserState = memento.GetData(); }