예제 #1
0
        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();
            }
        }
        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);
            }
        }
예제 #3
0
        [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>Get the anonymous store.</summary>
        /// <param name="site">The site to get the settings for.</param>
        /// <returns></returns>
        public static AnonymousSlkStore GetStore(SPSite site)
        {
            Guid siteId = site.ID;
            // set <httpContext> to the current HttpContext (null if none)
            HttpContext httpContext = HttpContext.Current;

            // if an AnonymousSlkStore corresponding to <spSiteGuid> is cached, retrieve it, otherwise
            // create one
            string            cacheItemName = null;
            AnonymousSlkStore anonymousSlkStore;

            if (httpContext != null)
            {
                cacheItemName     = String.Format(CultureInfo.InvariantCulture, "SlkStore_{0}", siteId);
                anonymousSlkStore = (AnonymousSlkStore)httpContext.Cache.Get(cacheItemName);
                if (anonymousSlkStore != null)
                {
                    return(anonymousSlkStore);
                }
            }

            // set <mapping> to the SlkSPSiteMapping corresponding to <siteId>; if no such
            // mapping, exists, a SafeToDisplayException is thrown
            SlkSPSiteMapping mapping = SlkSPSiteMapping.GetRequiredMapping(site);

            // load "SlkSettings.xsd" from a resource into <xmlSchema>
            XmlSchema xmlSchema;

            using (StringReader schemaStringReader = new StringReader(SlkCulture.GetDefaultResources().SlkSettingsSchema))
            {
                xmlSchema = XmlSchema.Read(schemaStringReader,
                                           delegate(object sender2, ValidationEventArgs e2)
                {
                    // ignore warnings (already displayed when SLK Settings file was uploaded)
                });
            }

            SlkSettings settings = null;

            try
            {
                settings = LoadSettings(mapping, site, xmlSchema);
            }
            catch (SqlException)
            {
                // Try again in case temporary error
                try
                {
                    settings = LoadSettings(mapping, site, xmlSchema);
                }
                catch (SqlException e)
                {
                    SlkCulture culture = new SlkCulture(CultureInfo.InvariantCulture);
                    SlkStore.LogError(culture.Resources.SlkSettingsSqlErrorLoad + " {0}", culture, e);
                    throw new SafeToDisplayException(culture.Resources.SlkSettingsSqlErrorLoad);
                }
            }

            // create and (if possible) cache the new AnonymousSlkStore object
            anonymousSlkStore = new AnonymousSlkStore(siteId, mapping, settings);
            DateTime cacheExpirationTime = DateTime.Now.AddSeconds(HttpContextCacheTime);

            if (httpContext != null)
            {
                httpContext.Cache.Add(cacheItemName, anonymousSlkStore, null, cacheExpirationTime,
                                      System.Web.Caching.Cache.NoSlidingExpiration,
                                      System.Web.Caching.CacheItemPriority.Normal, null);
            }

            return(anonymousSlkStore);
        }
        [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);
            }
        }