Example #1
0
        private void Chk_randomOrderQuestions_CheckedChanged(object sender, EventArgs e)
        {
            Quiz.ProgressData.AskQuestionsInRandomOrder = chk_randomOrderQuestions.Checked;

            CardPicker.NewRound(Quiz);
            Program.frmQuizPractise.SetCard();
            QuizCore.SaveQuizProgress(Quiz);
        }
Example #2
0
 private void InQuiz_FormClosing(object sender, FormClosingEventArgs e)
 {
     QuizCore.SaveQuizProgress(Quiz);
     if (exitAppOnClose)
     {
         Application.Exit();
     }
 }
Example #3
0
        private void Chk_intelligentLearning_CheckedChanged(object sender, EventArgs e)
        {
            Quiz.ProgressData.FullTestInProgress = !chk_intelligentLearning.Checked;

            CardPicker.NewRound(Quiz);
            Program.frmQuizPractise.SetCard();
            Program.frmQuizPractise.UpdateCardSideTypeLabels();
            QuizCore.SaveQuizProgress(Quiz);
        }
Example #4
0
        private void Rdo_answerFront_CheckedChanged(object sender, EventArgs e)
        {
            Quiz.ProgressData.AnswerCardSide = rdo_answerFront.Checked ? QuizProgressData.CardSide.Front : QuizProgressData.CardSide.Back;

            CardPicker.NewRound(Quiz);
            Program.frmQuizPractise.SetCard();
            Program.frmQuizPractise.UpdateCardSideTypeLabels();
            QuizCore.SaveQuizProgress(Quiz);
        }
Example #5
0
        private void btn_editFrontSynonyms_Click(object sender, EventArgs e)
        {
            var editWordSynonyms = new EditWordSynonyms(Card, 1);

            if (editWordSynonyms.ShowDialog() == DialogResult.OK)
            {
                Card.FrontSynonyms = editWordSynonyms.Synonyms;
                QuizCore.SaveQuiz(Quiz, Quiz.QuizIdentity.FindQuizPath());
            }
        }
