Exemplo n.º 1
0
        [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] // large switch statement
        public override void SetValue(PlainTextString inName, PlainTextString inValue)
        {
            // It's not valid to call in Review mode
            if (this.View == SessionView.Review)
            {
                throw new InvalidOperationException(
                    ResHelper.GetMessage(Localization.GetMessage("CONV_InvalidViewOnSetValue")));
            }

            if (this.ObjectiveIndexer == null)
            {
                throw new InvalidOperationException(
                    ResHelper.GetMessage(Localization.GetMessage("CONV_MappingRequired")));
            }

            this.CurrentElementName = inName.ToString();
            string[] nameParts = this.CurrentElementName.Split('.');

            string value = inValue.ToString();

            if (nameParts[0] == "cmi")
            {
                if (nameParts.Length < 2)
                {
                    throw new InvalidOperationException(
                        ResHelper.GetMessage(
                            Localization.GetMessage("CONV_SetValueInvalidName"),
                            this.CurrentElementName));
                }

                switch (nameParts[1])
                {
                    case "comments_from_learner":
                        {
                            this.VerifyElementNameTokens(4, nameParts);
                            this.SetCommentsFromLearner(nameParts[2], nameParts[3], value);
                        }
                        break;
                    case "completion_status":
                        {
                            this.SetCompletionStatus(value);
                        }
                        break;
                    case "exit":
                        {
                            this.SetExit(value);
                        }
                        break;
                    case "interactions":
                        {
                            this.SetInteractions(this.CurrentElementName.Substring(17), value);
                        }
                        break;
                    case "learner_preference":
                        {
                            this.VerifyElementNameTokens(3, nameParts);
                            this.SetLearnerPreferences(nameParts[2], value);
                        }
                        break;
                    case "location":
                        {
                            this.DataModel.Location = value;
                        }
                        break;
                    case "objectives":
                        {
                            this.SetObjectives(this.CurrentElementName.Substring(15), value);
                        }
                        break;
                    case "progress_measure":
                        {
                            this.SetProgressMeasure(value);
                        }
                        break;
                    case "score":
                        {
                            this.VerifyElementNameTokens(3, nameParts);
                            this.SetScore(nameParts[2], value);
                        }
                        break;
                    case "session_time":
                        {
                            this.SetSessionTime(value);
                        }
                        break;
                    case "success_status":
                        {
                            this.SetSuccessStatus(value);
                        }
                        break;
                    case "suspend_data":
                        {
                            this.SetSuspendData(value);
                        }
                        break;

                    default:
                        // All other values are read-only. This will throw exception.
                        this.SetReadOnlyValue();
                        break;
                }
            }
            else if (nameParts[0] == "adl")
            {
                if (nameParts.Length < 3)
                {
                    throw new InvalidOperationException(
                        ResHelper.GetMessage(
                            Localization.GetMessage("CONV_SetValueInvalidName"),
                            this.CurrentElementName));
                }

                if (nameParts[1] != "nav")
                {
                    throw new InvalidOperationException(
                        ResHelper.GetMessage(
                            Localization.GetMessage("CONV_SetValueInvalidName"),
                            this.CurrentElementName));
                }

                switch (nameParts[2])
                {
                    case "request":
                        {
                            this.SetNavRequest(value);
                        }
                        break;
                    default:
                        throw new InvalidOperationException(
                            ResHelper.GetMessage(
                                Localization.GetMessage("CONV_SetValueInvalidName"),
                                this.CurrentElementName));
                }
            }
            else
            {
                this.DataModel.ExtensionData[this.CurrentElementName] = value;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The entry point for SetValue functions. Pass in the name (in SCORM terms) of the data model element
        /// and this method sets the appropriate value in the LearningDataModel class.
        /// </summary>
        /// <param name="inName">SCORM data model element name (e.g., "cmi.exit"). </param>
        /// <param name="inValue">The value of the element in SCORM terms (e.g., "logout").</param>
        /// <remarks>Note: InteractionIndexer and ObjectiveIndexer must be set prior to calling this method.
        /// <para>It is not valid to call SetValue in Review view.</para>
        /// <p/>This method is relatively lax about throwing exceptions for invalid names. It assumes the caller 
        /// is passing in valid information.
        /// </remarks>
        public override void SetValue(PlainTextString inName, PlainTextString inValue)
        {
            // It's not valid to call in Review mode
            if (View == SessionView.Review)
                throw new InvalidOperationException(ResHelper.GetMessage(IUDICO.TestingSystem.Localization.getMessage("CONV_InvalidViewOnSetValue")));

            CurrentElementName = inName.ToString();
            string[] nameParts = CurrentElementName.Split('.');

            string value = inValue.ToString();

            if (nameParts[0] == "cmi")
            {
                if (nameParts.Length < 2)
                    throw new InvalidOperationException(ResHelper.GetMessage(IUDICO.TestingSystem.Localization.getMessage("CONV_SetValueInvalidName"), CurrentElementName));

                switch (nameParts[1])
                {
                    case "core":
                        {
                            SetCoreValues(nameParts, value);
                            break;
                        }

                    case "suspend_data":
                        {
                            DataModel.SuspendData = value;
                            break;
                        }
                    case "comments":
                        {
                            SetCommentsFromLearner(value);
                            break;
                        }
                    case "objectives":
                        {
                            VerifyElementNameTokens(4, nameParts);
                            SetObjectives(CurrentElementName.Substring(15) ,value);
                            break;
                        }
                    case "student_preference":
                        {
                            VerifyElementNameTokens(3, nameParts);
                            SetLearnerPreferences(nameParts[2], value);
                            break;
                        }
                    case "interactions":
                        {
                            SetInteractions(CurrentElementName.Substring(17), value);
                            break;
                        }

                    default:
                        // All other values are read-only (or invalid names). This will throw exception.
                        SetReadOnlyValue();
                        break;
                }

            }
            else
            {
                DataModel.ExtensionData[CurrentElementName] = value;
            }
        }