/// <summary>Gets the activity information.</summary> /// <param name="showErrorPage">Whether to show the error page if the activity id is not valid.</param> /// <param name="activityId">The activity to output.</param> /// <returns>True if the activity details are retrieved.</returns> public bool TryGetActivityInfo(bool showErrorPage, out long activityId) { // This will only be called in Review & RandomAccess views, in which case, m_contentPathParts is... // m_contentPathParts[1] = assignment view, m_contentPathParts[2] = learnerAssignmentId, m_contentPathParts[3] = activityId to display, m_contentPathParts[4] and beyond is resource path // activity id must be provided activityId = -1; bool isValid = false; if (m_contentPathParts.Length >= 4) { string strActivityId = m_contentPathParts[3]; if (long.TryParse(strActivityId, out activityId)) { if (activityId > 0) { isValid = true; } } } if (!isValid) { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.CON_ContentCannotBeDisplayedTitle), ResHelper.GetMessage(FramesetResources.CON_ContentCannotBeDisplayedMsg), false); } return(false); } return(true); }
protected void Page_Load(object sender, EventArgs e) { try { SlkUtilities.RetryOnDeadlock(delegate() { m_helper = new ChangeActivityHelper(Request, Response); m_helper.ProcessPageLoad(TryGetSessionView, TryGetAttemptId, TryGetActivityId, RegisterError, GetErrorInfo, GetMessage); m_pageLoadSuccessful = (!HasError); }); } catch (Exception e2) { // Unexpected exceptions are not shown to user SlkStore.LogError(FramesetResources.FRM_UnknownExceptionMsg, e2.ToString()); RegisterError(ResHelper.GetMessage(FramesetResources.FRM_UnknownExceptionTitle), ResHelper.GetMessage(SlkFrameset.FRM_UnexpectedExceptionMsg), false); m_pageLoadSuccessful = false; // Clear the response in case something has been written Response.Clear(); } }
/// <summary> /// Gets the attempt id required to render the page. Uses the FramesetQueryParameter.LearnerAssignmentId /// to determine attempt information. /// </summary> /// <param name="showErrorPage">Whether to show the error page or not.</param> /// <param name="learnerAssignmentGuidId">The id of the learner assignment.</param> /// <returns></returns> protected bool TryProcessLearnerAssignmentIdParameter(bool showErrorPage, out Guid learnerAssignmentGuidId) { // Initialize out parameter learnerAssignmentGuidId = Guid.Empty; string learnerAssignmentParam; if (!TryGetRequiredParameter(FramesetQueryParameter.LearnerAssignmentId, out learnerAssignmentParam)) { return(false); } bool isValid = true; // Assume return value is valid // Try converting it to a guid value. try { Guid learnerAssignmentKey = new Guid(learnerAssignmentParam); learnerAssignmentGuidId = learnerAssignmentKey; } catch (FormatException) { isValid = false; } if (!isValid && showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.LearnerAssignmentId), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.LearnerAssignmentId, learnerAssignmentParam), false); } return(isValid); }
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] // need to catch it to provide correct SLK message public bool TryGetViewInfo(bool showErrorPage, out SessionView view) { // make compiler happy view = SessionView.Execute; AssignmentView assignmentView; // Get the parts of the content path (parameter PF) value // pfParts[0] = "", pfParts[1] = assignment view, pfParts[2] = extra view data, everything else is path or extra data for attempt views m_contentPathParts = m_contentPath.Split(new char[] { '/' }); // First section is assignment view -- it must exist in all cases. string strAssignmentView = m_contentPathParts[1]; if (String.IsNullOrEmpty(strAssignmentView)) { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_ParameterRequiredTitle, FramesetQueryParameter.SlkView), ResHelper.GetMessage(FramesetResources.FRM_ParameterRequiredMsg, FramesetQueryParameter.SlkView), false); } return(false); } try { assignmentView = (AssignmentView)Enum.Parse(typeof(AssignmentView), strAssignmentView, true); if ((assignmentView < AssignmentView.Execute) || (assignmentView > AssignmentView.Grading)) { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.SlkView), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.SlkView, strAssignmentView), false); } return(false); } } catch { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.SlkView), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.SlkView, strAssignmentView), false); } return(false); } view = GetSessionView(assignmentView); m_sessionView = view; AssignmentView = assignmentView; return(true); }
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] // catch general exception so that message can be SLK-specific public bool TryGetAttemptInfo(bool showErrorPage, out AttemptItemIdentifier attemptId) { // Initialize out parameter attemptId = null; Guid learnerAssignmentKey; bool isValid = false; // For views based on an attempt, LearnerAssignmentId is required // It must be a positive long value. if (m_contentPathParts.Length >= 3) { learnerAssignmentKey = new Guid(m_contentPathParts[2]); if (learnerAssignmentKey != null) { LearnerAssignmentGuidId = learnerAssignmentKey; } } try { learnerAssignment = GetLearnerAssignment(); attemptId = learnerAssignment.AttemptId; isValid = true; } catch (HttpException) { // If something just happened with the connection, don't set header info } catch { // If we could not get the assignment, send the proper error codes Response.StatusCode = 404; Response.StatusDescription = "Not Found"; } if (!isValid) { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.CON_ContentCannotBeDisplayedTitle), ResHelper.GetMessage(FramesetResources.CON_ContentCannotBeDisplayedMsg), false); } return(false); } return(true); }
/// <summary>Tries to get the attempt id.</summary> public override bool TryGetAttemptId(bool showErrorPage, out AttemptItemIdentifier attemptId) { string attemptIdParam = null; bool isValid = true; // make compiler happy attemptId = null; if (!TryGetRequiredParameter(FramesetQueryParameter.AttemptId, out attemptIdParam)) { return(false); } // Try converting it to a long value. It must be positive. try { long attemptIdKey = long.Parse(attemptIdParam, NumberFormatInfo.InvariantInfo); if (attemptIdKey <= 0) { isValid = false; } else { attemptId = new AttemptItemIdentifier(attemptIdKey); } } catch (FormatException) { isValid = false; } if (!isValid && showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.AttemptId), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.AttemptId, attemptIdParam), false); } return(isValid); }
/// <summary>Trys to get the activity id.</summary> /// <param name="showErrorPage">Whether to show the error page on an error.</param> /// <param name="activityId">The activity id retrieved.</param> /// <returns>True if the id is found.</returns> public bool TryGetActivityId(bool showErrorPage, out long activityId) { string activityIdParam = null; bool isValid = true; activityId = -1; if (!TryGetRequiredParameter(FramesetQueryParameter.ActivityId, out activityIdParam)) { return(false); } // Try converting it to a long value. It must be positive. try { long activityIdKey = long.Parse(activityIdParam, NumberFormatInfo.InvariantInfo); if (activityIdKey <= 0) { isValid = false; } else { activityId = activityIdKey; } } catch (FormatException) { isValid = false; } if (!isValid && showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.ActivityId), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.ActivityId, activityIdParam), false); } return(isValid); }
/// <summary>Retrieves the session view.</summary> public override bool TryGetSessionView(bool showErrorPage, out SessionView view) { string viewParam; // Default value to make compiler happy view = SessionView.Execute; if (!TryGetRequiredParameter(FramesetQueryParameter.View, out viewParam)) { return(false); } try { // Get the view enum value view = (SessionView)Enum.Parse(typeof(SessionView), viewParam, true); if ((view < SessionView.Execute) || (view > SessionView.Review)) { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.View), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.View, viewParam), false); } return(false); } } catch (ArgumentException) { if (showErrorPage) { RegisterError(ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterTitle, FramesetQueryParameter.View), ResHelper.GetMessage(FramesetResources.FRM_InvalidParameterMsg, FramesetQueryParameter.View, viewParam), false); } return(false); } return(true); }
protected void Page_Load(object sender, EventArgs e) { try { SlkUtilities.RetryOnDeadlock(delegate() { // Clear data that may need to be reset on retry Response.Clear(); ClearError(); m_tocHelper = new TocHelper(); string submitText = ""; SessionView view; if (TryGetSessionView(false, out view)) { if (view == SessionView.Execute) { submitText = SlkFrameset.TOC_SubmitAssignment; } else { submitText = SlkFrameset.TOC_SubmitGrading; } } m_tocHelper.ProcessPageLoad(Response, SlkStore.PackageStore, TryGetSessionView, TryGetAttemptId, ProcessViewRequest, RegisterError, submitText); }); } catch (Exception ex) { // 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", "CA1031:DoNotCatchGeneralExceptionTypes")] // all exceptions caught and written to event log rather than getting aspx error page protected void Page_Load(object sender, EventArgs e) { try { bool isPosted = false; if (String.CompareOrdinal(Request.HttpMethod, "POST") == 0) { isPosted = true; } // Get the path to the content. This may be part of the url (if we are running without // an http module) or a URL parameter (with http module). We run in both modes because // VS.NET does not parse URLs of the form: /.../Content.aspx/0/1/foo.gif correctly without // the assistance of the module. m_contentPath = GetContentPath(); SPSecurity.CatchAccessDeniedException = true; SlkUtilities.RetryOnDeadlock(delegate() { // Initialize data that may get set on a first try, but must be reset for retry Response.Clear(); ClearError(); learnerAssignment = null; m_contentHelper = new ContentHelper(Request, Response, SlkEmbeddedUIPath); m_contentHelper.ProcessPageLoad(SlkStore.PackageStore, String.IsNullOrEmpty(m_contentPath), isPosted, TryGetViewInfo, TryGetAttemptInfo, TryGetActivityInfo, GetResourcePath, AppendContentFrameDetails, UpdateRenderContext, ProcessPostedData, ProcessViewRequest, ProcessPostedDataComplete, RegisterError, GetErrorInfo, GetMessage); }); } catch (ThreadAbortException) { // response ended. Do nothing. return; } catch (UnauthorizedAccessException uae) { SlkStore.LogError(FramesetResources.FRM_UnknownExceptionMsg, uae.ToString()); RegisterError(ResHelper.GetMessage(FramesetResources.FRM_UnknownExceptionTitle), ResHelper.GetMessage(SlkFrameset.FRM_UnexpectedExceptionMsg), false); // Clear the response in case something has been written Response.Clear(); } catch (Exception e2) { // Unexpected exceptions are not shown to user SlkStore.LogError(FramesetResources.FRM_UnknownExceptionMsg, e2.ToString()); RegisterError(ResHelper.GetMessage(FramesetResources.FRM_UnknownExceptionTitle), ResHelper.GetMessage(SlkFrameset.FRM_UnexpectedExceptionMsg), false); // Clear the response in case something has been written Response.Clear(); } }
/// <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); }
[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); } }