/// <summary> /// Preview the xml content and validate it /// </summary> /// <returns>Dataset containing the results of the preview stored procedure.</returns> public DataSet Preview() { try { //1. Validate the XML document this.Validate(); //2. If the document is valid upload it to the database otherwise do nothing. if (this.p_objValidationResult.IsValid) { DataSet dsLoadResult; Toolbook objToolbook = new Toolbook(); //3. Loads the UserXMLData. return(dsLoadResult = objToolbook.UploadContentObjectXMLPreview(this.GetXMLData(this.XMLFile), this.ModuleID, this.UserID)); } else //4. Schema Validation failed. { //5. Create a new DataSet DataSet dsLoadResult = new DataSet("LoadResult"); //6. Create a datatable with the error result from the validation struct. DataTable dtbLoadResult = new DataTable("Result"); DataColumn dtcName = new DataColumn("Error", System.Type.GetType("System.String")); dtbLoadResult.Columns.Add(dtcName); DataRow drError; drError = dtbLoadResult.NewRow(); drError["Error"] = "Invalid XML file"; dtbLoadResult.Rows.Add(drError); //7. Log the error to the error log //new ErrorLog(new Exception(this.ValidationResult.Error), ErrorLevel.High, "ImportToolbook", "Preview", "Validate XML"); new ErrorLog(new ApplicationException(ValidationResult.Error.ToString())); //8. Add the DataTable to the DataSet. dsLoadResult.Tables.Add(dtbLoadResult); //9. Return the DataSet. return(dsLoadResult); } } catch (Exception ex) { throw ex; } }
} // Quiz_OnLoad /// <summary> /// This event is called when a quiz is completed. /// It updates the QuizSession table in Salt with information /// provided by the Toolbook application. This information is supplied /// via form elements that are posted to this page. /// </summary> /// <param name="sessionID">This is the session id that maps to the lesson that is currently loading</param> /// <param name="postData">This is the collection of http post data variables</param> private void Quiz_OnScore(string sessionID, NameValueCollection postData) { string strDuration; // This isnt currently implemented in toolbook string strResponses; // The responses given by the user string strScore; // The score of the user int intScore; // The score of the user answering the quiz int intDuration; // The uration the user spent doing the quiz // Verify the necessary post parameters have been supplied strResponses = postData.Get("Responses"); if (strResponses.Length == 0) { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Missing required parameter: Responses" // paramater 2 - Error Message ); return; } // Get the duration strDuration = postData.Get("Duration"); if (strDuration.Length == 0) { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Missing required parameter: Duration" // paramater 2 - Error Message ); return; } // Get the score strScore = postData.Get("Score"); if (strDuration.Length == 0) { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Missing required parameter: Duration" // paramater 2 - Error Message ); return; } // Check that Duration and Score contain numeric values if (IsInteger(strDuration) && IsInteger(strScore)) { intDuration = Convert.ToInt32(strDuration); intScore = Convert.ToInt32(strScore); } else { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Invalid parameter type: Duration or Score" // paramater 2 - Error Message ); return; } try { // All Answers To All Questions string[] aAnswersAllQuestions; // Answers to one particular question string[] aAnswersOneQuestions; // QuizQuestionID string strQuestionToolbookPageID; int intFirstMarker; int intSecondMarker; BusinessServices.Toolbook objToolboook = new Toolbook(); // Remove one of the ['s strResponses = strResponses.Replace("[", ""); // Use the other ] as a delimiter to split the string to an array. strResponses = strResponses.Substring(0, strResponses.Length - 1); aAnswersAllQuestions = strResponses.Split(']'); foreach (string strAnswer in aAnswersAllQuestions) { // Find first opening square bracket intFirstMarker = strAnswer.IndexOf("{"); // Find the matching closing bracket. intSecondMarker = strAnswer.IndexOf("}"); // This turns the string "Q1{1,2,3}" into an array containing '1' '2' and '3' aAnswersOneQuestions = strAnswer.Substring(intFirstMarker + 1, intSecondMarker - intFirstMarker - 1).Split(','); // Get the Question ID from the start of the string, ignore the Q at the start. strQuestionToolbookPageID = strAnswer.Substring(0, intFirstMarker); objToolboook.CreateQuizQuestionAudit(sessionID, strQuestionToolbookPageID); // Iterate through each Answer for this question and add it to the salt database. foreach (string strQuizAnswer in aAnswersOneQuestions) { // Only add the answer if there is a value provided if (strQuizAnswer.Length > 0) { objToolboook.CreateQuizAnswerAudit(sessionID, strQuestionToolbookPageID, Convert.ToInt32(strQuizAnswer)); } } } // Record that the Quiz has finished try { DataTable endQuizInfo; int intUserID; int intQuizID; int intPassMark; int intUnitID; int intModuleID; int intQuizFrequency; int intOldCourseStatus; int intNewCourseStatus; int intNewQuizStatus; int intCourseID; DateTime dtmQuizCompletionDate; //objToolboook.EndQuizSession(sessionID, intDuration, intScore); endQuizInfo = objToolboook.BeforeQuizEnd(sessionID, intDuration, intScore); DataRow tmpRow = endQuizInfo.Rows[0]; intUserID = Int32.Parse(tmpRow["UserID"].ToString()); intQuizID = Int32.Parse(tmpRow["QuizID"].ToString()); intPassMark = Int32.Parse(tmpRow["PassMark"].ToString()); intUnitID = Int32.Parse(tmpRow["UnitID"].ToString()); intModuleID = Int32.Parse(tmpRow["ModuleID"].ToString()); intQuizFrequency = Int32.Parse(tmpRow["QuizFrequency"].ToString()); intOldCourseStatus = Int32.Parse(tmpRow["OldCourseStatus"].ToString()); intNewCourseStatus = Int32.Parse(tmpRow["NewCourseStatus"].ToString()); intNewQuizStatus = Int32.Parse(tmpRow["NewQuizStatus"].ToString()); intCourseID = Int32.Parse(tmpRow["CourseID"].ToString()); dtmQuizCompletionDate = tmpRow["QuizCompletionDate"] == null?DateTime.Parse("1/1/1900") : (DateTime)tmpRow["QuizCompletionDate"]; objToolboook.EndQuizSession_UpdateTables(sessionID, intDuration, intScore, intUserID, intQuizID, intPassMark, intUnitID, intModuleID, intCourseID, intOldCourseStatus, intNewQuizStatus, intNewCourseStatus, intQuizFrequency, dtmQuizCompletionDate); } catch (Exception ex) { ErrorHandler.ErrorLog Error = new ErrorHandler.ErrorLog(ex, ErrorLevel.Medium, "ToolBookListener.aspx.cs", "Quiz_OnScore", "Failed in objToolboook.EndQuizSession"); throw (ex); } // Everything has been saved to Salt successfully. // Send OK Return code to Toolbook to indicate completion OutputToToolBook( cm_strReturnCodeOK // paramater 1 - ReturnCode + cm_strDelimiter + "" // paramater 2 - Error Message ); } catch (Exception ex) { ErrorHandler.ErrorLog objError = new ErrorHandler.ErrorLog(ex, ErrorLevel.Medium, "ToolBookListener.aspx.cs", "Quiz_OnScore", ""); } } // Quiz_OnScore
public string writeDMEs(int StudentID, int ModuleID, string strSessID1, DataSet xmlDS, string sessiondata, int ProfileId) { try { Boolean isLesson = false; Boolean completed = false; int score = 0; int interactions = 0; string strResult = ""; int currentpage = 0; int Totalpage = 0; Hashtable ht = new Hashtable(); foreach (DataRow r in xmlDS.Tables["dme"].Rows) { // get the salt variables here... if (r["name"].ToString().ToLower().Contains("salt.variables.var")) { ht.Add(r["name"].ToString().ToLower(), r["value"].ToString()); } if (r["name"].ToString().ToLower().Equals("salt.lessonorquiz")) { try { isLesson = (r["value"].ToString().ToLower() == "lesson"); } catch { isLesson = true; } } if (r["name"].ToString().Equals("cmi.core.lesson_status")) { if (r["value"].ToString().Equals("completed") || r["value"].ToString().Equals("passed")) { completed = true; if (completed) { //break; } } } ////if (r["name"].ToString().Equals("cmi.core.lesson_status")) ////{ //// completed = r["value"].ToString().Equals("passed"); //// if (completed) //// { //// //break; //// } ////}Adaptive //if (r["name"].ToString().Equals("salt.variables.VarPageInChapter")) //{ // currentpage = int.Parse(r["value"].ToString()); //} //if (r["name"].ToString().Equals("cmi.suspend_data")) //{ // string phrase = r["value"].ToString(); // string[] strTallyVisited = phrase.Split(';'); // currentpage = Convert.ToInt32(strTallyVisited[0].Split('=')[1].ToString().Trim()); //} //if (r["name"].ToString().Equals("salt.variables.VarPagesInChapter")) //{ // Totalpage = int.Parse(r["value"].ToString()); // //if (Totalpage - 1 == currentpage && Totalpage != 0) // //{ // // completed = true; // // if (completed) // // { // // //break; // // } // //} //} //if (r["name"].ToString().Equals("salt.variables.VarRunningPageCount")) //{ // string phrase = r["value"].ToString(); // string[] strTallyVisited = phrase.Split(' '); // currentpage = Convert.ToInt32(strTallyVisited[1].ToString().Trim()); // Totalpage = Convert.ToInt32(strTallyVisited[3].ToString().Trim()); // if (Totalpage - 1 == currentpage && Totalpage != 0) // { // completed = true; // if (completed) // { // //break; // } // } //} //if (Totalpage != 0 || currentpage != 0) //{ // if (Totalpage == currentpage) // { // completed = true; // if (completed) // { // //break; // } // } //} if (r["name"].ToString().Equals("cmi.core.score.raw")) { try { score = int.Parse(r["value"].ToString()); } catch { score = 0; } } if (r["name"].ToString().Equals("cmi.core.lesson_score")) { try { score = int.Parse(r["value"].ToString()); } catch { score = 0; } } if (r["name"].ToString().Equals("cmi.interactions._count")) { try { interactions = int.Parse(r["value"].ToString()); r["value"] = "0"; } catch { // do nothing } } if (r["value"].ToString() != "") { strResult = WriteDMEvalue(StudentID, ModuleID, r["name"].ToString(), r["value"].ToString()); } } if (!isLesson) // train tblQuizQuestion and tblQuizAnswer { int intAskedQuestion = 1; int intWeighting = 1; String strLatency = ""; String strTime = ""; String strText = ""; String strType = ""; String strID = ""; Boolean isCorrect = false; String strCorrectResponse = ""; String strStudentResponse = ""; int intNextAskedQuestion = 0; String[] strPosAskedQuestion; BusinessServices.Toolbook objToolbook = new Toolbook(); DataTable endQuizInfo = objToolbook.BeforeQuizEnd2(StudentID, ModuleID, 46664, score); DataRow tmpRow = endQuizInfo.Rows[0]; String SessionID = tmpRow["SessionID"].ToString(); foreach (DataRow r in xmlDS.Tables["dme"].Rows) { if (r["name"].ToString().Length > 16) { if (r["name"].ToString().Substring(0, 16).Equals("cmi.interactions")) { strPosAskedQuestion = r["name"].ToString().Split('.'); try { intNextAskedQuestion = int.Parse(strPosAskedQuestion[2]); } catch { } if (intNextAskedQuestion != intAskedQuestion && strText != "") { saveQuestion(StudentID, intAskedQuestion, intWeighting, strLatency, strTime, strText, strID, isCorrect, strCorrectResponse, strStudentResponse, strType, ModuleID, SessionID); intAskedQuestion = intNextAskedQuestion; intWeighting = 1; strLatency = ""; strTime = ""; strText = ""; strID = ""; isCorrect = false; strCorrectResponse = ""; strStudentResponse = ""; strType = ""; } try { if (strPosAskedQuestion[3].Equals("id")) { try { strID = r["value"].ToString(); } catch { } } ; if (strPosAskedQuestion[3].Equals("latency")) { strLatency = r["value"].ToString(); } if (strPosAskedQuestion[3].Equals("question")) { strText = r["value"].ToString().Replace("\\r", ""); foreach (DictionaryEntry entry in ht) { if (entry.Value.ToString().Equals(strText)) { String[] arr = entry.Key.ToString().Split('_'); strStudentResponse = ht["salt.variables.varquestion_" + arr[1]].ToString(); strCorrectResponse = ht["salt.variables.varvarcorrectanswertext_" + arr[1]].ToString(); break; } } } if (strPosAskedQuestion[3].Equals("result")) { try { isCorrect = r["value"].ToString().ToLower().Equals("correct"); } catch { } } ; if (strPosAskedQuestion[3].Equals("time")) { strTime = r["value"].ToString(); } if (strPosAskedQuestion[3].Equals("type")) { strType = r["value"].ToString(); } if (strPosAskedQuestion[3].Equals("weighting")) { try { intWeighting = int.Parse(r["value"].ToString()); } catch { } } ; } catch { }; } } } if (!intAskedQuestion.Equals(1)) { saveQuestion(StudentID, intAskedQuestion, intWeighting, strLatency, strTime, strText, strID, isCorrect, strCorrectResponse, strStudentResponse, strType, ModuleID, SessionID); intAskedQuestion = 1; } if (!isLesson && interactions > 0) { int intUserID; int intQuizID; int intPassMark; int intUnitID; int intModuleID; int intQuizFrequency; int intOldCourseStatus; int intNewCourseStatus; int intNewQuizStatus; int intCourseID; DateTime dtmQuizCompletionDate; intUserID = Int32.Parse(tmpRow["UserID"].ToString()); try { intQuizID = Int32.Parse(tmpRow["QuizID"].ToString()); } catch { intQuizID = 0; } intPassMark = Int32.Parse(tmpRow["PassMark"].ToString()); intUnitID = Int32.Parse(tmpRow["UnitID"].ToString()); intModuleID = Int32.Parse(tmpRow["ModuleID"].ToString()); intQuizFrequency = tmpRow["QuizFrequency"] == null?Int32.Parse(tmpRow["QuizFrequency"].ToString()) : 0; intOldCourseStatus = Int32.Parse(tmpRow["OldCourseStatus"].ToString()); intNewCourseStatus = Int32.Parse(tmpRow["NewCourseStatus"].ToString()); intNewQuizStatus = Int32.Parse(tmpRow["NewQuizStatus"].ToString()); intCourseID = Int32.Parse(tmpRow["CourseID"].ToString()); dtmQuizCompletionDate = (tmpRow["QuizCompletionDate"] == System.DBNull.Value ? DateTime.Parse("1/1/1900") : (DateTime)tmpRow["QuizCompletionDate"]); endQuizInfo = objToolbook.EndQuizSession_UpdateTables(SessionID, 46664, score, intUserID, intQuizID, intPassMark, intUnitID, ModuleID, intCourseID, intOldCourseStatus, intNewQuizStatus, intNewCourseStatus, intQuizFrequency, dtmQuizCompletionDate); // read cert flag tmpRow = endQuizInfo.Rows[0]; Boolean blnSendCert = (bool)tmpRow["sendcert"]; if (blnSendCert) { DefaultQuiz dq = new DefaultQuiz(); dq.certemail(intUserID, intCourseID, 0); } } //code for adaptive else { if (endQuizInfo.Rows[0]["toolbooklocation"].ToString().Trim().Contains("launchpage.html")) { if (!isLesson && sessiondata == SessionID && score == 100) { int intUserIDAdapt; int intQuizIDAdapt; int intPassMarkAdapt; int intUnitIDAdapt; int intModuleIDAdapt; int intQuizFrequencyAdapt; int intOldCourseStatusAdapt; int intNewCourseStatusAdapt; int intNewQuizStatusAdapt; int intCourseIDAdapt; DateTime dtmQuizCompletionDateAdapt; intUserIDAdapt = Int32.Parse(tmpRow["UserID"].ToString()); try { intQuizIDAdapt = Int32.Parse(tmpRow["QuizID"].ToString()); } catch { intQuizIDAdapt = 0; } intPassMarkAdapt = Int32.Parse(tmpRow["PassMark"].ToString()); intUnitIDAdapt = Int32.Parse(tmpRow["UnitID"].ToString()); intModuleIDAdapt = Int32.Parse(tmpRow["ModuleID"].ToString()); intQuizFrequencyAdapt = tmpRow["adaptivequizfreq"] == null ? 0 : Int32.Parse(tmpRow["adaptivequizfreq"].ToString()); intOldCourseStatusAdapt = Int32.Parse(tmpRow["OldCourseStatus"].ToString()); intNewCourseStatusAdapt = Int32.Parse(tmpRow["NewCourseStatus"].ToString()); intNewQuizStatusAdapt = Int32.Parse(tmpRow["NewQuizStatus"].ToString()); intCourseIDAdapt = Int32.Parse(tmpRow["CourseID"].ToString()); dtmQuizCompletionDateAdapt = (tmpRow["QuizCompletionDate"] == System.DBNull.Value ? DateTime.Parse("1/1/1900") : (DateTime)tmpRow["QuizCompletionDate"]); if (score == 100) { endQuizInfo = objToolbook.EndQuizSession_UpdateTables(SessionID, 46664, score, intUserIDAdapt, intQuizIDAdapt, intPassMarkAdapt, intUnitIDAdapt, ModuleID, intCourseIDAdapt, intOldCourseStatusAdapt, intNewQuizStatusAdapt, intNewCourseStatusAdapt, intQuizFrequencyAdapt, dtmQuizCompletionDateAdapt); if (ProfileId > -1) { BusinessServices.Profile objProfile = new BusinessServices.Profile(); bool ApplyToQuiz = objProfile.QuizRequiredForPoints(ProfileId); if (ApplyToQuiz) // quiz only { if (!(objProfile.CheckQuizPointsAlreadyGivenForPeriod(ProfileId, intUserIDAdapt, ModuleID, 1))) { objProfile.ApplyCPDPoints(ProfileId, intUserIDAdapt, ModuleID, 1); } } } } // read cert flag tmpRow = endQuizInfo.Rows[0]; Boolean blnSendCert = (bool)tmpRow["sendcert"]; if (blnSendCert) { DefaultQuiz dq = new DefaultQuiz(); dq.certemail(intUserIDAdapt, intCourseIDAdapt, 0); } } else if (!isLesson && sessiondata == SessionID && (score > 0 && score < 100)) { int intUserIDAdapt; int intQuizIDAdapt; int intPassMarkAdapt; int intUnitIDAdapt; int intModuleIDAdapt; int intQuizFrequencyAdapt; int intOldCourseStatusAdapt; int intNewCourseStatusAdapt; int intNewQuizStatusAdapt; int intCourseIDAdapt; DateTime dtmQuizCompletionDateAdapt; intUserIDAdapt = Int32.Parse(tmpRow["UserID"].ToString()); try { intQuizIDAdapt = Int32.Parse(tmpRow["QuizID"].ToString()); } catch { intQuizIDAdapt = 0; } intPassMarkAdapt = Int32.Parse(tmpRow["PassMark"].ToString()); intUnitIDAdapt = Int32.Parse(tmpRow["UnitID"].ToString()); intModuleIDAdapt = Int32.Parse(tmpRow["ModuleID"].ToString()); intQuizFrequencyAdapt = tmpRow["adaptivequizfreq"] == null ? 0 : Int32.Parse(tmpRow["adaptivequizfreq"].ToString()); intOldCourseStatusAdapt = Int32.Parse(tmpRow["OldCourseStatus"].ToString()); intNewCourseStatusAdapt = Int32.Parse(tmpRow["NewCourseStatus"].ToString()); intNewQuizStatusAdapt = Int32.Parse(tmpRow["NewQuizStatus"].ToString()); intCourseIDAdapt = Int32.Parse(tmpRow["CourseID"].ToString()); dtmQuizCompletionDateAdapt = (tmpRow["QuizCompletionDate"] == System.DBNull.Value ? DateTime.Parse("1/1/1900") : (DateTime)tmpRow["QuizCompletionDate"]); if (score == 100) { endQuizInfo = objToolbook.EndQuizSession_UpdateTables(SessionID, 46664, score, intUserIDAdapt, intQuizIDAdapt, intPassMarkAdapt, intUnitIDAdapt, ModuleID, intCourseIDAdapt, intOldCourseStatusAdapt, intNewQuizStatusAdapt, intNewCourseStatusAdapt, intQuizFrequencyAdapt, dtmQuizCompletionDateAdapt); if (ProfileId > -1) { BusinessServices.Profile objProfile = new BusinessServices.Profile(); bool ApplyToQuiz = objProfile.QuizRequiredForPoints(ProfileId); if (ApplyToQuiz) // quiz only { if (!(objProfile.CheckQuizPointsAlreadyGivenForPeriod(ProfileId, intUserIDAdapt, ModuleID, 1))) { objProfile.ApplyCPDPoints(ProfileId, intUserIDAdapt, ModuleID, 1); } } } } } } } //end code delDME(StudentID, ModuleID); } if (completed && isLesson) { delDME(StudentID, ModuleID); Module.InsertLessonStatus(StudentID, ModuleID, LessonStatus.Completed); } return(""); } catch (Exception exc) { // do some thign here Debug.WriteLine(exc.StackTrace); return(""); } }