Implements an exception that provides help about the error that occurred.
Inheritance: SageException
示例#1
0
        /// <summary>
        /// Handles the BeginRequest event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected virtual void Application_BeginRequest(object sender, EventArgs e)
        {
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = Project.GenerateThreadId();
                log.InfoFormat("Thread name set to {0}", Thread.CurrentThread.Name);
            }

            if (initializationError != null)
            {
                StringBuilder html = new StringBuilder();
                using (TextWriter writer = new StringWriter(html))
                {
                    SageHelpException helpException = new SageHelpException(initializationProblemInfo, initializationError);
                    helpException.Render(writer, new SageContext(this.Context));
                }

                this.Response.Write(html.ToString());
                this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                this.Response.Cache.SetNoStore();
                this.Response.End();
            }

            var context = new SageContext(this.Context);
            if (context.LmCache.Get(ConfigWatchName) == null)
                Project.InitializeConfiguration(context);

            if (!Project.IsStarted)
            {
                lock (lck)
                {
                    if (!Project.IsStarted)
                    {
                        Project.Start(context);
                    }
                }
            }

            if (this.Context != null)
                log.InfoFormat("Request {0} started.", HttpContext.Current.Request.Url);
            else
                log.InfoFormat("Request started (no context)");
        }
示例#2
0
        internal static SageHelpException Create(Exception ex, string path = null, ProblemType suggestedProblem = ProblemType.Unknown)
        {
            ProblemInfo problem = new ProblemInfo(ProblemType.Unknown);
            if (ex is XmlException)
            {
                if (ex.Message.Contains("undeclared prefix"))
                    problem = new ProblemInfo(ProblemType.MissingNamespaceDeclaration, path);

                else if (path != null && (path.EndsWith("html") || path.EndsWith("htm")))
                    problem = new ProblemInfo(ProblemType.InvalidHtmlMarkup, path);

                else
                    problem = new ProblemInfo(ProblemType.InvalidMarkup, path);
            }
            else
            {
                var typeName = ex.GetType().Name;
                if (parsers.ContainsKey(typeName))
                    problem = parsers[typeName].Invoke(ex);
            }

            if (problem.Type == ProblemType.Unknown && suggestedProblem != ProblemType.Unknown)
                problem.Type = suggestedProblem;

            var result = new SageHelpException(problem) { Exception = ex };
            return result;
        }