Exemplo n.º 1
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is validated
        protected void WriteError(PlainTextString message, bool allowReloadCurrentActivity)
        {
            FramesetUtil.ValidateNonNullParameter("message", message);
            string msgToDisplay;

            // If the message will contain a link to reload the current activity, then add the link to have the
            // framesetMgr load the activity. We have to do this (rather than a get request) since we need to
            // re-initialize the RTE object at this point.
            if (allowReloadCurrentActivity)
            {
                JScriptString js =
                    new JScriptString(
                        ResHelper.FormatInvariant(
                            "API_GetFramesetManager().DoChoice(\"{0}\");",
                            FramesetUtil.GetStringInvariant(this.mSession.CurrentActivityId)));
                string        origMessage = message.ToString();
                StringBuilder sb          = new StringBuilder(origMessage.Length * 2);
                sb.Append(
                    ResHelper.Format(
                        "{0}<br><br><a href='{1}' >{2}</a>",
                        origMessage,
                        js.ToJavascriptProtocol(),
                        Localization.GetMessage("HID_ReloadCurrentContent")));

                msgToDisplay = sb.ToString();
            }
            else
            {
                msgToDisplay = message.ToString();
            }
            this.RegisterError(
                Localization.GetMessage("HID_ServerErrorTitle"), msgToDisplay, false);
        }
Exemplo n.º 2
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is validated
        protected void WriteSubmitPage(string titleHtml, string messageHtml, string saveButtonHtml)
        {
            FramesetUtil.ValidateNonNullParameter("messageHtml", messageHtml);
            string msgToDisplay;
            bool   hasCurrentActivity = this.Session.HasCurrentActivity;

            // The message will contain a link to submit the attempt.
            StringBuilder sb = new StringBuilder(messageHtml.Length * 2 + 500);

            sb.AppendLine("<script>");

            // If there is a current activity to return to, allow the user to do that.
            if (hasCurrentActivity)
            {
                sb.AppendLine("function onCancel(event)");
                sb.AppendLine("{");
                sb.AppendLine(" var frameMgr = API_GetFramesetManager();");
                sb.AppendLine(" if (frameMgr.ReadyForNavigation())");
                sb.AppendLine(" {");
                sb.AppendLine(
                    ResHelper.Format(
                        "     frameMgr.DoChoice(\"{0}\");",
                        FramesetUtil.GetStringInvariant(this.mSession.CurrentActivityId)));
                sb.AppendLine(" }");
                sb.AppendLine(" event.cancelBubble = true;");
                sb.AppendLine(" event.returnValue = false;");
                sb.AppendLine("}");
            }

            sb.AppendLine("function onSubmit(event)");
            sb.AppendLine("{");
            sb.AppendLine(" var frameMgr = API_GetFramesetManager();");
            sb.AppendLine(" if (frameMgr.ReadyForNavigation())");
            sb.AppendLine(" {");
            sb.AppendLine("     frameMgr.DoSubmit();");
            sb.AppendLine(" }");
            sb.AppendLine(" event.cancelBubble = true;");
            sb.AppendLine(" event.returnValue = false;");
            sb.AppendLine("}");
            sb.AppendLine("</script>");
            sb.AppendLine(
                ResHelper.Format(
                    "{0}<br><br><input type='button' value='{1}' id='submitBtn' onClick='onSubmit(event)'/>",
                    messageHtml,
                    saveButtonHtml));

            if (hasCurrentActivity)
            {
                sb.AppendLine(
                    ResHelper.Format(
                        "&nbsp;&nbsp;<input type='button' value='{0}' id='cancelBtn' onClick='onCancel(event)'/>",
                        Localization.GetMessage("POST_ContinueHtml")));
            }

            msgToDisplay = sb.ToString();
            this.RegisterError(titleHtml, msgToDisplay, true);

            this.SubmitPageDisplayed = true;
        }