Example #6
0
        private void btn_editWord2_Click(object sender, EventArgs e)
        {
            var editWord = new EditWord(Card.Back);

            if (editWord.ShowDialog() == DialogResult.OK)
            {
                Card.Back = editWord.Word;
                QuizCore.SaveQuiz(Quiz, Quiz.QuizIdentity.FindQuizPath());
                UpdateSideLabels();
            }
        }
        private void nud_minAnsTriesSkip_ValueChanged(object sender, EventArgs e)
        {
            Quiz.ProgressData.MinimumTriesCountToConsiderSkippingQuestion = (int)nud_minAnsTriesSkip.Value;

            if (!Quiz.ProgressData.FullTestInProgress)
            {
                CardPicker.NewRound(Quiz);
                Program.frmQuizPractise.SetCard();
                QuizCore.SaveQuizProgress(Quiz);
            }
        }
        private void Rdo_lastNattemptsIntelligentLearning_CheckedChanged(object sender, EventArgs e)
        {
            if (rdo_lastNattemptsIntelligentLearning.Checked)
            {
                Quiz.ProgressData.IntelligentLearningLastAnswersBasisCount = (int)nud_intelligentLearningAttempsCount.Value;

                if (!Quiz.ProgressData.FullTestInProgress)
                {
                    CardPicker.NewRound(Quiz);
                    Program.frmQuizPractise.SetCard();
                    QuizCore.SaveQuizProgress(Quiz);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Marks all Cards as not answered this round, lowers the RoundToSkip variables and updated CurrentCards with a new selection.
        /// </summary>
        /// <param name="quiz"></param>
        public static void NewRound(Quiz quiz)
        {
            quiz.ProgressData.CorrectAnswersThisRound = 0;
            if (!quiz.ProgressData.FullTestInProgress)
            {
                var possibleCards = (from x in quiz.Cards
                                     let progress = x.GetProgressData(quiz)
                                                    where progress.RoundsToSkip == 0
                                                    orderby progress.GetLearningProgress(quiz.ProgressData) ascending
                                                    select x.Guid).ToList();

                if (possibleCards.Count > 0)
                {
                    quiz.ProgressData.CurrentCards = possibleCards.Take(10).ToList();
                }
                else
                {
                    var indexes = Enumerable.Range(0, 5).ToList();
                    Shuffle(indexes);
                    quiz.ProgressData.CurrentCards = indexes
                                                     .Where(i => i <= quiz.Cards.Count() - 1)
                                                     .Select(i => quiz.Cards[i].Guid).ToList();
                }
            }
            else
            {
                quiz.ProgressData.CurrentCards = quiz.Cards.Select(x => x.Guid).ToList();
                Shuffle(quiz.ProgressData.CurrentCards);
            }

            quiz.ProgressData.CurrentCard = Guid.Empty;

            // Update RoundsToSkip
            foreach (var cardProgress in quiz.ProgressData.CardProgress)
            {
                cardProgress.AskedThisRound = false;

                if (cardProgress.RoundsToSkip > 0)
                {
                    --cardProgress.RoundsToSkip;
                }
            }

            QuizCore.SaveQuizProgress(quiz);
        }
Example #10
0
        private void Finish()
        {
            sfd_quiz.InitialDirectory = ConfigManager.Config.StorageConfig.DefaultQuizSaveFolder;

            if (sfd_quiz.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            QuizPath = sfd_quiz.FileName;

            var quiz = new Quiz(Language1, Language2, MetaData.QUIZ_FILE_FORMAT_VERSION);

            quiz.Cards = Cards.ToList();

            QuizCore.SaveQuiz(quiz, QuizPath);

            DialogResult = DialogResult.OK;
        }
Example #11
0
        private void Btn_resetProgData_Click(object sender, EventArgs e)
        {
            var msg = MessageBox.Show("Are you sure you want to reset the quiz progress data? This will remove ALL progress for ALL quizzes. " +
                                      "Intelligent Learning will forget EVERYTHING you have done",
                                      "Reset Quiz Progress Data - SteelQuiz", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (msg == DialogResult.Yes)
            {
                QuizCore.BackupProgress();

                try
                {
                    System.IO.File.Delete(ConfigManager.Config.StorageConfig.QuizProgressFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"An error occurred while resetting quiz progress data:\r\n\r\n{ex.ToString()}", "SteelQuiz",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Application.Restart();
            }
        }
Example #12
0
        public bool Save(bool writeToDisk)
        {
            if (!Directory.Exists(txt_defaultQuizSaveFolder.Text))
            {
                MessageBox.Show("Specified default quiz save folder path doesn't exist", "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            ConfigManager.Config.StorageConfig.DefaultQuizSaveFolder = txt_defaultQuizSaveFolder.Text;

            var oldPath = ConfigManager.Config.StorageConfig.QuizProgressFile;

            string newPath;

            if (txt_quizProgPath.Text == Path.GetDirectoryName(QuizCore.PROGRESS_FILE_DEFAULT))
            {
                // quiz progress file should have the filename "QuizProgress.json" in the default folder, for compatibility reasons
                newPath = QuizCore.PROGRESS_FILE_DEFAULT;
            }
            else
            {
                newPath = Path.Combine(txt_quizProgPath.Text, "SteelQuizProgress.json");
            }

            if (newPath == oldPath)
            {
                return(true);
            }

            if (!Directory.Exists(Path.GetDirectoryName(newPath)))
            {
                MessageBox.Show("Selected directory to store quiz progress data in does not exist", "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            try
            {
                QuizCore.BackupProgress();
            }
            catch (Exception ex)
            {
                txt_quizProgPath.Text = Path.GetDirectoryName(oldPath);
                throw ex;
            }

            if (File.Exists(newPath) && File.Exists(oldPath))
            {
                var conflictSolution = new QuizProgressConflict();
                if (conflictSolution.ShowDialog() != DialogResult.OK)
                {
                    txt_quizProgPath.Text = Path.GetDirectoryName(oldPath);
                    return(false);
                }

                if (conflictSolution.ConflictResult == ConflictResult.MergePrioTarget)
                {
                    var merge = QuizProgressMerger.Merge(newPath, oldPath, newPath);
                    if (!merge)
                    {
                        return(false);
                    }
                    File.Delete(oldPath);
                }
                else if (conflictSolution.ConflictResult == ConflictResult.MergePrioCurrent)
                {
                    var merge = QuizProgressMerger.Merge(oldPath, newPath, newPath);
                    if (!merge)
                    {
                        return(false);
                    }
                    File.Delete(oldPath);
                }
                else if (conflictSolution.ConflictResult == ConflictResult.KeepTarget)
                {
                    try
                    {
                        QuizCore.BackupProgress();
                    }
                    catch (Exception ex)
                    {
                        txt_quizProgPath.Text = Path.GetDirectoryName(oldPath);
                        throw ex;
                    }
                    File.Delete(oldPath);
                }
                else if (conflictSolution.ConflictResult == ConflictResult.OverwriteTarget)
                {
                    try
                    {
                        QuizCore.BackupProgress();
                    }
                    catch (Exception ex)
                    {
                        txt_quizProgPath.Text = Path.GetDirectoryName(oldPath);
                        throw ex;
                    }
                    File.Delete(newPath);
                    File.Move(oldPath, newPath);
                }
            }
            else if (File.Exists(oldPath))
            {
                File.Move(oldPath, newPath);
            }

            ConfigManager.Config.StorageConfig.QuizProgressFile = newPath;

            if (writeToDisk)
            {
                ConfigManager.SaveConfig();
            }

            QuizCore.LoadQuizAccessData();
            Program.frmDashboard.PopulateQuizList();
            if (Program.frmDashboard.LoadedQuiz != null)
            {
                // Reload quiz
                Program.frmDashboard.LoadedQuiz = QuizCore.LoadQuiz(Program.frmDashboard.LoadedQuiz.QuizIdentity.FindQuizPath());
                Program.frmDashboard.UpdateQuizOverview();
            }

            return(true);
        }
Example #13
0
        private bool SaveQuiz(bool saveAs = false, string customPath = null)
        {
            string path = null;

            if (customPath == null)
            {
                if (QuizPath == null || saveAs)
                {
                    sfd_quiz.InitialDirectory = ConfigManager.Config.StorageConfig.DefaultQuizSaveFolder;
                    int untitledCounter = 1;
                    path = $"Untitled{ untitledCounter }.steelquiz";
                    while (File.Exists(Path.Combine(QuizCore.QUIZ_FOLDER_DEFAULT, path)))
                    {
                        ++untitledCounter;
                        path = $"Untitled{ untitledCounter }.steelquiz";
                    }

                    var sfd = sfd_quiz.ShowDialog();
                    if (sfd != DialogResult.OK)
                    {
                        return(false);
                    }

                    if (QuizPath != sfd_quiz.FileName)
                    {
                        QuizGuid = Guid.NewGuid(); // create new guid if path is not the same
                    }
                    path = sfd_quiz.FileName;
                }
                else
                {
                    path = QuizPath;
                }
            }
            else
            {
                path = customPath;
            }

            UseWaitCursor = true;

            var quiz = ConstructQuiz();

            AtomicIO.AtomicWrite(path, JsonConvert.SerializeObject(quiz, Formatting.Indented));

            if (customPath == null)
            {
                QuizPath             = path;
                ChangedSinceLastSave = false;
            }

            QuizCore.LoadQuizAccessData();

            QuizCore.QuizIdentities[quiz.GUID]  = new QuizIdentity(quiz.GUID, QuizPath);
            QuizCore.QuizAccessTimes[quiz.GUID] = DateTime.Now;

            QuizCore.SaveQuizAccessData();

            UseWaitCursor = false;

            ShowNotification("Quiz has been saved", 3000);
            return(true);
        }