//public static void GetCurrentStateVariables(QAMgr QABot)
        //{
        //    AppStateInfo asi = new AppStateInfo(QABot.QuestionCount,QABot.ExerciseCount);
        //}

        public static void SaveCurrrentStateVariables(AppStateInfo asi)
        {
            DataContractSerializer dcs = new DataContractSerializer(typeof(AppStateInfo));

            using (FileStream fs = new FileStream(_appDataFileName, FileMode.Create))
            {
                dcs.WriteObject(fs, asi);
            }
        }
Exemple #2
0
        private void onLoad(object sender, EventArgs e)
        {
            Application.Idle += onIdle;
            AppStateInfo _savedStateData = StatusMgr.LoadSavedStateVariables();

            if (_savedStateData != null)
            {
                InitializeLoadedState(_savedStateData);
            }
            else
            {
                _currentAppState = new NormalState(this);//Application starts in the normal state for new user.
                _currentAppState.InitializeNew();
            }
        }
Exemple #3
0
 private void InitializeLoadedState(AppStateInfo loadedState)
 {
     if (string.Compare(loadedState.CurrentState, "RetakeState") == 0)
     {
         _currentAppState      = new RetakeState(this);
         QABot.FailedQuestions = loadedState.FailedQuestionsList;
     }
     else if (string.Compare(loadedState.CurrentState, "NormalState") == 0)
     {
         _currentAppState = new NormalState(this);
     }
     QABot.ExerciseCount = loadedState.CurrentExerciseNo;
     QABot.QuestionCount = loadedState.CurrentQuestionNo;
     QABot.SavedAnswers  = loadedState.SavedAnswers;
     _currentAppState.InitializeNew();
 }
        private void onSaveProgress(object sender, EventArgs e)
        {
            _qaControl.ApplicationState.SaveAnswer(_qaControl.CurrentAnswer);                                    //Save the last answer before exiting
            AppStateInfo currentStateVariables = QAControl.Instance.ApplicationState.GetCurrentStateVariables(); //Get the data to save.

            if (currentStateVariables != null)
            {
                try
                {
                    StatusMgr.SaveCurrrentStateVariables(currentStateVariables);
                    MessageBoxHelper.Info(this, "Progress Saved!");
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.Error(this, "Something went Wrong! Your Progress is not Saved" + ex.Message);
                    //Create artificial exit.
                }
            }
        }