예제 #1
0
        public void ProcessPageLoad(TryGetViewInfo TryGetViewInfo,
            TryGetAttemptInfo TryGetAttemptInfo,
            TryGetActivityInfo TryGetActivityInfo,
            RegisterError registerError,
            GetErrorInfo getErrorInfo,
            GetFramesetMsg getFramesetMessage)
        {
            RegisterError = registerError;
            GetErrorInfo = getErrorInfo;
            GetFramesetMsg = getFramesetMessage;

            // This page simply causes the frameset to request to move to a different activity. It does not verify that
            // the user is authorized to do this. If the user is not authorized, the subsequent request will fail.

            if (!TryGetViewInfo(true, out m_view))
            {
                return;
            }

            if (!TryGetAttemptInfo(true, out m_attemptId))
            {
               return;
            }

            if (!TryGetActivityInfo(true, out m_activityId))
            {
                return;
            }
        }
예제 #2
0
        public void ProcessPageLoad(TryGetViewInfo TryGetViewInfo,
                                    TryGetAttemptInfo TryGetAttemptInfo,
                                    TryGetActivityInfo TryGetActivityInfo,
                                    RegisterError registerError,
                                    GetErrorInfo getErrorInfo,
                                    GetFramesetMsg getFramesetMessage)
        {
            RegisterError  = registerError;
            GetErrorInfo   = getErrorInfo;
            GetFramesetMsg = getFramesetMessage;

            // This page simply causes the frameset to request to move to a different activity. It does not verify that
            // the user is authorized to do this. If the user is not authorized, the subsequent request will fail.

            if (!TryGetViewInfo(true, out m_view))
            {
                return;
            }

            if (!TryGetAttemptInfo(true, out m_attemptId))
            {
                return;
            }

            if (!TryGetActivityInfo(true, out m_activityId))
            {
                return;
            }
        }
