コード例 #1
0
        /// <summary>
        ///     Do the codeRR collection pipeline.
        /// </summary>
        /// <param name="context">context</param>
        /// <param name="contextCollections">Extras</param>
        public static ErrorReportDTO ExecutePipeline(AspNetMvcContext context, params ContextCollectionDTO[] contextCollections)
        {
            if (
                context.HttpContext.Request.Url.AbsolutePath.IndexOf("/coderr/submit", StringComparison.OrdinalIgnoreCase) !=
                -1)
            {
                ProcessSubmit(context.HttpContext);
                context.HttpContext.Response.Redirect("~/");
                return(null);
            }
            if (context.HttpContext.Items.Contains("CoderrReported"))
            {
                return(null);
            }
            context.HttpContext.Items.Add("CoderrReported", "true");

            if (context.HttpApplication == null)
            {
                var module = context.Reporter as ErrorHttpModule;
                if (module?.Application != null)
                {
                    context.HttpApplication = module.Application;
                }
            }
            if (context.HttpApplication != null)
            {
                if (DisplayErrorPage)
                {
                    context.HttpApplication.Response.Clear();
                }
            }

            var httpCodeIdentifier = new HttpCodeIdentifier(context.HttpApplication, context.Exception);
            var report             = Err.GenerateReport(context);

            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 || !Err.Configuration.UserInteraction.AskUserForPermission)
            {
                Err.UploadReport(report);
                if (!DisplayErrorPage)
                {
                    return(report);
                }
            }
            else
            {
                TempData[report.ReportId] = report;
            }

            // Already rendered an error page.
            if (context.HttpContext.Items.Contains("OneTrueHandled"))
            {
                return(report);
            }

            context.HttpContext.Items["OneTrueHandled"] = true;
            var handler = new CustomControllerContext(context.Exception, report.ReportId)
            {
                HttpCode     = httpCodeIdentifier.HttpCode,
                HttpCodeName = httpCodeIdentifier.HttpCodeName
            };

            var ctx = new HttpErrorReporterContext(context.Reporter, context.Exception, context.HttpContext)
            {
                ErrorId            = report.ReportId,
                HttpStatusCode     = handler.HttpCode,
                HttpStatusCodeName = handler.HttpCodeName
            };

            context.HttpContext.Response.StatusCode        = handler.HttpCode;
            context.HttpContext.Response.StatusDescription = handler.HttpCodeName;
            handler.Execute(ctx);
            return(report);
        }
コード例 #2
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);
        }