/// <summary> /// Create context when the lesson starts /// </summary> private void CreateContext() { //1. Get Page Context LessonPageContext objContext = new LessonPageContext(); objContext.Path = Request.Url.AbsolutePath.Replace("/default.aspx", ""); objContext.StartTime = DateTime.Now; objContext.PageIndex = 0; objContext.Initialize(); PageContext.Current = objContext; //2. Get the bookmark, and change the current page index if bookmark exists if (!PageContext.Current.IsPreviewMode) { BusinessServices.Toolbook objToolbook = new BusinessServices.Toolbook(); string strBookmarkPageID = objToolbook.GetBookmark(objContext.SessionID); if (strBookmarkPageID != null) { try { objContext.PageIndex = objContext.FindPageIndex(strBookmarkPageID); } catch (ApplicationException) { // if a bookmark could not be found - ignore it. } } } }
/// <summary> /// Page Load event /// </summary> /// <remarks> /// This event fires when a user goes to a page. It is used to track a user’s progress through a lesson and determine when they have completed their training requirement. /// The event will call the Toolbook.RecordPageVisited method. /// </remarks> private void Page_Load() { if (!PageContext.Current.IsPreviewMode) { BusinessServices.Toolbook objToolbook = new BusinessServices.Toolbook(); objToolbook.RecordPageVisited(PageContext.Current.SessionID, PageContext.Current.PageID); } }
/// <summary> /// Quiz load event /// </summary> private void Quiz_Load() { if (!PageContext.Current.IsPreviewMode) { BusinessServices.Toolbook objToolbook = new BusinessServices.Toolbook(); if (!objToolbook.StartQuiz(PageContext.Current.SessionID)) { Response.Write(ResourceManager.GetString("QuizLesson_Error")); Response.End(); //throw new Exception("Quiz has already been started"); } } }
} //Lesson_OnLoad /// <summary> /// LessonPage_OnLoad /// </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 LessonPage_OnLoad(SqlString sessionID, NameValueCollection postData) { string strToolbookPageID; // Verify the necessary post parameters have been supplied strToolbookPageID = postData.Get("TBPageID"); if (strToolbookPageID.Length == 0) { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Missing required parameter: TBPageID" // paramater 2 - Error Message ); return; } try { BusinessServices.Toolbook objToolBook = new BusinessServices.Toolbook(); if (objToolBook.RecordPageVisited(sessionID, strToolbookPageID)) { // Normal condition -> tell TB "c_strReturnCodeOK", i.e. it can continue OutputToToolBook( cm_strReturnCodeOK // paramater 1 - ReturnCode + cm_strDelimiter + "" // paramater 2 - Error Message ); return; } else { // Error condition OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 15. " + ResourceManager.GetString("Error2") //" // paramater 2 - Error Message ); return; } } catch (Exception ex) { // log the error ErrorHandler.ErrorLog Error = new ErrorHandler.ErrorLog(ex); OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 16. Unknown Error" // paramater 2 - Error Message ); return; } } // LessonPage_OnLoad
/// <summary> /// Lesson End event /// </summary> /// <remarks> /// A user can exit a lesson at any point by clicking on the Exit button. Alternatively, when they reach the end of a lesson they will be presented with a screen indicating they have completed the lesson for the current module and provide a link to exit the lesson. Any of these 2 actions will trigger the Lesson_OnExit event. /// The event will call the Toolbook.EndLessonSession method by passing the following parameters: /// .Bookmark: The bookmark is the current page ID. /// If they selected the Exit button on any page other than the last page the book mark parameter will be sent. /// If the user selects to exit on the last page by pressing the exit button in the toolbar a bookmark parameter should not be sent to the SALT LMS as part of the event. /// .Duration: The system needs to keep track of the duration of a lesson. The duration, in seconds as an integer needs to be supplied as part of the EndLessonSession method of objToolBook. /// </remarks> private void Lesson_End() { if (!PageContext.Current.IsPreviewMode) { try { string bookmark; if (!PageContext.Current.IsLastPage) { bookmark = PageContext.Current.PageID; } else { bookmark = null; } TimeSpan objTimeSpan = DateTime.Now.Subtract(PageContext.Current.StartTime); BusinessServices.Toolbook objToolbook = new BusinessServices.Toolbook(); objToolbook.EndLessonSession(PageContext.Current.SessionID, objTimeSpan.Seconds, bookmark); //obtain profileIDs for all profiles that have access to module and apply points BusinessServices.Profile objProfile = new BusinessServices.Profile(); int ModuleID = Int32.Parse(Request.QueryString["ModuleID"].ToString()); int UserID = Int32.Parse(Request.QueryString["UserID"].ToString()); int intCourseID = Int32.Parse(Request.QueryString["CourseID"].ToString()); int intProfileID = Int32.Parse(Request.QueryString["ProfileID"].ToString()); DataTable dtProfiles = objProfile.ProfilesWithModuleAccess(UserID, ModuleID); foreach (DataRow dr in dtProfiles.Rows) { int ProfileID = int.Parse(dr["ProfileID"].ToString()); ApplyProfilePoints(ProfileID); } Response.Redirect("/MyTraining.aspx"); } catch (Exception ex) { if (ex.Message.ToLower().StartsWith("violation of primary key")) { Response.Write(ResourceManager.GetString("QuizLesson_Error")); Response.End(); } else { throw ex; } } } }
} //Lesson_OnExit /// <summary> /// This method is called when a Quiz is Loaded. /// It looks up various pieces of data from the Salt tables /// before returning them to the Toolbook application /// </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_OnLoad(string sessionID, NameValueCollection postData) { string strToolbookID; // the toolbook ID as per the toolbook application string strUserName; // the username int intUserID; // User ID of the current User int intModuleID; // Module ID that this quiz belongs to int intQuizID; // QuizID that the user is currently sitting int intPassMark; // The passmark for the quiz that the user is currently sitting int intUnitID; // The unit ID of the current user bool blnError; // Boolean flag indicating the presence of an error // Verify the necessary post parameters have been supplied strToolbookID = postData.Get("ToolbookID"); if (strToolbookID.Length == 0) { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Missing required parameter: ToolbookID" // paramater 2 - Error Message ); return; } // toolbook object used to return necessary information below.. BusinessServices.Toolbook objToolBook = new BusinessServices.Toolbook(); // Get UserName and ID strUserName = objToolBook.GetUser(sessionID); intUserID = objToolBook.GetUserIDBySessionID(sessionID); // Get Module ID and UserID to determine Access intModuleID = objToolBook.GetModuleIDBySessionID(sessionID); intUnitID = objToolBook.GetUnitIDByUserID(intUserID); // Get Quiz ID, Number of Quiz Questions and PassMark intQuizID = objToolBook.GetQuizIDBySessionID(sessionID); intPassMark = objToolBook.GetQuizPassMark(intUnitID, intModuleID); // Assume no errors to start with. blnError = false; // If no username if (strUserName.Length == 0) { OutputToToolBook( cm_strReturnCodeCriticalError + cm_strDelimiter + "TBListener Error 5. The User Name could not be found" + cm_strDelimiter + m_strRootURL + cm_strErrorLocation + "?errnum=5" ); blnError = true; } // If no Quiz ID if (intQuizID <= 0) { OutputToToolBook( cm_strReturnCodeCriticalError + cm_strDelimiter + "TBListener Error 6. The Quiz ID could not be found" + cm_strDelimiter + m_strRootURL + cm_strErrorLocation + "?errnum=6" ); blnError = true; } // If no module ID if (intModuleID <= 0) { OutputToToolBook( cm_strReturnCodeCriticalError + cm_strDelimiter + "TBListener Error 8. The Module ID Could not be found" + cm_strDelimiter + m_strRootURL + cm_strErrorLocation + "?errnum=8" ); blnError = true; } // If no Unit ID if (intUnitID <= 0) { OutputToToolBook( cm_strReturnCodeCriticalError + cm_strDelimiter + "TBListener Error 9. The Unit ID Could not be found" + cm_strDelimiter + m_strRootURL + cm_strErrorLocation + "?errnum=9" ); blnError = true; } // If no error has occurred if (!blnError) { // Start the quiz if (objToolBook.StartQuiz(sessionID)) { // Let Toolbook know that we have successfully started the quiz OutputToToolBook( cm_strReturnCodeOK // paramater 1 - ReturnCode + cm_strDelimiter + intPassMark // paramater 3 - PassMark + cm_strDelimiter + strUserName // paramater 4 - User Name + cm_strDelimiter + m_strRootURL + cm_strHomeLocation + "?SessionID=" + sessionID // paramater 5 - Exit Home URL + cm_strDelimiter + m_strRootURL + cm_strReportLocation + "?QuizSessionID=" + sessionID // paramater 6 - Exit Report URL + cm_strDelimiter + m_strRootURL + cm_strErrorLocation // paramater 7 - Error URL + cm_strDelimiter + "" // paramater 8 - Error Message ); return; } else { OutputToToolBook( cm_strReturnCodeCriticalError + cm_strDelimiter + ResourceManager.GetString("Error1") //"Please make sure you do not use your browser's backwards and forwards buttons. Navigate lessons and quizzes using the buttons in the bottom right hand corner." + cm_strDelimiter + m_strRootURL + cm_strHomeLocation + "?errnum=2" //cm_strErrorLocation ); return; } } } // Quiz_OnLoad
} // LessonPage_OnLoad /// <summary> /// Lesson_OnExit /// </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 Lesson_OnExit(SqlString sessionID, NameValueCollection postData) { int iDuration; string strDuration, strBookmark; // Verify the necessary post parameters have been supplied 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; } // Check that Duration contains a numeric value if (IsInteger(strDuration)) { iDuration = Convert.ToInt32(strDuration); } else { OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 1. Invalid parameter type: Duration" // paramater 2 - Error Message ); return; } // Bookmark is optionial strBookmark = postData.Get("Bookmark"); try { BusinessServices.Toolbook objToolBook = new BusinessServices.Toolbook(); if (objToolBook.EndLessonSession(sessionID, iDuration, strBookmark)) { // Normal condition -> tell TB "cm_strReturnCodeOK", i.e. it can continue OutputToToolBook( cm_strReturnCodeOK // paramater 1 - ReturnCode + cm_strDelimiter + "" // paramater 2 - Error Message ); return; } else { // log the error Exception Ex = new Exception("TBListener Error 17. The lesson_OnExit event for session '" + (string)sessionID + "' has failed. One reason for this may be that the lesson has already ended and toolbook has firing the event twice. Except for this."); ErrorHandler.ErrorLog Error = new ErrorHandler.ErrorLog(Ex, ErrorLevel.Medium, "ToolBookListener.aspx.cs", "lesson_OnExit", "TBListener Error 17. The Stored proc prcLessonSession_EndLesson returned false - indicating that it could not or has already finished this lesson"); // error condition -> TB is closing any way so no need to send a critical error, just advise user that there is a problem OutputToToolBook( cm_strReturnCodeNonCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 17. " + ResourceManager.GetString("Error3") //There was a problem recording the finishing of your lesson, details may not have been saved :-(" // paramater 2 - Error Message ); return; } } catch (Exception ex) { // log the error ErrorHandler.ErrorLog Error = new ErrorHandler.ErrorLog(ex); OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListener Error 18. Unknown Error" // paramater 2 - Error Message ); return; } } //Lesson_OnExit
/// <summary> /// Lesson_OnLoad /// </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 Lesson_OnLoad(SqlString sessionID, NameValueCollection postData) { try { string strPagesVisited = ""; // List of pages already visited within this lesson string strBookmark = ""; // Bookmarked page, if any string strUsersName = ""; // User's full name DataTable dtbPagesVisitedResults; BusinessServices.Toolbook objToolBook = new BusinessServices.Toolbook(); // // TODO: any other validation including - dateExported, toolbookID // // Validate that this lesson has not been started before (based on the guid) // it should have no date completed if (!objToolBook.StartLesson(sessionID)) { //TODO: check this redirect : Response.Redirect(c_strHomeUrl); OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + ResourceManager.GetString("Error1") //"Please make sure you do not use your browser's backwards and forwards buttons. Navigate lessons and quizzes using the buttons in the bottom right hand corner." // paramater 2 - Error Message + cm_strDelimiter + m_strRootURL + cm_strHomeLocation + "?SessionID=" + (string)sessionID // paramater 3 - ExitURL ); return; } // Get pages visited dtbPagesVisitedResults = objToolBook.GetPagesVisited(sessionID); foreach (DataRow objPageVisited in dtbPagesVisitedResults.Rows) { if (strPagesVisited.Length > 0) { strPagesVisited += ","; } strPagesVisited += objPageVisited["ToolBookPageID"].ToString(); } // Get any Bookmark strBookmark = objToolBook.GetBookmark(sessionID); // Get user's full name strUsersName = objToolBook.GetUser(sessionID); OutputToToolBook( cm_strReturnCodeOK // paramater 1 - ReturnCode + cm_strDelimiter + strPagesVisited // paramater 2 - Pages Visited + cm_strDelimiter + strBookmark // paramater 3 - BookMark + cm_strDelimiter + strUsersName // paramater 4 - UserName + cm_strDelimiter + m_strRootURL + cm_strHomeLocation + "?SessionID=" + (string)sessionID // paramater 5 - ExitURL + cm_strDelimiter + m_strRootURL + cm_strErrorLocation + "?errnum=14" // paramater 6 - ErrorURL + cm_strDelimiter + "" // paramater 7 - Error Message ); // scussfully started lesson // - increase the session timeout Session.Timeout = 40; return; } catch (Exception ex) { //TODO: log this error OutputToToolBook( cm_strReturnCodeCriticalError // paramater 1 - ReturnCode + cm_strDelimiter + "TBListner Error 15. Unknown Error" + ex.Message // paramater 2 - Error Message + cm_strDelimiter + m_strRootURL + cm_strHomeLocation // paramater 3 - ExitURL ); return; } } //Lesson_OnLoad
/// <summary> /// Quiz End event /// </summary> /// <remarks> /// This event fires when a student clicks the “Submit answers” button on the last page. The event will /// .Score: Calculate the score (Question number with correct answer/Total question number * 100) /// .Duration: Calculate the duration of the testing. /// .QuizQuestionAudit: Record quiz question audit. /// .QuizAnswerAudit: Record quiz answer audit /// </remarks> public void Quiz_End() { //certemail(956, 42, 0); if (!PageContext.Current.IsPreviewMode) { try { BusinessServices.Toolbook objToolbook = new BusinessServices.Toolbook(); NameValueCollection nvcAnswers = CurrentQuizContext.Answers; DataTable endQuizInfo; int intUserID; int intQuizID; int intPassMark; int intUnitID; int intModuleID; int intQuizFrequency; int intOldCourseStatus; int intNewCourseStatus; int intNewQuizStatus; int intCourseID; DateTime dtmQuizCompletionDate; foreach (string strKey in nvcAnswers.AllKeys) { objToolbook.CreateQuizQuestionAudit(PageContext.Current.SessionID, strKey); objToolbook.CreateQuizAnswerAudit(PageContext.Current.SessionID, strKey, Convert.ToInt32(nvcAnswers[strKey])); } int intScore = objToolbook.GetQuizScore(PageContext.Current.SessionID); TimeSpan objTimeSpan = DateTime.Now.Subtract(PageContext.Current.StartTime); //objToolbook.EndQuizSession(PageContext.Current.SessionID,objTimeSpan.Seconds,intScore); endQuizInfo = objToolbook.BeforeQuizEnd(PageContext.Current.SessionID, objTimeSpan.Seconds, 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 = 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()); int intProfileID = Int32.Parse(Request.QueryString["ProfileID"].ToString()); dtmQuizCompletionDate = (tmpRow["QuizCompletionDate"] == System.DBNull.Value ? DateTime.Parse("1/1/1900"): (DateTime)tmpRow["QuizCompletionDate"]); endQuizInfo = objToolbook.EndQuizSession_UpdateTables(PageContext.Current.SessionID, objTimeSpan.Seconds, intScore, intUserID, intQuizID, intPassMark, intUnitID, intModuleID, intCourseID, intOldCourseStatus, intNewQuizStatus, intNewCourseStatus, intQuizFrequency, dtmQuizCompletionDate); tmpRow = endQuizInfo.Rows[0]; Boolean blnSendCert = (bool)tmpRow["sendcert"]; if (blnSendCert) { certemail(intUserID, intCourseID, intProfileID); } //obtain profileIDs for all profiles that have access to module and apply points BusinessServices.Profile objProfile = new BusinessServices.Profile(); DataTable dtProfiles = objProfile.ProfilesWithModuleAccess(intUserID, intModuleID); foreach (DataRow dr in dtProfiles.Rows) { int ProfileID = int.Parse(dr["ProfileID"].ToString()); ApplyProfilePoints(ProfileID, intNewQuizStatus, intModuleID, intUserID); } Session["CourseID"] = intCourseID.ToString(); Session["CourseID_ProfileID"] = "CourseID=" + intCourseID.ToString() + "&ProfileID=" + intProfileID.ToString(); } catch (Exception ex) { if (ex.Message.ToLower().StartsWith("violation of primary key")) { Response.Write(ResourceManager.GetString("QuizLesson_Error")); Response.End(); } else { //throw ex; ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex); } } Response.Redirect("/Reporting/QuizResult.aspx?QuizSessionID=" + PageContext.Current.SessionID); } }