static void ProcessQuestions(Exam exam, string question) { var splitQuestion = question.Split('\n'); var splitHeader = splitQuestion[0].Split('.'); exam.Categories[ToInt32(splitHeader[0]) - INDEX_ADJUST].Name = splitHeader.Length >= 3 ? splitHeader[2] : $"Category {splitHeader[0]}"; var thisQuestion = exam.Categories[ToInt32(splitHeader[0]) - INDEX_ADJUST].Questions[ToInt32(splitHeader[1]) - INDEX_ADJUST]; thisQuestion.Text = ConvertFromHtml(Split(splitQuestion[1], "<br>")[0].Trim()); thisQuestion.QuestionType = ParseQuestionType(splitQuestion[2]); switch (thisQuestion.QuestionType) { case QuestionType.TrueFalse: thisQuestion.A.Text = "True"; thisQuestion.B.Text = "False"; thisQuestion.SetCorrectAnswer(ParseAnswers(splitQuestion[5].Trim())); break; default: thisQuestion.A.Text = ConvertFromHtml(splitQuestion[3].Trim()); thisQuestion.B.Text = ConvertFromHtml(splitQuestion[4].Trim()); thisQuestion.C.Text = ConvertFromHtml(splitQuestion[5].Trim()); thisQuestion.D.Text = ConvertFromHtml(splitQuestion[6].Trim()); thisQuestion.E.Text = ConvertFromHtml(splitQuestion[7].Trim()); thisQuestion.SetCorrectAnswer(ParseAnswers(splitQuestion[8].Trim())); break; } }
public static async Task WriteExamFileAsync(string filepath, Exam exam) { using ( var sw = new StreamWriter(filepath) ) { await sw.WriteLineAsync($"{exam.Name}"); foreach ( var cat in exam.Categories ) { await sw.WriteLineAsync(cat.ToString()); } } }
static void ReadExam(string fileDump, Exam exam) { var splitExam = fileDump.Split('#'); exam.Name = splitExam[ 0 ]; foreach ( var question in splitExam.Where(question => question != exam.Name) ) { ProcessQuestions(exam, question); } }
public static async Task ReadExamFileAsync(string filePath, Exam exam) { string fileDump; using ( var reader = new StreamReader(filePath) ) { fileDump = await reader.ReadToEndAsync(); } ReadExam(fileDump, exam); }