Exemplo n.º 3
0
        /// <summary>Writes the frame manager initialization javascript.</summary>
        public void WriteFrameMgrInit()
        {
            Response.Write(ResHelper.Format("frameMgr.SetAttemptId({0});\r\n", FramesetUtil.GetString(m_attemptId)));
            Response.Write(ResHelper.Format("frameMgr.SetView({0});\r\n", FramesetUtil.GetString(m_view)));
            Response.Write("frameMgr.SetPostFrame(\"frameHidden\");\r\n");
            Response.Write("frameMgr.SetPostableForm(GetHiddenFrame().contentWindow.document.forms[0]);\r\n");

            // Tell frameMgr to move to new activity
            Response.Write(ResHelper.Format("frameMgr.DoChoice(\"{0}\", true);\r\n", FramesetUtil.GetStringInvariant(m_activityId)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the string to use to redirect the current response to ChangeActivity page.
        /// </summary>
        /// <returns></returns>
        private string GetRedirectLocation()
        {
            string url = ResHelper.Format("./ChangeActivity.aspx?{0}={1}&{2}={3}&{4}={5}",
                                          FramesetQueryParameter.View, FramesetUtil.GetString(Session.View),
                                          FramesetQueryParameter.AttemptId, FramesetUtil.GetStringInvariant(Session.AttemptId.GetKey()),
                                          FramesetQueryParameter.ActivityId, FramesetUtil.GetStringInvariant(Session.CurrentActivityId));
            UrlString urlStr = new UrlString(url);

            return(urlStr.ToAscii());
        }
Exemplo n.º 5
0
        /// <summary>Write initialization code for frameset manager. </summary>
        /// <remarks>
        /// This method is called in three possible cases:
        /// 1. An error condition occurred
        /// 2. The submit page is being displayed. Note that in this case, since the submit page is registered as displaying an
        /// error condition, HasError will be true.
        /// 3. The current activity has changed and we display this page mainly so that the 'please wait' information can be
        /// displayed and the client can issue a GET request to load the new activity.
        /// </remarks>
        public void WriteFrameMgrInit()
        {
            // Write frame to post. When displaying an error (which is the case, since we are here) the hidden frame is posted next
            Response.Write("frameMgr.SetPostFrame('frameHidden');\r\n");
            Response.Write("frameMgr.SetPostableForm(window.top.frames[MAIN_FRAME].document.getElementById(HIDDEN_FRAME).contentWindow.document.forms[0]);\r\n");

            if (HasError || SubmitPageDisplayed)
            {
                // Set the content frame URL to be null. This means the content frame will not be re-loaded by the frameMgr.
                Response.Write("frameMgr.SetContentFrameUrl(null); \r\n");
            }

            // If there is no session, we can't do anything else
            if (Session == null)
            {
                return;
            }

            if ((ActivityHasChanged) && (!SubmitPageDisplayed))
            {
                // Reload the content frame with the new activity.
                Response.Write(String.Format(CultureInfo.CurrentCulture, "frameMgr.SetContentFrameUrl(\"{0}\"); \r\n", GetContentFrameUrl()));

                // The new activity may be scorm content, so reinitialize the rte, if needed
                Response.Write(ResHelper.Format("frameMgr.InitNewActivity( {0} );\r\n", (CurrentActivityRequiresRte ? "true" : "false")));
            }

            Response.Write(ResHelper.Format("frameMgr.SetAttemptId('{0}');\r\n", FramesetUtil.GetStringInvariant(Session.AttemptId.GetKey())));

            // Write view to display.
            Response.Write(String.Format(CultureInfo.CurrentCulture, "frameMgr.SetView('{0}');\r\n", FramesetUtil.GetString(Session.View)));

            // Write the current activity Id. Write -1 if there isn't one.
            string activityId;

            if (SubmitPageDisplayed)
            {
                activityId = SubmitId;
            }
            else
            {
                activityId = (Session.HasCurrentActivity ? FramesetUtil.GetStringInvariant(Session.CurrentActivityId) : "-1");
            }
            Response.Write(String.Format(CultureInfo.InvariantCulture, "frameMgr.SetActivityId({0});\r\n",
                                         JScriptString.QuoteString(activityId, true)));

            // Write nav visibility, in case it's changed since the hidden frame was rendered
            if (SubmitPageDisplayed)
            {
                // If the submit page is being displayed, don't show UI elements
                Response.Write(String.Format(CultureInfo.CurrentCulture, "frameMgr.SetNavVisibility( {0}, {1}, {2}, {3}, {4});",
                                             ("false"), // showNext
                                             ("false"), // showPrevious
                                             ("false"), // showAbandon
                                             ("false"), // showExit
                                             (Session.ShowSave ? "true" : "false")));

                // If the submit page is now being displayed, make sure the frameset isn't waiting for another commit
                Response.Write("frameMgr.WaitForContentCompleted(0);\r\n");
            }
            else
            {
                Response.Write(String.Format(CultureInfo.CurrentCulture, "frameMgr.SetNavVisibility( {0}, {1}, {2}, {3}, {4});\r\n",
                                             (Session.ShowNext ? "true" : "false"),
                                             (Session.ShowPrevious ? "true" : "false"),
                                             (Session.ShowAbandon ? "true" : "false"),
                                             (Session.ShowExit ? "true" : "false"),
                                             (Session.ShowSave ? "true" : "false")));
            }

            // Register that the frame loading is complete. This is required so as to notify the frameset of activity id, and
            // other UI status.
            Response.Write(String.Format(CultureInfo.InvariantCulture, "frameMgr.RegisterFrameLoad({0});\r\n ",
                                         JScriptString.QuoteString("frameContent", false)));

            if (m_isPostedPage)
            {
                // Set PostIsComplete. THIS MUST BE THE LAST VALUE SET!
                Response.Write("frameMgr.PostIsComplete();");
            }
        }
Exemplo n.º 6
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();
                }
            }
        }