Esempio n. 1
0
        /// <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;
                    }
                }
            }
        }
Esempio n. 2
0
        }         // 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