예제 #3
0
        // it's not worth changing this now
        public void ProcessPageLoad(
            PackageStore packageStore,
            bool firstRendering,
            // frameset is being initialized
            bool isPostBack,
            // page was posted
            TryGetViewInfo tryGetViewInfo,
            TryGetAttemptInfo tryGetAttemptInfo,
            TryGetActivityInfo tryGetActivityInfo,
            GetResourcePath getResourcePath,
            AppendContentFrameDetails appendContentFrameDetails,
            UpdateRenderContext updateRenderContext,
            ProcessPostedData processPostedData,
            ProcessViewRequest processViewRequest,
            ProcessPostedDataComplete processPostedDataComplete,
            RegisterError registerError,
            GetErrorInfo getErrorInfo,
            GetFramesetMsg getFramesetMsg)
        {
            this.RegisterError = registerError;
            this.UpdateRenderContext = updateRenderContext;
            this.GetErrorInfo = getErrorInfo;
            this.AppendContentFrameDetails = appendContentFrameDetails;
            this.GetFramesetMsg = getFramesetMsg;

            this.mIsPostedPage = isPostBack;

            // If this is the first time the page is being rendered, just show 'please wait' and return.
            if (firstRendering)
            {
                // Initial page rendering, show "please wait"
                WritePleaseWaitToResponse(this.Response);
                this.Response.End();
                return;
            }

            SessionView view;

            // Get View information. It determines what else to look for.
            if (!tryGetViewInfo(true, out view))
            {
                return;
            }

            // There is something to display, so process the request...

            AttemptItemIdentifier attemptId;
            if (!tryGetAttemptInfo(true, out attemptId))
            {
                return;
            }

            StoredLearningSession slsSession = new StoredLearningSession(view, attemptId, packageStore);

            if (!processViewRequest(view, slsSession))
            {
                return;
            }

            this.Session = slsSession;

            if (slsSession.View == SessionView.Execute)
            {
                // Check if the session can be executed...

                if (slsSession.AttemptStatus != AttemptStatus.Active)
                {
                    this.RegisterError(
                        this.GetFramesetMsg(FramesetStringId.CannotDisplayContentTitle),
                        this.GetFramesetMsg(FramesetStringId.SessionIsNotActiveMsg),
                        false);
                    return;
                }

                if (!slsSession.CurrentActivityIsActive)
                {
                    this.RegisterError(
                        this.GetFramesetMsg(FramesetStringId.SelectActivityTitleHtml),
                        this.GetFramesetMsg(FramesetStringId.SelectActivityMessageHtml),
                        true);
                    return;
                }
            }
            else if (slsSession.View == SessionView.Review)
            {
                // Get information about which activity to review, then make that the current activity.

                long activityId = -1; // make compiler happy
                if (!tryGetActivityInfo(true, out activityId))
                {
                    return;
                }

                // Move to the requested activity. Under normal conditions, this should always succeed, since the frameset should be 
                // giving this page a valid activity id.
                MoveToActivity(slsSession, activityId);
            }

            else if (slsSession.View == SessionView.RandomAccess)
            {
                // Get information about which activity to edit, then make that the current activity.

                long activityId = -1; // make compiler happy
                if (!tryGetActivityInfo(true, out activityId))
                {
                    return;
                }

                // Move to the requested activity. Under normal conditions, this should always succeed, since the frameset should be 
                // giving this page a valid activity id.
                MoveToActivity(slsSession, activityId);
            }

            if (isPostBack /* && !SessionEnded */)
            {
                // Process information from posted content
                if (!this.SessionIsReadOnly)
                {
                    HttpFileCollection files = this.Request.Files;
                    int numFiles = files.Count;
                    Dictionary<string, HttpPostedFile> newFileCollection =
                        new Dictionary<string, HttpPostedFile>(numFiles);

                    // Allow the application to process the form data
                    if (!processPostedData(slsSession, this.Request, newFileCollection))
                    {
                        return;
                    }

                    // Allow MLC to process the form data
                    this.Session.ProcessFormData(this.Request.Form, newFileCollection);

                    // Allow application to do final processing after all posted data is processed.
                    processPostedDataComplete(this.Session);

                    // If there was an error in processing form data, end the processing. This allows, for instance, to 
                    // save the data, display an error and not have commands (such as 'move to next activity') executed.
                    if (this.HasError)
                    {
                        this.Session.CommitChanges();
                        return;
                    }
                }

                // Issue with Review view: where to get activity id? From URL or posted data?

                // Find out what the commands are and do them.
                ICollection<CommandInfo> commands = this.GetCommands();
                foreach (CommandInfo cmdInfo in commands)
                {
                    switch (cmdInfo.Command)
                    {
                        case Commands.DoNext:
                            {
                                // When leaving a current activity, we must allow navigation requests the SCO has made to be 
                                // executed. If that results in changing the current activity, then do not also ask for another 
                                // move.
                                if (!ProcessNavigationRequests(this.Session))
                                {
                                    if (this.Session.IsMoveToNextValid())
                                    {
                                        MoveToNextActivity(this.Session);
                                        this.ActivityHasChanged = true;
                                    }
                                }
                                else
                                {
                                    this.ActivityHasChanged = true;
                                }

                                if (!this.ActivityHasChanged)
                                {
                                    // Moving to the next activity is not valid. 

                                    this.WriteError(
                                        ResHelper.Format(
                                            this.GetFramesetMsg(FramesetStringId.MoveToNextFailedHtml),
                                            this.ThemeFolderPath),
                                        true);
                                }
                            }
                            break;
                        case Commands.DoPrevious:
                            {
                                if (!ProcessNavigationRequests(this.Session))
                                {
                                    if (this.Session.IsMoveToPreviousValid())
                                    {
                                        MoveToPreviousActivity(this.Session);
                                        this.ActivityHasChanged = true;
                                    }
                                }
                                else
                                {
                                    this.ActivityHasChanged = true;
                                }

                                if (!this.ActivityHasChanged)
                                {
                                    // Moving to the previous activity is not valid.
                                    this.WriteError(
                                        ResHelper.Format(
                                            this.GetFramesetMsg(FramesetStringId.MoveToPreviousFailedHtml),
                                            this.ThemeFolderPath),
                                        true);
                                }
                            }
                            break;
                        case Commands.DoChoice:
                        case Commands.DoTocChoice:
                            {
                                // These commands are used to navigate to activities, and to navigate to the final 'submit' page.
                                // In SCORM content, these commands do different things. In LRM content (which is what we are 
                                // in, since this is the posted page), they have identical effects. 

                                // First check whether this is a request for the submit page or an activity.

                                string cmdData = cmdInfo.CommandData;
                                if (string.CompareOrdinal(cmdData, SubmitId) == 0)
                                {
                                    // Requesting submit page. Do not change the current activity, but mark it as changed so that 
                                    // it appears to the user that it has changed.
                                    this.ActivityHasChanged = true;
                                    string title = this.GetFramesetMsg(FramesetStringId.SubmitPageTitleHtml);
                                    string message;
                                    string saveBtn = this.GetFramesetMsg(FramesetStringId.SubmitPageSaveButtonHtml);
                                    if (this.Session.HasCurrentActivity)
                                    {
                                        message = this.GetFramesetMsg(FramesetStringId.SubmitPageMessageHtml);
                                    }
                                    else
                                    {
                                        message =
                                            this.GetFramesetMsg(FramesetStringId.SubmitPageMessageNoCurrentActivityHtml);
                                    }
                                    this.WriteSubmitPage(title, message, saveBtn);
                                }
                                else
                                {
                                    long activityId;
                                    if (long.TryParse(cmdData, out activityId))
                                    {
                                        // If the requested activity is the current activity, then do not do the navigation.
                                        // We skip it because moving to the activity basically exits the current attempt and creates
                                        // a new one. That new one also increments the attempt count. If we don't do the move, we 
                                        // pretend it was done. This will force the content frame to be reloaded with the current 
                                        // activity.
                                        if (this.IsCurrentActiveActivity(activityId))
                                        {
                                            this.ActivityHasChanged = true;
                                        }
                                        else
                                        {
                                            if (!ProcessNavigationRequests(this.Session))
                                            {
                                                if (this.Session.IsMoveToActivityValid(activityId))
                                                {
                                                    MoveToActivity(this.Session, activityId);
                                                    this.ActivityHasChanged = true;
                                                }
                                            }
                                            else
                                            {
                                                this.ActivityHasChanged = true;
                                            }
                                        }
                                    }
                                }

                                if (!this.ActivityHasChanged)
                                {
                                    // Moving to the selected activity is not valid. 

                                    this.WriteError(
                                        ResHelper.Format(
                                            this.GetFramesetMsg(FramesetStringId.MoveToActivityFailedHtml),
                                            this.ThemeFolderPath),
                                        true);
                                }
                            }
                            break;
                        case Commands.DoSave:
                            {
                                // Do nothing. The information will be saved since the page was posted.
                            }
                            break;
                        case Commands.DoSubmit:
                            {
                                if (this.Session.View == SessionView.Execute)
                                {
                                    ProcessNavigationRequests(this.Session);
                                    this.Session.Exit();
                                }

                                this.ActivityHasChanged = true;
                            }
                            break;
                    }
                }
            }

            // If an error has been registered (and it's not the submit 
            // page rendering), don't attempt to render the content.
            if (this.HasError && !this.SubmitPageDisplayed)
            {
                if (!this.SessionIsReadOnly)
                {
                    this.Session.CommitChanges();
                }
                return;
            }

            // There was no error, so go ahead and render the content from the package.
            // If the current activity has changed in the processing of this page, then render the current activity's resource.
            // Otherwise, ask the application which resource to read.
            if (this.ActivityHasChanged)
            {
                // If the activity has changed, we render the content page without rendering the content. The page will then 
                // reload the content frame with the new activity.
                if (!this.SessionIsReadOnly)
                {
                    this.Session.CommitChanges();
                }
            }
            else
            {
                // Render the requested file in the current activity.
                this.RenderPackageContent(getResourcePath());

                // If there was no error, end the response. Otherwise, we wait and render the error on the page.
                if (!this.HasError)
                {
                    this.Response.End();
                }
            }
        }
