Exemple #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);
        }
Exemple #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;
        }
Exemple #3
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]    // parameter is validated
        protected void VerifyElementNameTokens(int numberRequired, string[] nameTokens)
        {
            FramesetUtil.ValidateNonNullParameter("nameTokens", nameTokens);

            if (nameTokens.Length < numberRequired)
            {
                throw new InvalidOperationException(ResHelper.GetMessage(FramesetResources.CONV_SetValueInvalidName, m_currentElementName));
            }
        }
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]    // parameter is validated
        protected void VerifyElementNameTokens(int numberRequired, string[] nameTokens)
        {
            FramesetUtil.ValidateNonNullParameter("nameTokens", nameTokens);

            if (nameTokens.Length < numberRequired)
            {
                throw new InvalidOperationException(ResHelper.GetMessage(IUDICO.TestingSystem.Localization.getMessage("CONV_SetValueInvalidName"), m_currentElementName));
            }
        }
Exemple #5
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is validated
        protected static void MoveToActivity(LearningSession session, long activityId)
        {
            FramesetUtil.ValidateNonNullParameter("session", session);
            session.MoveToActivity(activityId);

            // If this is random access view, make sure to move to an activity that has a resource.
            if ((session.View == SessionView.RandomAccess) && (session.CurrentActivityResourceType == ResourceType.None))
            {
                MoveToNextActivity(session);
            }
        }
Exemple #6
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is validated
        public static RteDataModelConverter Create(LearningSession session)
        {
            FramesetUtil.ValidateNonNullParameter("session", session);
            switch (session.PackageFormat)
            {
            case PackageFormat.V1p2:
            case PackageFormat.Lrm:
                return(new Rte1p2DataModelConverter(session.View, session.CurrentActivityDataModel));

            case PackageFormat.V1p3:
                return(new Rte2004DataModelConverter(session.View, session.CurrentActivityDataModel));
            }
            return(null);
        }
Exemple #7
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is validated
        public static string GetRteLearnerResponse(object response)
        {
            FramesetUtil.ValidateNonNullParameter("response", response);
            Type responseType = response.GetType();

            if ((responseType == Type.GetType("System.Boolean")) || (responseType == Type.GetType("bool")))
            {
                bool br = (bool)response;
                return(br ? "true" : "false");
            }
            else if (responseType == Type.GetType("float"))
            {
                float fr = (float)response;
                return(fr.ToString(NumberFormatInfo.InvariantInfo));
            }

            return(response.ToString());
        }
Exemple #8
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // arguments are validated
        public void ProcessPageLoad(
            HttpResponse response,
            PackageStore packageStore,
            TryGetViewInfo tryGetViewInfo,
            TryGetAttemptInfo tryGetAttemptInfo,
            ProcessViewRequest processViewRequest,
            RegisterError registerError,
            string submitPageLinkText)
        {
            FramesetUtil.ValidateNonNullParameter("packageStore", packageStore);
            FramesetUtil.ValidateNonNullParameter("tryGetViewInfo", tryGetViewInfo);
            FramesetUtil.ValidateNonNullParameter("tryGetAttemptInfo", tryGetAttemptInfo);
            FramesetUtil.ValidateNonNullParameter("registerError", registerError);

            this.mResponse           = response;
            this.mSubmitPageLinkText = submitPageLinkText;

            AttemptItemIdentifier attemptId;
            SessionView           view;

            if (!tryGetViewInfo(true, out view))
            {
                return;
            }

            // This is an attempt-based session
            if (!tryGetAttemptInfo(true, out attemptId))
            {
                return;
            }

            this.mSession = new StoredLearningSession(view, new AttemptItemIdentifier(attemptId), packageStore);

            // If user cannot access the session, then remove the reference to the session.
            if (!processViewRequest(view, this.mSession))
            {
                this.mSession = null;
            }
        }
