public QuestionEntity read(OdbcDataReader reader) { var res = new QuestionEntity(); res.id = reader.GetInt32(0); res.ans = reader.GetString(2); var choicejson = reader.GetString(3); var decoder = new JavaScriptSerializer(); res.choices = decoder.Deserialize< ArrayList >(choicejson); res.imageURL = reader.GetString(4); res.statement = reader.GetString(5); res.type = getTypeString( reader.GetInt32(1) ); return res; }
public ExamEntity praseFromDoc(String filePath) { ExamEntity exam = new ExamEntity(); Document doc = new Document(filePath); QuestionEntity currentQuestion=null; foreach(Section section in doc.Sections) { foreach(Paragraph paragraph in section.Paragraphs) { var text = paragraph.Text.Trim(); if(text.StartsWith("##"))//Configration { var list = text.Substring(3, text.Length - 4).Split(':'); if(list[0] == "time") { exam.time = int.Parse(list[1]); } else if(list[0] == "TF") { exam.tNumber = int.Parse(list[1]); exam.tScore = float.Parse(list[2]); } else if (list[0] == "SC") { exam.sNumber = int.Parse(list[1]); exam.sScore = float.Parse(list[2]); } else if (list[0] == "MC") { exam.mNumber = int.Parse(list[1]); exam.mScore = float.Parse(list[2]); } } else if(text.StartsWith("$$"))//Start of a question { var list = text.Substring(3, text.Length - 4).Split(':'); string problemType = list[0]; string ans = list[2]; currentQuestion = new QuestionEntity(); currentQuestion.type = problemType; currentQuestion.ans = ans; } else if(text.Length==0) //End of a question { DocPicture pic = null; foreach (DocumentObject docObject in paragraph.ChildObjects) { if (docObject.DocumentObjectType == DocumentObjectType.Picture) { pic = docObject as DocPicture; } } if(pic != null ) // a line with picture but no text { currentQuestion.image = pic.Image; } else // end of a question { if (currentQuestion != null) { if (currentQuestion.type.Equals("TF")) { exam.tf.Add(currentQuestion); } else if (currentQuestion.type.Equals("SC")) { exam.sc.Add(currentQuestion); } else// MC { exam.mc.Add(currentQuestion); } } currentQuestion = null; } } else { if( currentQuestion.type=="TF") { foreach (DocumentObject docObject in paragraph.ChildObjects) { if (docObject.DocumentObjectType == DocumentObjectType.TextRange) { TextRange info = docObject as TextRange; currentQuestion.statement += info.Text; } else if(docObject.DocumentObjectType == DocumentObjectType.Picture) { DocPicture picture = docObject as DocPicture; currentQuestion.image = picture.Image; } } } else// SC && MC { if (text.StartsWith("A:") && text.Split(';').Length >=4) //at least 4 choices { var choiceList = text.Split(';'); currentQuestion.choices.AddRange(choiceList); } else { foreach (DocumentObject docObject in paragraph.ChildObjects) { if (docObject.DocumentObjectType == DocumentObjectType.TextRange) { var info = (docObject as TextRange).Text; currentQuestion.statement += info; } else if (docObject.DocumentObjectType == DocumentObjectType.Picture) { DocPicture picture = docObject as DocPicture; currentQuestion.image = picture.Image; } } } } } } } return exam; }