예제 #4
0
        [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] // it's not worth changing this now
        public void ProcessPageLoad(PackageStore packageStore,
                                    bool firstRendering,                                  // frameset is being initialized
                                    bool isPostBack,                                      // page was posted
                                    TryGetViewInfo TryGetViewInfo,
                                    TryGetAttemptInfo TryGetAttemptInfo,
                                    TryGetActivityInfo TryGetActivityInfo,
                                    GetResourcePath GetResourcePath,
                                    AppendContentFrameDetails appendContentFrameDetails,
                                    UpdateRenderContext updateRenderContext,
                                    ProcessPostedData ProcessPostedData,
                                    ProcessViewRequest ProcessViewRequest,
                                    ProcessPostedDataComplete ProcessPostedDataComplete,
                                    RegisterError registerError,
                                    GetErrorInfo getErrorInfo,
                                    GetFramesetMsg getFramesetMsg)
        {
            RegisterError             = registerError;
            UpdateRenderContext       = updateRenderContext;
            GetErrorInfo              = getErrorInfo;
            AppendContentFrameDetails = appendContentFrameDetails;
            GetFramesetMsg            = getFramesetMsg;

            m_isPostedPage = isPostBack;

            // If this is the first time the page is being rendered, just show 'please wait' and return.
            if (firstRendering)
            {
                // Initial page rendering, show "please wait"
                WritePleaseWaitToResponse(Response);
                Response.End();
                return;
            }

            SessionView view;

            // Get View information. It determines what else to look for.
            if (!TryGetViewInfo(true, out view))
            {
                return;
            }

            // There is something to display, so process the request...

            AttemptItemIdentifier attemptId;

            if (!TryGetAttemptInfo(true, out attemptId))
            {
                return;
            }

            StoredLearningSession slsSession = new StoredLearningSession(view, attemptId, packageStore);

            if (!ProcessViewRequest(view, slsSession))
            {
                return;
            }

            Session = slsSession;

            if (slsSession.View == SessionView.Execute)
            {
                // Check if the session can be executed...

                if (slsSession.AttemptStatus != AttemptStatus.Active)
                {
                    RegisterError(GetFramesetMsg(FramesetStringId.CannotDisplayContentTitle),
                                  GetFramesetMsg(FramesetStringId.SessionIsNotActiveMsg), false);
                    return;
                }

                if (!slsSession.CurrentActivityIsActive)
                {
                    RegisterError(GetFramesetMsg(FramesetStringId.SelectActivityTitleHtml),
                                  GetFramesetMsg(FramesetStringId.SelectActivityMessageHtml), true);
                    return;
                }
            }
            else if (slsSession.View == SessionView.Review)
            {
                // Get information about which activity to review, then make that the current activity.

                long activityId = -1;   // make compiler happy
                if (!TryGetActivityInfo(true, out activityId))
                {
                    return;
                }

                // Move to the requested activity. Under normal conditions, this should always succeed, since the frameset should be
                // giving this page a valid activity id.
                MoveToActivity(slsSession, activityId);
            }

            else if (slsSession.View == SessionView.RandomAccess)
            {
                // Get information about which activity to edit, then make that the current activity.

                long activityId = -1;   // make compiler happy
                if (!TryGetActivityInfo(true, out activityId))
                {
                    return;
                }

                // Move to the requested activity. Under normal conditions, this should always succeed, since the frameset should be
                // giving this page a valid activity id.
                MoveToActivity(slsSession, activityId);
            }

            if (isPostBack /* && !SessionEnded */)
            {
                //Process information from posted content
                if (!this.SessionIsReadOnly)
                {
                    HttpFileCollection files = Request.Files;
                    int numFiles             = files.Count;
                    Dictionary <string, HttpPostedFile> newFileCollection = new Dictionary <string, HttpPostedFile>(numFiles);

                    // Allow the application to process the form data
                    if (!ProcessPostedData(slsSession, Request, newFileCollection))
                    {
                        return;
                    }

                    // Allow MLC to process the form data
                    Session.ProcessFormData(Request.Form, newFileCollection);

                    // Allow application to do final processing after all posted data is processed.
                    ProcessPostedDataComplete(Session);

                    // If there was an error in processing form data, end the processing. This allows, for instance, to
                    // save the data, display an error and not have commands (such as 'move to next activity') executed.
                    if (HasError)
                    {
                        Session.CommitChanges();
                        return;
                    }
                }

                // Issue with Review view: where to get activity id? From URL or posted data?

                // Find out what the commands are and do them.
                ICollection <CommandInfo> commands = GetCommands();
                foreach (CommandInfo cmdInfo in commands)
                {
                    switch (cmdInfo.Command)
                    {
                    case Commands.DoNext:
                    {
                        // When leaving a current activity, we must allow navigation requests the SCO has made to be
                        // executed. If that results in changing the current activity, then do not also ask for another
                        // move.
                        if (!ProcessNavigationRequests(Session))
                        {
                            if (Session.IsMoveToNextValid())
                            {
                                MoveToNextActivity(Session);
                                ActivityHasChanged = true;
                            }
                        }
                        else
                        {
                            ActivityHasChanged = true;
                        }

                        if (!ActivityHasChanged)
                        {
                            // Moving to the next activity is not valid.

                            WriteError(ResHelper.Format(GetFramesetMsg(FramesetStringId.MoveToNextFailedHtml), ThemeFolderPath), true);
                        }
                    }
                    break;

                    case Commands.DoPrevious:
                    {
                        if (!ProcessNavigationRequests(Session))
                        {
                            if (Session.IsMoveToPreviousValid())
                            {
                                MoveToPreviousActivity(Session);
                                ActivityHasChanged = true;
                            }
                        }
                        else
                        {
                            ActivityHasChanged = true;
                        }


                        if (!ActivityHasChanged)
                        {
                            // Moving to the previous activity is not valid.
                            WriteError(ResHelper.Format(GetFramesetMsg(FramesetStringId.MoveToPreviousFailedHtml), ThemeFolderPath), true);
                        }
                    }
                    break;

                    case Commands.DoChoice:
                    case Commands.DoTocChoice:
                    {
                        // These commands are used to navigate to activities, and to navigate to the final 'submit' page.
                        // In SCORM content, these commands do different things. In LRM content (which is what we are
                        // in, since this is the posted page), they have identical effects.

                        // First check whether this is a request for the submit page or an activity.

                        string cmdData = cmdInfo.CommandData;
                        if (String.CompareOrdinal(cmdData, SubmitId) == 0)
                        {
                            // Requesting submit page. Do not change the current activity, but mark it as changed so that
                            // it appears to the user that it has changed.
                            ActivityHasChanged = true;
                            string title = GetFramesetMsg(FramesetStringId.SubmitPageTitleHtml);
                            string message;
                            string saveBtn = GetFramesetMsg(FramesetStringId.SubmitPageSaveButtonHtml);
                            if (Session.HasCurrentActivity)
                            {
                                message = GetFramesetMsg(FramesetStringId.SubmitPageMessageHtml);
                            }
                            else
                            {
                                message = GetFramesetMsg(FramesetStringId.SubmitPageMessageNoCurrentActivityHtml);
                            }
                            WriteSubmitPage(title, message, saveBtn);
                        }
                        else
                        {
                            long activityId;
                            if (long.TryParse(cmdData, out activityId))
                            {
                                // If the requested activity is the current activity, then do not do the navigation.
                                // We skip it because moving to the activity basically exits the current attempt and creates
                                // a new one. That new one also increments the attempt count. If we don't do the move, we
                                // pretend it was done. This will force the content frame to be reloaded with the current
                                // activity.
                                if (IsCurrentActiveActivity(activityId))
                                {
                                    ActivityHasChanged = true;
                                }
                                else
                                {
                                    if (!ProcessNavigationRequests(Session))
                                    {
                                        if (Session.IsMoveToActivityValid(activityId))
                                        {
                                            MoveToActivity(Session, activityId);
                                            ActivityHasChanged = true;
                                        }
                                    }
                                    else
                                    {
                                        ActivityHasChanged = true;
                                    }
                                }
                            }
                        }

                        if (!ActivityHasChanged)
                        {
                            // Moving to the selected activity is not valid.

                            WriteError(ResHelper.Format(GetFramesetMsg(FramesetStringId.MoveToActivityFailedHtml), ThemeFolderPath), true);
                        }
                    }
                    break;

                    case Commands.DoSave:
                    {
                        // Do nothing. The information will be saved since the page was posted.
                    }
                    break;

                    case Commands.DoSubmit:
                    {
                        if (Session.View == SessionView.Execute)
                        {
                            ProcessNavigationRequests(Session);
                            Session.Exit();
                        }

                        ActivityHasChanged = true;
                    }
                    break;
                    }
                }
            }

            // If an error has been registered (and it's not the submit
            // page rendering), don't attempt to render the content.
            if (HasError && !SubmitPageDisplayed)
            {
                if (!SessionIsReadOnly)
                {
                    Session.CommitChanges();
                }
                return;
            }

            // There was no error, so go ahead and render the content from the package.
            // If the current activity has changed in the processing of this page, then render the current activity's resource.
            // Otherwise, ask the application which resource to read.
            if (ActivityHasChanged)
            {
                // If the activity has changed, we render the content page without rendering the content. The page will then
                // reload the content frame with the new activity.
                if (!SessionIsReadOnly)
                {
                    Session.CommitChanges();
                }
            }
            else
            {
                // Render the requested file in the current activity.
                RenderPackageContent(GetResourcePath());

                // If there was no error, end the response. Otherwise, we wait and render the error on the page.
                if (!HasError)
                {
                    Response.End();
                }
            }
        }