public static void SaveCurrentState(string filename, AppState currentState) { DataContractSerializer dcs = new DataContractSerializer(typeof(AppState)); if (filename != null) { using (FileStream fs = new FileStream(filename, FileMode.Create)) { dcs.WriteObject(fs, currentState); } } }
public static AppState LoadState(string filename) { if (File.Exists(filename)) { AppState _loadedState = new AppState(); DataContractSerializer dcs = new DataContractSerializer(typeof(AppState)); using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { _loadedState = (AppState)dcs.ReadObject(fs); } return _loadedState; } return null; }
private static void GetLoadedState(AppState SavedState) { QAData.QuestCount = SavedState.QuestionNo; QAData.ResourceArray = SavedState.CurrentResources; QAData.UserAnswers = SavedState.CurrentAnswers; wrongAnswersIndices = SavedState.CurrentWrongAnswers; wrongAnswersIndex = SavedState.WrongAnswerIndex; exerciseCounter = SavedState.CurrentExerciseIndex; }