[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameters are validated protected void AppendContentFrameDetails(LearningSession session, StringBuilder sb) { FramesetUtil.ValidateNonNullParameter("sb", sb); FramesetUtil.ValidateNonNullParameter("session", session); // The URL for attempt-based content frames is: // http://<...basicWebApp>/Content.aspx/<AssignmentView>/<LearnerAssignmentId>/otherdata/ // the otherdata depends on the view sb.Append(String.Format(CultureInfo.InvariantCulture, "/{0}", Convert.ToInt32(AssignmentView, NumberFormatInfo.InvariantInfo))); StoredLearningSession slsSession = session as StoredLearningSession; if (slsSession == null) { // Not attempt-based view } else { sb.AppendFormat("/{0}", LearnerAssignmentGuidId.ToString()); // In review & ra views, append the current activity id if ((slsSession.View == SessionView.Review) || (slsSession.View == SessionView.RandomAccess)) { sb.AppendFormat("/{0}", FramesetUtil.GetStringInvariant(slsSession.CurrentActivityId)); } } }
public PlainTextString GetSessionTitle(LearningSession session) { FramesetUtil.ValidateNonNullParameter("session", session); LearnerAssignmentProperties la = GetLearnerAssignment(); switch (session.View) { case SessionView.Execute: return(new PlainTextString(la.Assignment.Title)); case SessionView.RandomAccess: return(new PlainTextString(ResHelper.Format("{0}: {1}", la.LearnerName, la.Assignment.Title))); case SessionView.Review: { if (IsInstructorReview) { return(new PlainTextString(ResHelper.Format("{0}: {1}", la.LearnerName, la.Assignment.Title))); } else { return(new PlainTextString(la.Assignment.Title)); } } default: return(new PlainTextString(la.Assignment.Title)); } }
/// <summary> /// Process the posted data before it is saved by the shared code. This allows checking the file attachments /// and making sure they meet the requirements of the SlkSettings. /// </summary> public bool ProcessPostedData(LearningSession session, HttpRequest request, Dictionary <string, HttpPostedFile> files) { // Save initial value of FinalPoints m_initialTotalPoints = session.TotalPoints; // Check the files for validity and fill in the output collection HttpFileCollection attachedFiles = Request.Files; int numFilesAttached = attachedFiles.Count; if (numFilesAttached > 0) { // Check if posted data meets requirements in SlkSettings. Additionally, check if there are files // that refer to files that do not exist (i.e. have 0 length). int maxKb = SlkStore.Settings.MaxAttachmentKilobytes; ICollection <string> attachmentTypes = SlkStore.Settings.ApprovedAttachmentTypes; List <string> invalidFileAttachments = new List <string>(numFilesAttached); List <string> invalidFileSize = new List <string>(numFilesAttached); List <string> filesDontExist = new List <string>(numFilesAttached); // Keep track of whether there is at least bool hasInvalidFileAttachment = false; bool hasInvalidFileSize = false; bool fileExists = true; // Go through posted files and test if they meet requirements foreach (string fileKey in attachedFiles) { HttpPostedFile file = attachedFiles[fileKey]; bool fileIsValid = true; // is this file a valid file attachment? string filename = file.FileName; // If the filename is empty, the file wasn't actually attached. if (!String.IsNullOrEmpty(filename)) { if (file.ContentLength == 0) { filesDontExist.Add(filename); fileExists = false; fileIsValid = false; } else if ((file.ContentLength / 1024) > maxKb) { invalidFileSize.Add(filename); hasInvalidFileSize = true; fileIsValid = false; } if (!attachmentTypes.Contains(Path.GetExtension(filename))) { invalidFileAttachments.Add(filename); hasInvalidFileAttachment = true; fileIsValid = false; } } // else: The file was valid on a previous posting, so consider it valid here if (fileIsValid) { // Add it to the returned list of valid files files.Add(fileKey, file); } } // if any of the posted files are invalid, then we need to write the message if (hasInvalidFileSize || hasInvalidFileAttachment || !fileExists) { StringBuilder message = new StringBuilder(1000); if (hasInvalidFileAttachment) { message.Append(ResHelper.GetMessage(SlkFrameset.CON_InvalidFileExtensionMsgHtml)); message.Append("<br><br><ul>"); foreach (string filename in invalidFileAttachments) { message.AppendFormat("<li>{0}</li>", SlkUtilities.GetHtmlEncodedText(filename)); } message.Append("</ul>"); } if (hasInvalidFileSize) { message.AppendFormat(ResHelper.GetMessage(SlkFrameset.CON_MaxFileSizeExceededMsgHtml, Convert.ToString(maxKb, CultureInfo.CurrentCulture.NumberFormat))); message.Append("<br><br><ul>"); foreach (string filename in invalidFileSize) { message.AppendFormat("<li>{0}</li>", SlkUtilities.GetHtmlEncodedText(filename)); } message.Append("</ul>"); } if (!fileExists) { message.AppendFormat(SlkFrameset.CON_FilesDontExistHtml); message.Append("<br><br><ul>"); foreach (string filename in filesDontExist) { message.AppendFormat("<li>{0}</li>", SlkUtilities.GetHtmlEncodedText(filename)); } message.Append("</ul>"); } // If one of the cases that relates to SLK settings is true, then tell user that there are settings // that affect the error if (hasInvalidFileSize || hasInvalidFileAttachment) { message.AppendFormat(CultureInfo.InvariantCulture, "{0}<br><br>", ResHelper.GetMessage(SlkFrameset.CON_InvalidFileAttachmentMsgHtml)); } message.Append(FramesetResources.CON_FileAttachmentErrorEndHtml); // Add information for the 'Continue' link JScriptString js = new JScriptString(ResHelper.FormatInvariant("API_GetFramesetManager().DoChoice(\"{0}\");", FramesetUtil.GetStringInvariant(session.CurrentActivityId))); message.AppendFormat(CultureInfo.InvariantCulture, "<br><br><a href='{0}' >{1}</a>", js.ToJavascriptProtocol(), HttpUtility.HtmlEncode(FramesetResources.HID_ReloadCurrentContent)); RegisterError(SlkFrameset.CON_InvalidFileAttachmentTitleHtml, message.ToString(), false); } } return(true); }
public void UpdateRenderContext(RenderContext context, StringBuilder scriptBlock, LearningSession session) { // Set values other than OutputStream and RelativePath context.EmbeddedUIResourcePath = new Uri(SlkEmbeddedUIPath, "Images/"); SetMimeTypeMapping(context.MimeTypeMapping); SetIisCompatibilityModeExtensions(context.IisCompatibilityModeExtensions); // If this is not the primary resource, nothing else matters. if (scriptBlock == null) { return; } LearnerAssignmentProperties la = GetLearnerAssignment(); switch (AssignmentView) { case AssignmentView.Execute: { context.ShowCorrectAnswers = false; context.ShowReviewerInformation = false; } break; case AssignmentView.StudentReview: { context.ShowCorrectAnswers = la.Assignment.ShowAnswersToLearners; context.ShowReviewerInformation = false; } break; case AssignmentView.InstructorReview: { context.ShowCorrectAnswers = true; context.ShowReviewerInformation = true; } break; case AssignmentView.Grading: { context.ShowCorrectAnswers = true; context.ShowReviewerInformation = true; } break; } // Update hidden controls and script to include assignment information if there is script // information to be written. Only write script in LRM content. if ((scriptBlock != null) && (session.CurrentActivityResourceType == ResourceType.Lrm)) { WriteSlkMgrInit(scriptBlock); scriptBlock.AppendLine("slkMgr = Slk_GetSlkManager();"); context.FormHiddenControls.Add(HiddenFieldNames.LearnerAssignmentId, FramesetUtil.GetStringInvariant(la.LearnerAssignmentId.GetKey())); scriptBlock.AppendFormat("slkMgr.LearnerAssignmentId = document.getElementById({0}).value;\r\n", JScriptString.QuoteString(HiddenFieldNames.LearnerAssignmentId, false)); context.FormHiddenControls.Add(HiddenFieldNames.LearnerAssignmentStatus, SlkUtilities.GetLearnerAssignmentState(la.Status)); scriptBlock.AppendFormat("slkMgr.Status = document.getElementById({0}).value;\r\n", JScriptString.QuoteString(HiddenFieldNames.LearnerAssignmentStatus, false)); // Set the change in final points. This can only happen in grading. if (AssignmentView == AssignmentView.Grading) { string finalPointsValue = "null"; float? finalPoints = la.FinalPoints; if (finalPoints != null) { // FinalPoints is invariant culture finalPointsValue = Convert.ToString(finalPoints.Value, CultureInfo.InvariantCulture.NumberFormat); } scriptBlock.AppendFormat("slkMgr.FinalPoints = {0};\r\n", finalPointsValue); } // Send information about total points (ie, computed points on the client). if (session != null) { if (session.TotalPoints != null) { // TotalPoints is passed in current culture, as a string JScriptString totalPointsValue = JScriptString.QuoteString(Convert.ToString(session.TotalPoints, CultureInfo.CurrentCulture.NumberFormat), false); scriptBlock.AppendFormat("slkMgr.ComputedPoints = {0};\r\n", totalPointsValue); } else { scriptBlock.Append("slkMgr.ComputedPoints = \"\";\r\n"); } if (session.SuccessStatus != SuccessStatus.Unknown) { scriptBlock.AppendFormat("slkMgr.PassFail = {0};\r\n", JScriptString.QuoteString(((session.SuccessStatus == SuccessStatus.Passed) ? "passed" : "failed"), false)); } } } }
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] // exceptions caught, added to event log protected void Page_Load(object sender, EventArgs e) { try { SlkUtilities.RetryOnDeadlock(delegate() { //Initialize data that may need to be reset on retry Response.Clear(); ClearError(); m_sessionEnded = false; m_hiddenHelper = new HiddenHelper(Request, Response, SlkEmbeddedUIPath); m_hiddenHelper.ProcessPageLoad(SlkStore.PackageStore, GetSessionTitle, TryGetSessionView, TryGetAttemptId, AppendContentFrameDetails, RegisterError, GetErrorInfo, ProcessSessionEnd, ProcessViewRequest, GetMessage, IsPostBack); // Send assignment information to client. If the session has ended, then force a reload of the current // assignment properties. Otherwise, the cached value will have required info so no need to re-query database. LearnerAssignmentProperties la = GetLearnerAssignment(SessionEnded); // Add assignment information to the hidden controls HiddenControlInfo hiddenCtrlInfo = new HiddenControlInfo(); hiddenCtrlInfo.Id = new PlainTextString(HiddenFieldNames.LearnerAssignmentId); hiddenCtrlInfo.Value = new PlainTextString(FramesetUtil.GetStringInvariant(la.LearnerAssignmentId.GetKey())); hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString(ResHelper.Format("slkMgr.LearnerAssignmentId = document.getElementById({0}).value;", JScriptString.QuoteString(HiddenFieldNames.LearnerAssignmentId, false))); m_hiddenHelper.HiddenControls.Add(hiddenCtrlInfo); // Learner assignment status ('not started', 'in progress', etc) hiddenCtrlInfo = new HiddenControlInfo(); hiddenCtrlInfo.Id = new PlainTextString(HiddenFieldNames.LearnerAssignmentStatus); hiddenCtrlInfo.Value = new PlainTextString(SlkUtilities.GetLearnerAssignmentState(la.Status)); hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString(ResHelper.Format("slkMgr.Status = document.getElementById({0}).value;", JScriptString.QuoteString(HiddenFieldNames.LearnerAssignmentStatus, false))); m_hiddenHelper.HiddenControls.Add(hiddenCtrlInfo); hiddenCtrlInfo = new HiddenControlInfo(); if (la.FinalPoints != null) { // finalPoints is passed in invariant culture, as a float hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString(ResHelper.Format("slkMgr.FinalPoints = {0};", Convert.ToString(la.FinalPoints, CultureInfo.InvariantCulture.NumberFormat))); } else { hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString("slkMgr.FinalPoints = null;"); } m_hiddenHelper.HiddenControls.Add(hiddenCtrlInfo); // Send information about total points (ie, computed points on the client). This is called 'graded score' in // grading page. LearningSession session = m_hiddenHelper.Session; if (session != null) { hiddenCtrlInfo = new HiddenControlInfo(); if (session.TotalPoints != null) { // TotalPoints is passed in current culture, as a string JScriptString totalPointsValue = JScriptString.QuoteString(Convert.ToString(session.TotalPoints, CultureInfo.CurrentCulture.NumberFormat), false); hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString(ResHelper.Format("slkMgr.ComputedPoints = {0};", totalPointsValue)); } else { hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString("slkMgr.ComputedPoints = \"\";"); } m_hiddenHelper.HiddenControls.Add(hiddenCtrlInfo); if (session.SuccessStatus != SuccessStatus.Unknown) { hiddenCtrlInfo = new HiddenControlInfo(); hiddenCtrlInfo.FrameManagerInitializationScript = new JScriptString(ResHelper.Format("slkMgr.PassFail = {0};\r\n", JScriptString.QuoteString(((session.SuccessStatus == SuccessStatus.Passed) ? "passed" : "failed"), false))); m_hiddenHelper.HiddenControls.Add(hiddenCtrlInfo); } } }); } catch (Exception ex) { ClearError(); // Unexpected exceptions are not shown to user SlkStore.LogError(FramesetResources.FRM_UnknownExceptionMsg, ex.ToString()); RegisterError(ResHelper.GetMessage(FramesetResources.FRM_UnknownExceptionTitle), ResHelper.GetMessage(SlkFrameset.FRM_UnexpectedExceptionMsg), false); } }
SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")] // parameter is validated public void ProcessSessionEnd(LearningSession session, ref string messageTitle, ref string message) { FramesetUtil.ValidateNonNullParameter("session", session); // If we have already been here, then there is nothing more to do. if (SessionEnded) { return; } LearnerAssignmentProperties la = GetLearnerAssignment(); // Session ending results in message shown to the user. if (session.View == SessionView.Execute) { StoredLearningSession slsSession = session as StoredLearningSession; if (slsSession != null) { // The rollup and/or sequencing process may have changed the state of the attempt. If so, there are some cases // that cannot continue so show an error message. switch (slsSession.AttemptStatus) { case AttemptStatus.Abandoned: messageTitle = SlkFrameset.HID_SessionAbandonedTitle; message = SlkFrameset.HID_ExecuteViewAbandonedSessionMsg; SessionEnded = true; break; case AttemptStatus.Completed: messageTitle = SlkFrameset.HID_SessionCompletedTitle; message = SlkFrameset.HID_ExecuteViewCompletedSessionMsg; SessionEnded = true; break; case AttemptStatus.Suspended: messageTitle = SlkFrameset.HID_SessionSuspendedTitle; message = SlkFrameset.HID_ExecuteViewSuspendedSessionMsg; // Do not set SessionEnded -- the session being suspended does not warrant ending the learner assignment break; } } if (SessionEnded) { // Call FinishLearnerAssignment since the attempt has already been completed. SlkStore.FinishLearnerAssignment(LearnerAssignmentGuidId); } } else if (session.View == SessionView.RandomAccess) { messageTitle = SlkFrameset.HID_GradingFinishedTitle; message = SlkFrameset.HID_GradingFinishedMessage; StringBuilder sb = new StringBuilder(1000); sb.Append(message); sb.Append("<br><script>"); // Write the assignment status to slkFrameMgr WriteSlkMgrInit(sb); sb.AppendLine("slkMgr = Slk_GetSlkManager();"); sb.AppendFormat("slkMgr.LearnerAssignmentId = {0};\r\n", JScriptString.QuoteString(FramesetUtil.GetStringInvariant(la.LearnerAssignmentId.GetKey()), false)); sb.AppendFormat("slkMgr.Status = {0};\r\n", JScriptString.QuoteString(SlkUtilities.GetLearnerAssignmentState(la.Status), false)); if (AssignmentView == AssignmentView.Grading) { string finalPointsValue = "null"; float? finalPoints = la.FinalPoints; if (finalPoints != null) { finalPointsValue = Convert.ToString(finalPoints.Value, CultureInfo.InvariantCulture.NumberFormat); } sb.AppendFormat("slkMgr.FinalPoints = {0};\r\n", finalPointsValue); } // Send information about total points (ie, computed points on the client). if (session != null) { if (session.TotalPoints != null) { sb.AppendFormat("slkMgr.ComputedPoints = {0};\r\n", JScriptString.QuoteString(Convert.ToString(session.TotalPoints, CultureInfo.CurrentCulture.NumberFormat), false)); } else { sb.AppendFormat("slkMgr.ComputedPoints = \"\";\r\n"); } if (session.SuccessStatus != SuccessStatus.Unknown) { sb.AppendFormat("slkMgr.PassFail = {0};\r\n", JScriptString.QuoteString(((session.SuccessStatus == SuccessStatus.Passed) ? "passed" : "failed"), false)); } } } }