Ejemplo n.º 1
0
        /// <summary>
        /// Process data returned from a form generated by an instance of this class. Also sets the data model's
        /// evaluation points field to the total points, computed from the autograding or teacher grading.
        /// </summary>
        /// <param name="context">
        /// The context within which to process the form data. </param>
        /// <param name="formData">The collection of information from the form that should be processed.</param>
        /// <param name="files">Collection of valid files, posted from the request. This may be a subset of the files
        /// included in the request, as some posted files may have been removed by the application as invalid.</param>
        /// <remarks>
        /// <p>Data that does not correspond to expected information is ignored.</p>
        /// </remarks>
        /// <exception cref="InvalidFormDataException">Thrown if posted data contains invalid data.</exception>
        public override void ProcessFormData(RloProcessFormDataContext context, NameValueCollection formData, IDictionary <string, HttpPostedFile> files)
        {
            // Do two passes here through all the interactions. This allows detecting any error in the posted data
            // before making changes to the data model based on posted data

            AssessmentItemManager.ProcessFormContext = context;

            LearningDataModel learningDataModel = context.LearningDataModel;

            // Validate the form data for all interactions. Any validation error throws InvalidFormDataException.
            foreach (Interaction interaction in learningDataModel.Interactions)
            {
                FormDataProcessor processor = m_assessmentItemMgr.GetFormDataProcessor(interaction);
                // must check that processor is non null, since GetFormDataProcessor() can return null
                if (processor != null)
                {
                    processor.ValidateFormData(formData, files); // throws exception if not valid
                }
            }
            // Process the form data.  This won't execute if ValidateFormData threw and exception, above.
            // Keep a running sum the Interaction.Evaluation.Points values to set the page's Points value.
            float?totalPoints = null;

            foreach (Interaction interaction in learningDataModel.Interactions)
            {
                FormDataProcessor processor = m_assessmentItemMgr.GetFormDataProcessor(interaction);
                // must check that processor is non null, since GetFormDataProcessor() can return null.
                // If it is null, any item score associated with this interaction is not totalled into
                // EvaluationPoints.
                if (processor != null)
                {
                    processor.ProcessFormData(formData, files);
                    if (interaction.Evaluation.Points.HasValue)
                    {
                        if (totalPoints.HasValue)
                        {
                            totalPoints += interaction.Evaluation.Points.Value;
                        }
                        else
                        {
                            totalPoints = interaction.Evaluation.Points.Value;
                        }
                    }
                }
            }
            learningDataModel.EvaluationPoints = totalPoints;

            if (context.View == SessionView.Execute)
            {
                SetPageHasBeenAutograded(learningDataModel);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the processor that can process posted data related to the specified interaction, or <c>null</c> if none.
 /// </summary>
 /// <remarks>ProcessFormContext must have been set prior to calling this method.  If this
 /// interaction's InteractionType does not have a value (such as when it represents a rubric or item score
 /// with no associated assessment) this method returns <c>null</c>.
 /// </remarks>
 internal FormDataProcessor GetFormDataProcessor(Interaction interaction)
 {
     if (interaction.InteractionType.HasValue)
     {
         FormDataProcessor processor = m_formProcessors[interaction.InteractionType.Value];
         processor.Interaction = interaction;
         return(processor);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Requests the RloHandler to do whatever is required to exit from the current activity.
        /// This request may only be issued when the session is in Execute view and is not active -- it is
        /// either Completed or Abandoned.
        /// </summary>
        /// <param name="context">The context within which the command is processed</param>
        /// <remarks>
        /// This method should only be called for the <c>SessionView.Execute</c> view.  However,
        /// no checks are done internally to verify this - if this is called with other views,
        /// unexpected results will occur.
        /// </remarks>
        public override void ProcessSessionEnd(RloDataModelContext context)
        {
            LearningDataModel learningDataModel = context.LearningDataModel;

            // Set ExitMode to suspend so that when a student exits the activity it is left in a suspended state.
            // This way if the activity is reactivated, the student's previous answers are intact.
            learningDataModel.NavigationRequest.ExitMode = ExitMode.Suspended;
            // If the page has never been visited, "visit" it.
            if (!GetPageHasBeenVisited(learningDataModel))
            {
                AssessmentItemManager.DataModelContext = context;
                // Get the input stream containing the primary file from the resource associated with the
                // current activity in the session.
                using (Stream inputStream = context.GetInputStream())
                {
                    // find all the assessment items (<IMG> tags that contain the text "mslamrk" as part of the src attribute.)
                    using (HtmlTextReader reader = new HtmlTextReader(inputStream))
                    {
                        int srcIndex;
                        while (reader.Read())
                        {
                            if (IsAITag(reader, out srcIndex))
                            {
                                try
                                {
                                    AssessmentItem         ai       = AssessmentItem.Parse(reader.GetAttributeValue(srcIndex));
                                    AssessmentItemRenderer renderer = AssessmentItemManager.GetRenderer(ai);
                                    renderer.TryAddToDataModel();
                                }
                                catch (FormatException)
                                {
                                    // skip this one.
                                }
                            }
                        }
                    }
                }
                SetPageHasBeenVisited(learningDataModel);
            }
            // If the page has never been autograded, call ProcessSessionEnd on the form data processors
            if (!GetPageHasBeenAutograded(learningDataModel))
            {
                AssessmentItemManager.ProcessFormContext = new RloProcessFormDataContext(SessionView.Execute, learningDataModel);
                float?totalPoints = null;
                foreach (Interaction interaction in learningDataModel.Interactions)
                {
                    FormDataProcessor processor = m_assessmentItemMgr.GetFormDataProcessor(interaction);
                    // must check that processor is non null, since GetFormDataProcessor() can return null.
                    // If it is null, any item score associated with this interaction is not totalled into
                    // EvaluationPoints.
                    if (processor != null)
                    {
                        processor.ProcessSessionEnd(context);
                        if (interaction.Evaluation.Points.HasValue)
                        {
                            if (totalPoints.HasValue)
                            {
                                totalPoints += interaction.Evaluation.Points;
                            }
                            else
                            {
                                totalPoints = interaction.Evaluation.Points;
                            }
                        }
                    }
                }
                learningDataModel.EvaluationPoints = totalPoints;
                SetPageHasBeenAutograded(learningDataModel);
            }
        }