Ejemplo n.º 1
0
 /// <summary>
 /// Attempt to save settings to file.
 /// </summary>
 /// <returns>Appropriate error message.</returns>
 public static string SaveSettingsToFile(Constants.QuestionOrder questionOrder, Constants.TermDisplay termDisplay, Constants.ProvideFeedback provideFeedback)
 {
     try
     {
         settings[0] = questionOrder.ToString();
         settings[1] = termDisplay.ToString();
         settings[2] = provideFeedback.ToString();
         File.WriteAllLines(Constants.SettingsFile, settings, Encoding.UTF8);
         return(string.Format(AppResources.SettingsSaveSuccessMessage));
     }
     catch (Exception ex)
     {
         return(string.Format(AppResources.SettingsSaveErrorMessage, ex.Message));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an array list of test questions.
        /// </summary>
        /// <param name="testFileName">The name of the test data file</param>
        /// <param name="questionOrder">Question order setting: Default to display questions as read from the file, Random to randomize the order.</param>
        /// <param name="termDisplay">Term display settings: TermAsQuestion to display terms as question (Default); DefinitionAsQuestion to display definitions as question; Mixed to mix it up.</param>
        /// <returns>A formatted list of test questions created from test data objects.</returns>
        public static List <TestQuestion> GetTest(string testFileName, Constants.QuestionOrder questionOrder, Constants.TermDisplay termDisplay)
        {
            List <TestQuestion> testQuestions = new List <TestQuestion>();
            List <Question>     testData      = ReadFile(testFileName);
            List <int>          ktIndex       = new List <int>();

            for (int x = 0; x < testData.Count; x++)
            {
                if (testData[x].QuestionType == Constants.QuestionType.K)
                {
                    ktIndex.Add(x);
                }
            }
            int ktCount = 0;

            for (int x = 0; x < testData.Count; x++)
            {
                Constants.QuestionType qt = testData[x].QuestionType;
                RandomNumbers          rn;
                switch (qt)
                {
                case Constants.QuestionType.K:
                    KeyTermQuestion kt = (KeyTermQuestion)testData[x];
                    int             ktNumberOfChoices = ((ktIndex.Count - 1) < 3 ? (ktIndex.Count - 1) : 3);
                    List <string>   ktTempChoices     = new List <string>();
                    rn = new RandomNumbers((ktIndex.Count - 1), ktCount, ktNumberOfChoices);
                    bool displayTermAsQuestion = true;
                    switch (termDisplay)
                    {
                    case Constants.TermDisplay.DefinitionAsQuestion:
                        displayTermAsQuestion = false;
                        break;

                    case Constants.TermDisplay.Mixed:
                        displayTermAsQuestion = (Random.Next(2) == 0 ? false : true);
                        break;

                    case Constants.TermDisplay.TermAsQuestion:
                    default:
                        break;
                    }
                    if (displayTermAsQuestion)
                    {
                        for (int y = 0; y <= ktNumberOfChoices; y++)
                        {
                            ktTempChoices.Add(((KeyTermQuestion)testData[ktIndex[rn.UniqueArray[y]]]).Definition);
                        }
                        testQuestions.Add(new TestQuestion(qt, kt.KeyTerm, kt.MediaType, kt.MediaFileName, ktNumberOfChoices, ktTempChoices, rn.IndexLocation, kt.Explanation));
                    }
                    else
                    {
                        for (int y = 0; y <= ktNumberOfChoices; y++)
                        {
                            ktTempChoices.Add(((KeyTermQuestion)testData[ktIndex[rn.UniqueArray[y]]]).KeyTerm);
                        }
                        testQuestions.Add(new TestQuestion(qt, kt.Definition, kt.MediaType, kt.MediaFileName, ktNumberOfChoices, ktTempChoices, rn.IndexLocation, kt.Explanation));
                    }
                    ktCount++;
                    break;

                case Constants.QuestionType.M:
                    MultipleChoiceQuestion mc            = (MultipleChoiceQuestion)testData[x];
                    List <string>          mcTempChoices = new List <string>();
                    rn = new RandomNumbers(mc.NumberOfChoices, 0, mc.NumberOfChoices);
                    for (int i = 0; i <= mc.NumberOfChoices; i++)
                    {
                        mcTempChoices.Add(mc.Choices[rn.UniqueArray[i]]);
                    }
                    testQuestions.Add(new TestQuestion(qt, mc.Question, mc.MediaType, mc.MediaFileName, mc.NumberOfChoices, mcTempChoices, rn.IndexLocation, mc.Explanation));
                    break;

                case Constants.QuestionType.T:
                    TrueFalseQuestion tf            = (TrueFalseQuestion)testData[x];
                    List <string>     tfTempChoices = new List <string> {
                        "true",
                        "false"
                    };
                    testQuestions.Add(new TestQuestion(qt, tf.Question, tf.MediaType, tf.MediaFileName, 1, tfTempChoices, (tf.Answer ? 0 : 1), tf.Explanation));
                    break;

                default:
                    throw new ArgumentException("Corrupt data. Check structure and values.");
                }
            }
            if (questionOrder == Constants.QuestionOrder.Random)
            {
                RandomNumbers qoArray = new RandomNumbers(testQuestions.Count);
                for (int x = 0; x < testQuestions.Count; x++)
                {
                    TestQuestion temp = testQuestions[x];
                    testQuestions[x] = testQuestions[qoArray.UniqueArray[x]];
                    testQuestions[qoArray.UniqueArray[x]] = temp;
                }
            }
            return(testQuestions);
        }