public virtual LmsQuestionDTO ParseQuestion(BBQuestionDTO dto) { var ret = new LmsQuestionDTO() { //question_text = dto.text.ClearName(), question_type = dto.type, is_single = singleQuestionTypes.Any( x => dto.type.Equals(x, StringComparison.InvariantCultureIgnoreCase)), question_name = dto.title.ClearName(), id = BlackboardHelper.GetBBId(dto.id), rows = dto.rows, answers = ParseAnswers(dto) }; ret.question_text = dto.htmlText.ClearName(); ret.htmlText = dto.htmlText; var imageLinks = dto.answersImageLinks as JToken; ret.answersImageLinks = imageLinks != null?imageLinks.ToObject <List <string> >() : null; ret.answers.ForEach( a => { a.text = a.text.ClearName(); a.question_text = a.question_text.ClearName(); }); ret.caseSensitive = ret.answers.Any(x => x.caseSensitive); return(ret); }
public virtual LmsQuestionDTO ParseQuestion(BBQuestionDTO dto) { var ret = new LmsQuestionDTO() { //question_text = dto.text.ClearName(), question_type = dto.type, is_single = singleQuestionTypes.Any( x => dto.type.Equals(x, StringComparison.InvariantCultureIgnoreCase)), question_name = dto.title.ClearName(), id = int.Parse(dto.id), rows = dto.rows, answers = ParseAnswers(dto) }; ret.question_text = dto.htmlText.ClearName(); ret.htmlText = dto.htmlText; var imageLinks = dto.answersImageLinks as JToken; ret.answersImageLinks = imageLinks?.ToObject <List <string> >(); ret.answers.ForEach( a => { a.text = a.text.ClearName(); //a.text = a.text.ClearName(); a.question_text = a.question_text.ClearName(); }); ret.caseSensitive = ret.answers.Any(x => x.caseSensitive); //var lmsQuestion = ret; //if (!string.IsNullOrEmpty(dto.questionImageBinary)) //{ // var fileDto = new LmsQuestionFileDTO // { // fileName = !string.IsNullOrEmpty(dto.questionImageLink) ? dto.questionImageLink.Split('/').Last() : string.Empty, // fileUrl = dto.questionImageLink, // base64Content = dto.questionImageBinary // }; // lmsQuestion.files.Add(0, fileDto); //} return(ret); }
public override LmsQuestionDTO ParseQuestion(BBQuestionDTO dto) { var ret = new LmsQuestionDTO() { question_text = dto.text.ClearName(), question_type = dto.type, is_single = singleQuestionTypes.Any( x => dto.type.Equals(x, StringComparison.InvariantCultureIgnoreCase)), question_name = dto.title.ClearName(), id = int.Parse(dto.id), rows = dto.rows, answers = ParseAnswers(dto) }; ret.answers.ForEach( a => { a.text = a.question_text; a.question_text = a.question_text.ClearName(); }); ret.caseSensitive = ret.answers.Any(x => x.caseSensitive); var lmsQuestion = ret; if (!string.IsNullOrEmpty(dto.questionImageBinary)) { var fileDto = new LmsQuestionFileDTO { fileName = !string.IsNullOrEmpty(dto.questionImageLink) ? dto.questionImageLink.Split('/').Last() : string.Empty, fileUrl = dto.questionImageLink, base64Content = dto.questionImageBinary }; lmsQuestion.files.Add(0, fileDto); } return(lmsQuestion); }
/// <summary> /// Parses the specified XML. /// </summary> /// <param name="xml"> /// The XML. /// </param> /// <param name="errorMessage"> /// The error message /// </param> /// <param name="error"> /// The error text /// </param> /// <returns> /// Collection of Meeting Items. /// </returns> public static LmsQuizDTO Parse(XmlNode xml, ref string errorMessage, ref string error) { if (xml == null) { return(null); } XmlNode message = xml.SelectSingleNode(MessagePath); if (message != null) { errorMessage = message.InnerText; } XmlNode debugInfo = xml.SelectSingleNode(DebugPath); if (debugInfo != null) { error = debugInfo.InnerText; } XmlNode quiz = xml.SelectSingleNode(QuizPath); if (quiz == null) { return(null); } var ret = new LmsQuizDTO(); ret.id = int.Parse(quiz.GetNodeValue("id") ?? "0"); ret.title = quiz.GetNodeValue("name"); ret.description = quiz.GetNodeValue("intro"); XmlNode courseSingle = quiz.SelectSingleNode(CoursePath); if (courseSingle != null) { int courseIdInt; if (int.TryParse(courseSingle.GetNodeValue("id"), out courseIdInt)) { ret.course = courseIdInt.ToString(); } ret.courseName = courseSingle.GetNodeValue("fullname"); } XmlNodeList questions = quiz.SelectNodes(QuestionsPath); var quizQuestions = new List <LmsQuestionDTO>(); if (questions != null) { foreach (XmlNode quest in questions) { var q = new LmsQuestionDTO(); quizQuestions.Add(q); q.id = int.Parse(quest.GetNodeValue("id") ?? "0"); q.question_name = quest.GetNodeValue("name"); q.question_text = quest.GetNodeValue("questiontext"); q.question_type = quest.GetNodeValue("qtype") ?? quest.GetNodeValue("typ"); q.presentation = quest.GetNodeValue("presentation"); q.is_mandatory = int.Parse(quest.GetNodeValue("required") ?? "0") > 0; XmlNodeList datasetsSingle = quest.SelectNodes(DataSetPath); if (datasetsSingle != null) { foreach (XmlNode ds in datasetsSingle) { //var mds = new SakaiDataset(); //mds.Id = ds.GetNodeValue("id"); //mds.Name = ds.GetNodeValue("name"); //mds.Max = ds.GetNodeValue("maximum"); //mds.Min = ds.GetNodeValue("minimum"); //q.datasets.Add(mds); //XmlNodeList items = ds.SelectNodes("KEY[@name='items']/MULTIPLE/SINGLE"); //if (items == null) //{ // continue; //} //mds.Items = new List<SakaiDataSetItem>(); //foreach (XmlNode it in items) //{ // var mit = new SakaiDataSetItem(); // mit.ItemNumber = it.GetNodeValue("itemnumber"); // string val = it.GetNodeValue("value"); // double value; // if (val != null && double.TryParse(val, out value)) // { // mit.Value = value; // } // mds.Items.Add(mit); //} } } XmlNode optionsSingle = quest.SelectSingleNode(OptionSinglePath); if (optionsSingle == null) { continue; } string singleChoice = optionsSingle.GetNodeValue("single"); int singleChoiceInt; if (int.TryParse(singleChoice, out singleChoiceInt)) { q.is_single = singleChoiceInt > 0; } XmlNodeList answers = optionsSingle.SelectNodes(AnswersPath); if (answers != null) { foreach (XmlNode answ in answers) { var a = new AnswerDTO(); q.answers.Add(a); a.id = int.Parse(answ.GetNodeValue("id") ?? "0"); a.text = answ.GetNodeValue("answer"); a.weight = (int)(double.Parse(answ.GetNodeValue("fraction") ?? "0") * 100); double tolerance; string tol = answ.GetNodeValue("tolerance"); if (tol != null && double.TryParse(tol, out tolerance)) { a.margin = tolerance; } } } XmlNodeList qzs = optionsSingle.SelectNodes(QuestionsPath); if (qzs != null && qzs.Count == 0) { qzs = optionsSingle.SelectNodes(SubquestionsPath); } if (qzs != null) { foreach (XmlNode quizNode in qzs) { var a = new AnswerDTO(); q.answers.Add(a); a.id = int.Parse(quizNode.GetNodeValue("id") ?? "0"); a.question_type = quizNode.GetNodeValue("questiontype"); a.question_text = quizNode.GetNodeValue("questiontext"); a.text = quizNode.GetNodeValue("answertext"); } } } } ret.question_list = quizQuestions.ToArray(); ProcessQuiz(ret); return(ret); }