コード例 #1
0
        private void OnError(object sender, EventArgs e)
        {
            var app = (HttpApplication)sender;

            if (!ConfigExtensions.CatchExceptions)
                return;

            var exception = app.Server.GetLastError();
            var httpCodeIdentifier = new HttpCodeIdentifier(app, exception);

            var context = new HttpErrorReporterContext(this, exception)
            {
                HttpContext = app.Context,
                HttpStatusCode = httpCodeIdentifier.HttpCode,
                HttpStatusCodeName = httpCodeIdentifier.HttpCodeName,
                ErrorMessage = ExtractFirstLine(exception.Message)
            };
            var dto = OneTrue.GenerateReport(context);

            var collection =
                dto.ContextCollections.FirstOrDefault(
                    x => x.Name.Equals("ExceptionProperties", StringComparison.OrdinalIgnoreCase));
            if (collection != null)
            {
                if (!collection.Properties.ContainsKey("HttpCode"))
                    collection.Properties.Add("HttpCode", context.HttpStatusCode.ToString());
            }

            if (OneTrue.Configuration.UserInteraction.AskUserForPermission)
                TempData[dto.ReportId] = dto;
            else
                OneTrue.UploadReport(dto);

            app.Response.StatusCode = context.HttpStatusCode;
            app.Response.StatusDescription = context.ErrorMessage;
            app.Response.TrySkipIisCustomErrors = true;
            app.Response.ContentEncoding = Encoding.UTF8;

            var pageContext = new PageGeneratorContext
            {
                Request = new HttpRequestWrapper(app.Request),
                Response = new HttpResponseWrapper(app.Response),
                ReporterContext = context,
                ReportId = dto.ReportId
            };

            ConfigExtensions.ErrorPageGenerator.Generate(pageContext);
            app.Server.ClearError();
            app.Response.End();
        }
コード例 #2
0
        private static void OnException(object sender, ThreadExceptionEventArgs e)
        {
            var context = new WinformsErrorReportContext(_instance, e.Exception);

            var dto = OneTrue.GenerateReport(context);

            if (!OneTrue.Configuration.UserInteraction.AskUserForPermission)
            {
                OneTrue.UploadReport(dto);
            }

            var ctx = new FormFactoryContext {
                Context = context, Report = dto
            };
            var dialog = FormFactory(ctx);

            dialog.ShowDialog();
        }
コード例 #3
0
        private static void OnException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            var context = new WpfErrorReportContext(Instance, e.Exception);

            var dto = OneTrue.GenerateReport(context);

            if (!OneTrue.Configuration.UserInteraction.AskUserForPermission)
            {
                ActionWrapper.SafeActionExecution(() => OneTrue.UploadReport(dto));
            }

            var ctx = new WindowFactoryContext {
                Context = context, Report = dto
            };
            var dialog = WindowFactory(ctx);

            dialog.ShowDialog();
        }
コード例 #4
0
        /// <summary>
        ///     Do the OneTrueError collection pipeline.
        /// </summary>
        /// <param name="source">Thingy that detected the exception</param>
        /// <param name="exception">Exception that was caught</param>
        /// <param name="httpContext">Context currently executing</param>
        /// <param name="contextCollections">Extras</param>
        public static void ExecutePipeline(object source, Exception exception, HttpContextBase httpContext,
                                           params ContextCollectionDTO[] contextCollections)
        {
            if (
                httpContext.Request.Url.AbsolutePath.IndexOf("/onetrueerror/submit", StringComparison.OrdinalIgnoreCase) !=
                -1)
            {
                ProcessSubmit(httpContext);
                httpContext.Response.Redirect("~/");
                return;
            }

            HttpApplication application = null;
            var             module      = source as ErrorHttpModule;

            if (module != null && module.Application != null)
            {
                application = module.Application;
                if (DisplayErrorPage)
                {
                    module.Application.Response.Clear();
                }
            }

            var httpCodeIdentifier = new HttpCodeIdentifier(application, exception);
            var reportingContext   = new AspNetContext(application ?? source, exception, httpContext);
            var report             = OneTrue.GenerateReport(reportingContext);

            if (contextCollections.Any())
            {
                var newList = new List <ContextCollectionDTO>(report.ContextCollections);
                newList.AddRange(contextCollections);
                report.ContextCollections = newList.ToArray();
            }

            // Add http code
            var exceptionCollection = report.ContextCollections.FirstOrDefault(x => x.Name == "ExceptionProperties");

            if (exceptionCollection != null)
            {
                if (!exceptionCollection.Properties.ContainsKey("HttpCode"))
                {
                    exceptionCollection.Properties["HttpCode"] = httpCodeIdentifier.HttpCode.ToString();
                }
            }

            if (!DisplayErrorPage || !OneTrue.Configuration.UserInteraction.AskUserForPermission)
            {
                OneTrue.UploadReport(report);
                if (!DisplayErrorPage)
                {
                    return;
                }
            }
            else
            {
                TempData[report.ReportId] = report;
            }

            var handler = new CustomControllerContext(exception, report.ReportId)
            {
                HttpCode     = httpCodeIdentifier.HttpCode,
                HttpCodeName = httpCodeIdentifier.HttpCodeName
            };

            var ctx = new HttpErrorReporterContext(source, exception, httpContext)
            {
                ErrorId            = report.ReportId,
                HttpStatusCode     = handler.HttpCode,
                HttpStatusCodeName = handler.HttpCodeName
            };

            httpContext.Response.StatusCode        = handler.HttpCode;
            httpContext.Response.StatusDescription = handler.HttpCodeName;
            handler.Execute(ctx);
        }
コード例 #5
0
        public static ErrorReportDTO GenerateReport(IErrorReporterContext context)
        {
            ErrorReportDTO dto = OneTrue.GenerateReport(context);

            return(dto);
        }
コード例 #6
0
        public static ErrorReportDTO GenerateReport(Exception exception)
        {
            ErrorReportDTO dto = OneTrue.GenerateReport(exception);

            return(dto);
        }