Exemple #9
0
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]    // parameter is validated
        private void WriteTocEntry(HtmlStringWriter sw, TableOfContentsElement currentElement)
        {
            FramesetUtil.ValidateNonNullParameter("sw", sw);
            FramesetUtil.ValidateNonNullParameter("currentElement", currentElement);

            string     activityId         = FramesetUtil.GetStringInvariant(currentElement.ActivityId);
            bool       elementHasChildren = currentElement.Children.Count > 0;
            HtmlString activityIdHtml     = new PlainTextString(activityId).ToHtmlString();
            HtmlString titleHtml          = new PlainTextString(currentElement.Title).ToHtmlString();

            // If the current element is visible or is an invisible leaf node, then render it. (If it's an
            // invisible leaf node, the node will exist but not be visible.)
            if (RenderThisNode(currentElement))
            {
                sw.AddAttribute(HtmlTextWriterAttribute.Class, new PlainTextString("NodeParent"));
                sw.AddAttribute("activityId", activityIdHtml);
                sw.AddAttribute("isValidChoice", (currentElement.IsValidChoiceNavigationDestination ? "true" : "false"));
                sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("div{0}", activityIdHtml));
                sw.RenderBeginTag(HtmlTextWriterTag.Div);   // #Div1

                if (currentElement.IsVisible)
                {
                    sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("icon{0}", activityIdHtml));
                    if (currentElement.HasVisibleChildren)
                    {
                        sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/MinusBtn.gif");
                    }
                    else
                    {
                        sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/Leaf.gif");
                    }
                    sw.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
                    sw.RenderBeginTag(HtmlTextWriterTag.Img);
                    sw.RenderEndTag();

                    sw.AddAttribute(HtmlTextWriterAttribute.Src, "Theme/1px.gif");
                    sw.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
                    sw.RenderBeginTag(HtmlTextWriterTag.Img);
                    sw.RenderEndTag();
                    sw.WriteLine();

                    sw.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)");
                    sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("a{0}", activityIdHtml));
                    if (!currentElement.IsValidChoiceNavigationDestination)
                    {
                        sw.AddAttribute(HtmlTextWriterAttribute.Disabled, "true");
                        sw.AddAttribute("class", "disable");
                    }

                    sw.AddAttribute(HtmlTextWriterAttribute.Style,
                                    ResHelper.FormatInvariant("FONT-WEIGHT: normal;visibility:{0}", (currentElement.IsVisible ? "visible" : "hidden")));
                    sw.AddAttribute(HtmlTextWriterAttribute.Title, titleHtml);
                    sw.RenderBeginTag(HtmlTextWriterTag.A);
                    sw.WriteHtml(titleHtml);
                    sw.RenderEndTag();
                }
            }

            // Write sub-elements (regardless of whether or not this node is rendered)
            if (elementHasChildren)
            {
                sw.WriteLine();
                bool clusterStarted = false;
                if (currentElement.IsVisible)
                {
                    sw.AddAttribute(HtmlTextWriterAttribute.Id, ResHelper.FormatInvariant("divCluster{0}", activityIdHtml));
                    sw.AddAttribute(HtmlTextWriterAttribute.Style, "MARGIN-TOP: 5px; DISPLAY: block; MARGIN-LEFT: 18px;");
                    sw.RenderBeginTag(HtmlTextWriterTag.Div);
                    clusterStarted = true;
                }

                foreach (TableOfContentsElement childElement in currentElement.Children)
                {
                    WriteTocEntry(sw, childElement);
                }

                if (clusterStarted)
                {
                    sw.RenderEndTag(); // end div
                    sw.WriteLine();
                }
            }

            if (RenderThisNode(currentElement))
            {
                sw.RenderEndTag();  // div (see #Div1, above)
                sw.WriteLine();
            }
        }
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]   // parameters are validated
        public void ProcessPageLoad(PackageStore packageStore,
                                    TryGetViewInfo TryGetViewInfo,
                                    TryGetAttemptInfo TryGetAttemptInfo,
                                    ProcessViewRequest ProcessViewRequest)
        {
            // These should never be a problem, however fxcop complains about them.
            FramesetUtil.ValidateNonNullParameter("TryGetViewInfo", TryGetViewInfo);
            FramesetUtil.ValidateNonNullParameter("TryGetAttemptInfo", TryGetAttemptInfo);
            FramesetUtil.ValidateNonNullParameter("ProcessViewRequest", ProcessViewRequest);
            FramesetUtil.ValidateNonNullParameter("packageStore", packageStore);

            // Session information that may be required
            SessionView           view;
            AttemptItemIdentifier attemptId; // not required for all views

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

            // Based on View, request other information
            switch (view)
            {
            case SessionView.Execute:
            {
                // AttemptId is required
                if (!TryGetAttemptInfo(true, out attemptId))
                {
                    return;
                }

                // Create the session
                m_session = new StoredLearningSession(view, attemptId, packageStore);

                StoredLearningSession slsSession = m_session as StoredLearningSession;

                if (!ProcessViewRequest(SessionView.Execute, slsSession))
                {
                    return;
                }

                // If the attempt id appeared valid (that is, it was numeric), but does not represent a valid
                // attempt, the call to access AttemptStatus on the session will trigger an InvalidOperationException
                // containing a message for the user that the attempt id was not valid.
                switch (slsSession.AttemptStatus)
                {
                case AttemptStatus.Abandoned:
                {
                    // Can't do execute view on abandoned sessions. The application should have handled this
                    // in the ProcessViewRequest.
                    return;
                }

                case AttemptStatus.Active:
                {
                    // Check if it's started. If not, try starting it and forcing selection of a current activity.
                    if (!slsSession.HasCurrentActivity)
                    {
                        try
                        {
                            slsSession.Start(false);
                            slsSession.CommitChanges();
                        }
                        catch (SequencingException)
                        {
                            // Intentionally ignored. This means it was either already started or could not
                            // select an activity. In either case, just let the content frame ask the user to
                            // deal with selecting an activity.
                        }
                    }
                    else
                    {
                        // If the current activity is not active, then it's possible the frameset was removed from the
                        // user and the content suspended the current activity. In that case, we do this little trick
                        // and try suspending all the activities and then resuming them. The resume will simply resume
                        // all the activities between the current activity and the root. Other suspended activities
                        // will not be affected.
                        if (!slsSession.CurrentActivityIsActive)
                        {
                            slsSession.Suspend();
                            slsSession.Resume();
                            slsSession.CommitChanges();
                        }
                    }
                }
                break;

                case AttemptStatus.Completed:
                {
                    // Can't do execute view on completed sessions. The application should have handled this in the
                    // ProcessViewRequest.
                    return;
                }

                case AttemptStatus.Suspended:
                {
                    // Resume it
                    slsSession.Resume();
                    slsSession.CommitChanges();
                }
                break;

                default:
                    break;
                }
            }
            break;

            case SessionView.RandomAccess:
            {
                // AttemptId is required
                if (!TryGetAttemptInfo(true, out attemptId))
                {
                    return;
                }

                StoredLearningSession slsSession = new StoredLearningSession(SessionView.RandomAccess, attemptId, packageStore);

                m_session = slsSession;

                if (!ProcessViewRequest(SessionView.RandomAccess, slsSession))
                {
                    return;
                }

                // Move to the first activity with a resource.
                PostableFrameHelper.MoveToNextActivity(m_session);
            }
            break;

            case SessionView.Review:
            {
                // AttemptId is required
                if (!TryGetAttemptInfo(true, out attemptId))
                {
                    return;
                }

                // Create the session
                StoredLearningSession slsSession = new StoredLearningSession(view, attemptId, packageStore);
                m_session = slsSession;

                if (!ProcessViewRequest(SessionView.Review, m_session))
                {
                    return;
                }

                // Access a property. If the user doesn't have permission, this will throw exception
                if (m_session.HasCurrentActivity)
                {
                    // This is good. The 'if' statement is here to make compiler happy.
                }
            }
            break;
            }
        }
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is verified
        public static string GetValueAsParameter(Guid value)
        {
            FramesetUtil.ValidateNonNullParameter("value", value);

            return(value.ToString());
        }
        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is verified
        public static string GetValueAsParameter(LearningStoreItemIdentifier value)
        {
            FramesetUtil.ValidateNonNullParameter("value", value);

            return(value.GetKey().ToString(NumberFormatInfo.InvariantInfo));
        }