public static List <string> CheckFileDefault(string csvFile) { List <string> errors = new List <string>(); if (!File.Exists(csvFile)) { return(errors); } string[] lines = File.ReadAllLines(csvFile); for (int i = 0; i < lines.Length; i++) { List <string> items = JwCSV.GetLineItems(lines[i]); if (items.Count < 20) { errors.Add("Not enought items in line " + i.ToString()); continue; } // skip 1st line if (items[0] == "code") { continue; } // check code (0) is not blank if (items[0] == String.Empty) { errors.Add("line " + i.ToString() + ": code is blank"); } // check correct_choice (2) starts with "choice_" if (!items[2].StartsWith("choice_")) { errors.Add("line " + i.ToString() + ": cell 3 should start with 'choice_'"); } // check 13 = Open if (items[13] != "Open") { errors.Add("line " + i.ToString() + ": cell 14 should be 'Open'"); } // check 14 = L1 if (items[14] != "L1") { errors.Add("line " + i.ToString() + ": cell 15 should be 'L1'"); } } return(errors); }
public static List <string> CheckFileMResponse(string csvFile) { List <string> errors = new List <string>(); if (!File.Exists(csvFile)) { return(errors); } string[] lines = File.ReadAllLines(csvFile); for (int i = 0; i < lines.Length; i++) { List <string> items = JwCSV.GetLineItems(lines[i]); if (items.Count < 27) { errors.Add("Not enought items in line " + i.ToString()); continue; } // skip 1st line if (items[0] == "code") { continue; } // check code (0) is not blank if (items[0] == String.Empty) { errors.Add("line " + i.ToString() + ": code is blank"); } // check 22 = Open if (items[22] != "Open") { errors.Add("line " + i.ToString() + ": cell 23 should be 'Open'"); } // check 23 = L1 if (items[23] != "L1") { errors.Add("line " + i.ToString() + ": cell 24 should be 'L1'"); } } return(errors); }
public static List <string> CreateDefaultCSV(string filename, List <Question> questions) { int questionsSkipped = 0; List <string> result = new List <string>(); result.Add("Processing default question types...."); // build CSV text string csvText = "code,body,correct_choice,"; csvText += "choice_1,choice_2,choice_3,choice_4,choice_5,choice_6,choice_7,choice_8,choice_9,choice_10,"; csvText += "status,difficulty,question_category_code,keyword,can_fail_exam,correct_feedback,incorrect_feedback"; //csvText += ",generalfeedback,partiallycorrectfeedback"; for (int i = 1; i <= 10; i++) { csvText += ",choice_" + i.ToString() + "_feedback"; } for (int i = 0; i < questions.Count; i++) { Question q = questions[i]; List <string> errorsFound = QuestionLib.CheckQuestion(q); if (errorsFound.Count == 0) { string csv = GetQuestionAsCSV(q); if (csv.Length > 0) { csvText += Environment.NewLine + csv; } } else { questionsSkipped++; } } result.Add("\tCSV text created; questions skipped: " + questionsSkipped.ToString()); // write csv file JwCSV.WriteToFile(filename, csvText); result.Add("\tCSV file created."); // create image folder List <Question> questionsWithImageData = QuestionLib.GetQuestionsWithImageData(questions); string imageFolder = CFG.outputDir + Path.GetFileNameWithoutExtension(filename) + "-img"; if (questionsWithImageData.Count > 0) { System.IO.Directory.CreateDirectory(imageFolder); result.Add("\timage dir created."); // create images int imageCount = 0; for (int i = 0; i < questionsWithImageData.Count; i++) { Question q = questionsWithImageData[i]; for (int j = 0; j < q.images.Count; j++) { if (q.images[j].name != String.Empty && q.images[j].imageData != String.Empty) { string imageFile = Path.Combine(imageFolder, q.images[j].name); File.WriteAllBytes(imageFile, Convert.FromBase64String(q.images[j].imageData)); imageCount++; } } } result.Add("\t" + imageCount.ToString() + " images created."); } // return result return(result); }