From 1a708b8479d1e8ef4ce09ee0a9ff464467f95fb2 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 3 Sep 2015 09:34:19 -0700 Subject: [PATCH] Fixed razor view as its compilation fails due to changed apis Updated PageGenerator to consider the modified Views folder paths More restructuring of files --- DiagnosticsPages.sln | 4 +- ...ple.xproj => ExceptionHandlerSample.xproj} | 0 samples/ErrorHandlerSample/Startup.cs | 4 +- ...roj => DeveloperExceptionPageSample.xproj} | 0 samples/ErrorPageSample/Startup.cs | 8 +- src/Microsoft.AspNet.Diagnostics/Constants.cs | 11 --- .../DeveloperExceptionPageExtensions.cs | 42 +++++------ ...ns.cs => DeveloperExceptionPageOptions.cs} | 29 ++++++++ .../Views/CompilationErrorModel.cs | 0 .../Views/CompilationErrorPage.cs | 0 .../Views/CompilationErrorPage.cshtml | 0 .../Views/ErrorDetails.cs | 0 .../Views/ErrorPage.cs | 0 .../Views/ErrorPage.cshtml | 0 .../Views/ErrorPage.css | 0 .../Views/ErrorPage.js | 0 .../Views/ErrorPageModel.cs | 0 .../Views/StackFrame.cs | 0 .../DiagnosticsPage.cs | 8 +- .../DiagnosticsPage.cshtml | 2 +- .../ExceptionHandlerExtensions.cs | 74 +++++++++---------- .../ExceptionHandlerMiddleware.cs | 18 ++--- ...rOptions.cs => ExceptionHandlerOptions.cs} | 6 +- .../Views/RuntimeInfoPage.cs | 0 .../Views/RuntimeInfoPage.cshtml | 0 .../Views/RuntimeInfoPage.css | 0 .../Views/RuntimeInfoPageModel.cs | 0 .../{ => WelcomePage}/Views/WelcomePage.cs | 0 .../Views/WelcomePage.cshtml | 0 src/Microsoft.AspNet.Diagnostics/project.json | 2 +- src/PageGenerator/Program.cs | 43 +++++------ ...> DeveloperExceptionPageMiddlewareTest.cs} | 4 +- ...HandlerTest.cs => ExceptionHandlerTest.cs} | 4 +- 33 files changed, 138 insertions(+), 121 deletions(-) rename samples/ErrorHandlerSample/{ErrorHandlerSample.xproj => ExceptionHandlerSample.xproj} (100%) rename samples/ErrorPageSample/{ErrorPageSample.xproj => DeveloperExceptionPageSample.xproj} (100%) delete mode 100644 src/Microsoft.AspNet.Diagnostics/Constants.cs rename src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/{ErrorPageOptions.cs => DeveloperExceptionPageOptions.cs} (54%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/CompilationErrorModel.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/CompilationErrorPage.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/CompilationErrorPage.cshtml (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/ErrorDetails.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/ErrorPage.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/ErrorPage.cshtml (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/ErrorPage.css (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/ErrorPage.js (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/ErrorPageModel.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => DeveloperExceptionPage}/Views/StackFrame.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{Views => DiagnosticsPage}/DiagnosticsPage.cs (80%) rename src/Microsoft.AspNet.Diagnostics/{Views => DiagnosticsPage}/DiagnosticsPage.cshtml (94%) rename src/Microsoft.AspNet.Diagnostics/ExceptionHandler/{ErrorHandlerOptions.cs => ExceptionHandlerOptions.cs} (63%) rename src/Microsoft.AspNet.Diagnostics/{ => RuntimeInfo}/Views/RuntimeInfoPage.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => RuntimeInfo}/Views/RuntimeInfoPage.cshtml (100%) rename src/Microsoft.AspNet.Diagnostics/{ => RuntimeInfo}/Views/RuntimeInfoPage.css (100%) rename src/Microsoft.AspNet.Diagnostics/{ => RuntimeInfo}/Views/RuntimeInfoPageModel.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => WelcomePage}/Views/WelcomePage.cs (100%) rename src/Microsoft.AspNet.Diagnostics/{ => WelcomePage}/Views/WelcomePage.cshtml (100%) rename test/Microsoft.AspNet.Diagnostics.Tests/{ErrorPageMiddlewareTest.cs => DeveloperExceptionPageMiddlewareTest.cs} (98%) rename test/Microsoft.AspNet.Diagnostics.Tests/{ErrorHandlerTest.cs => ExceptionHandlerTest.cs} (99%) diff --git a/DiagnosticsPages.sln b/DiagnosticsPages.sln index 05042e2643..ee44b38077 100644 --- a/DiagnosticsPages.sln +++ b/DiagnosticsPages.sln @@ -11,7 +11,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WelcomePageSample", "sample EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Diagnostics", "src\Microsoft.AspNet.Diagnostics\Microsoft.AspNet.Diagnostics.xproj", "{68A1F0E1-ECCE-46D1-B20F-C43EE5B097DE}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ErrorPageSample", "samples\ErrorPageSample\ErrorPageSample.xproj", "{589AC17F-9455-4764-8F82-FCD2AE58DA14}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "DeveloperExceptionPageSample", "samples\ErrorPageSample\DeveloperExceptionPageSample.xproj", "{589AC17F-9455-4764-8F82-FCD2AE58DA14}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PageGenerator", "src\PageGenerator\PageGenerator.xproj", "{4D4A785A-ECB9-4916-A88F-0FD306EE3B74}" EndProject @@ -26,7 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2AF90579-B EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Diagnostics.Tests", "test\Microsoft.AspNet.Diagnostics.Tests\Microsoft.AspNet.Diagnostics.Tests.xproj", "{994351B4-7B2A-4139-8B72-72C5BB5CC618}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ErrorHandlerSample", "samples\ErrorHandlerSample\ErrorHandlerSample.xproj", "{427CDB36-78B0-4583-9EBC-7F283DE60355}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ExceptionHandlerSample", "samples\ErrorHandlerSample\ExceptionHandlerSample.xproj", "{427CDB36-78B0-4583-9EBC-7F283DE60355}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Diagnostics.Entity", "src\Microsoft.AspNet.Diagnostics.Entity\Microsoft.AspNet.Diagnostics.Entity.xproj", "{4F5A6A72-FFE4-49C4-B4C6-58132CFCB9FE}" EndProject diff --git a/samples/ErrorHandlerSample/ErrorHandlerSample.xproj b/samples/ErrorHandlerSample/ExceptionHandlerSample.xproj similarity index 100% rename from samples/ErrorHandlerSample/ErrorHandlerSample.xproj rename to samples/ErrorHandlerSample/ExceptionHandlerSample.xproj diff --git a/samples/ErrorHandlerSample/Startup.cs b/samples/ErrorHandlerSample/Startup.cs index 04116029aa..9e162834a3 100644 --- a/samples/ErrorHandlerSample/Startup.cs +++ b/samples/ErrorHandlerSample/Startup.cs @@ -5,7 +5,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.Framework.WebEncoders; -namespace ErrorHandlerSample +namespace ExceptionHandlerSample { public class Startup { @@ -35,7 +35,7 @@ namespace ErrorHandlerSample }); // We could also configure it to re-execute the request on the normal pipeline with a different path. - // app.UseErrorHandler("/error.html"); + // app.UseExceptionHandler("/error.html"); // The broken section of our application. app.Map("/throw", throwApp => diff --git a/samples/ErrorPageSample/ErrorPageSample.xproj b/samples/ErrorPageSample/DeveloperExceptionPageSample.xproj similarity index 100% rename from samples/ErrorPageSample/ErrorPageSample.xproj rename to samples/ErrorPageSample/DeveloperExceptionPageSample.xproj diff --git a/samples/ErrorPageSample/Startup.cs b/samples/ErrorPageSample/Startup.cs index 0352d8856b..7b4c399981 100644 --- a/samples/ErrorPageSample/Startup.cs +++ b/samples/ErrorPageSample/Startup.cs @@ -1,7 +1,7 @@ using System; using Microsoft.AspNet.Builder; -namespace ErrorPageSample +namespace DeveloperExceptionPageSample { public class Startup { @@ -11,9 +11,9 @@ namespace ErrorPageSample app.Run(context => { throw new Exception(string.Concat( - "Demonstration exception. The list:", "\r\n", - "New Line 1", "\n", - "New Line 2", Environment.NewLine, + "Demonstration exception. The list:", "\r\n", + "New Line 1", "\n", + "New Line 2", Environment.NewLine, "New Line 3")); }); } diff --git a/src/Microsoft.AspNet.Diagnostics/Constants.cs b/src/Microsoft.AspNet.Diagnostics/Constants.cs deleted file mode 100644 index ee43d000fe..0000000000 --- a/src/Microsoft.AspNet.Diagnostics/Constants.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNet.Diagnostics -{ - internal static class Constants - { - internal const string HostAppMode = "host.AppMode"; - internal const string DevMode = "development"; - } -} diff --git a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs index ca91244237..912ebb1f17 100644 --- a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs +++ b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs @@ -11,28 +11,28 @@ namespace Microsoft.AspNet.Builder /// public static class ErrorPageExtensions { - ///// - ///// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. - ///// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties. - ///// - ///// - ///// - //public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder) - //{ - // return builder.UseErrorPage(new ErrorPageOptions()); - //} + /// + /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. + /// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties. + /// + /// + /// + public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder) + { + return builder.UseErrorPage(new ErrorPageOptions()); + } - ///// - ///// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. - ///// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties. - ///// - ///// - ///// - ///// - //public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder, ErrorPageOptions options) - //{ - // return builder.UseMiddleware(options); - //} + /// + /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. + /// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties. + /// + /// + /// + /// + public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder, ErrorPageOptions options) + { + return builder.UseMiddleware(options); + } /// /// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. diff --git a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/ErrorPageOptions.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageOptions.cs similarity index 54% rename from src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/ErrorPageOptions.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageOptions.cs index 2c7da7078b..75b7a3951a 100644 --- a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/ErrorPageOptions.cs +++ b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageOptions.cs @@ -34,4 +34,33 @@ namespace Microsoft.AspNet.Diagnostics /// public IFileProvider FileProvider { get; set; } } + + /// + /// Options for the DeveloperExceptionPageMiddleware. + /// + public class DeveloperExceptionPageOptions + { + /// + /// Create an instance with the default options settings. + /// + public DeveloperExceptionPageOptions() + { + SourceCodeLineCount = 6; + } + + /// + /// Determines how many lines of code to include before and after the line of code + /// present in an exception's stack frame. Only applies when symbols are available and + /// source code referenced by the exception stack trace is present on the server. + /// + public int SourceCodeLineCount { get; set; } + + /// + /// Provides files containing source code used to display contextual information of an exception. + /// + /// + /// If null will use a . + /// + public IFileProvider FileProvider { get; set; } + } } diff --git a/src/Microsoft.AspNet.Diagnostics/Views/CompilationErrorModel.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/CompilationErrorModel.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/CompilationErrorModel.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/CompilationErrorModel.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/CompilationErrorPage.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/CompilationErrorPage.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/CompilationErrorPage.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/CompilationErrorPage.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/CompilationErrorPage.cshtml b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/CompilationErrorPage.cshtml similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/CompilationErrorPage.cshtml rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/CompilationErrorPage.cshtml diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorDetails.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorDetails.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/ErrorDetails.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorDetails.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cshtml b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.cshtml similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cshtml rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.cshtml diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.css b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.css similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.css rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.css diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.js b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.js similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.js rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPage.js diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPageModel.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPageModel.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/ErrorPageModel.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPageModel.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/StackFrame.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/StackFrame.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/StackFrame.cs rename to src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/StackFrame.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/DiagnosticsPage.cs b/src/Microsoft.AspNet.Diagnostics/DiagnosticsPage/DiagnosticsPage.cs similarity index 80% rename from src/Microsoft.AspNet.Diagnostics/Views/DiagnosticsPage.cs rename to src/Microsoft.AspNet.Diagnostics/DiagnosticsPage/DiagnosticsPage.cs index c7bc2f36e7..44f97819ce 100644 --- a/src/Microsoft.AspNet.Diagnostics/Views/DiagnosticsPage.cs +++ b/src/Microsoft.AspNet.Diagnostics/DiagnosticsPage/DiagnosticsPage.cs @@ -62,10 +62,10 @@ using System.Globalization #line default #line hidden WriteLiteral("\r\n

(Request.PathBase, 774), false), - Tuple.Create(Tuple.Create("", 791), Tuple.Create(Request.Path, 791), false), Tuple.Create(Tuple.Create("", 804), Tuple.Create("?error=", 804), true), - Tuple.Create(Tuple.Create("", 811), Tuple.Create(Resources.DiagnosticsPageHtml_TestErrorMessage, 811), false)); + WriteAttribute("href", Tuple.Create(" href=\"", 763), Tuple.Create("\"", 854), + Tuple.Create(Tuple.Create("", 770), Tuple.Create(Request.PathBase, 770), false), + Tuple.Create(Tuple.Create("", 787), Tuple.Create(Request.Path, 787), false), Tuple.Create(Tuple.Create("", 800), Tuple.Create("?error=", 800), true), + Tuple.Create(Tuple.Create("", 807), Tuple.Create(Resources.DiagnosticsPageHtml_TestErrorMessage, 807), false)); WriteLiteral(">throw InvalidOperationException

\r\n \r\n\r\n\r\n"); } #pragma warning restore 1998 diff --git a/src/Microsoft.AspNet.Diagnostics/Views/DiagnosticsPage.cshtml b/src/Microsoft.AspNet.Diagnostics/DiagnosticsPage/DiagnosticsPage.cshtml similarity index 94% rename from src/Microsoft.AspNet.Diagnostics/Views/DiagnosticsPage.cshtml rename to src/Microsoft.AspNet.Diagnostics/DiagnosticsPage/DiagnosticsPage.cshtml index 55b1d06f52..41099f3dde 100644 --- a/src/Microsoft.AspNet.Diagnostics/Views/DiagnosticsPage.cshtml +++ b/src/Microsoft.AspNet.Diagnostics/DiagnosticsPage/DiagnosticsPage.cshtml @@ -2,7 +2,7 @@ @using System.Globalization @{ Response.ContentType = "text/html"; - string error = Request.Query.Get("error"); + string error = Request.Query["error"]; if (!string.IsNullOrWhiteSpace(error)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "User requested error '{0}'", error)); diff --git a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs index 73436b635a..e3793f91e0 100644 --- a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs +++ b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs @@ -9,40 +9,40 @@ namespace Microsoft.AspNet.Builder { public static class ExceptionHandlerExtensions { - ///// - ///// Adds a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request. - ///// The request will not be re-executed if the response has already started. - ///// - ///// - ///// - ///// - //public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder app, string errorHandlingPath) - //{ - // var options = new ErrorHandlerOptions() - // { - // ErrorHandlingPath = new PathString(errorHandlingPath) - // }; - // return app.UseMiddleware(options); - //} + /// + /// Adds a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request. + /// The request will not be re-executed if the response has already started. + /// + /// + /// + /// + public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder app, string errorHandlingPath) + { + var options = new ExceptionHandlerOptions() + { + ExceptionHandlingPath = new PathString(errorHandlingPath) + }; + return app.UseMiddleware(options); + } - ///// - ///// Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline. - ///// The request will not be re-executed if the response has already started. - ///// - ///// - ///// - ///// - //public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder app, Action configure) - //{ - // var subAppBuilder = app.New(); - // configure(subAppBuilder); - // var errorPipeline = subAppBuilder.Build(); - // var options = new ErrorHandlerOptions() - // { - // ErrorHandler = errorPipeline - // }; - // return app.UseMiddleware(options); - //} + /// + /// Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline. + /// The request will not be re-executed if the response has already started. + /// + /// + /// + /// + public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder app, Action configure) + { + var subAppBuilder = app.New(); + configure(subAppBuilder); + var errorPipeline = subAppBuilder.Build(); + var options = new ExceptionHandlerOptions() + { + ExceptionHandler = errorPipeline + }; + return app.UseMiddleware(options); + } /// /// Adds a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request. @@ -53,9 +53,9 @@ namespace Microsoft.AspNet.Builder /// public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, string errorHandlingPath) { - var options = new ErrorHandlerOptions() + var options = new ExceptionHandlerOptions() { - ErrorHandlingPath = new PathString(errorHandlingPath) + ExceptionHandlingPath = new PathString(errorHandlingPath) }; return app.UseMiddleware(options); } @@ -72,9 +72,9 @@ namespace Microsoft.AspNet.Builder var subAppBuilder = app.New(); configure(subAppBuilder); var errorPipeline = subAppBuilder.Build(); - var options = new ErrorHandlerOptions() + var options = new ExceptionHandlerOptions() { - ErrorHandler = errorPipeline + ExceptionHandler = errorPipeline }; return app.UseMiddleware(options); } diff --git a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerMiddleware.cs index 5fb70e4d51..acb384a966 100644 --- a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerMiddleware.cs +++ b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerMiddleware.cs @@ -14,18 +14,18 @@ namespace Microsoft.AspNet.Diagnostics public class ExceptionHandlerMiddleware { private readonly RequestDelegate _next; - private readonly ErrorHandlerOptions _options; + private readonly ExceptionHandlerOptions _options; private readonly ILogger _logger; private readonly Func _clearCacheHeadersDelegate; - public ExceptionHandlerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, ErrorHandlerOptions options) + public ExceptionHandlerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, ExceptionHandlerOptions options) { _next = next; _options = options; _logger = loggerFactory.CreateLogger(); - if (_options.ErrorHandler == null) + if (_options.ExceptionHandler == null) { - _options.ErrorHandler = _next; + _options.ExceptionHandler = _next; } _clearCacheHeadersDelegate = ClearCacheHeaders; } @@ -47,17 +47,17 @@ namespace Microsoft.AspNet.Diagnostics } PathString originalPath = context.Request.Path; - if (_options.ErrorHandlingPath.HasValue) + if (_options.ExceptionHandlingPath.HasValue) { - context.Request.Path = _options.ErrorHandlingPath; + context.Request.Path = _options.ExceptionHandlingPath; } try { - var errorHandlerFeature = new ExceptionHandlerFeature() + var exceptionHandlerFeature = new ExceptionHandlerFeature() { Error = ex, }; - context.Features.Set(errorHandlerFeature); + context.Features.Set(exceptionHandlerFeature); context.Response.StatusCode = 500; context.Response.Headers.Clear(); context.Response.OnStarting(_clearCacheHeadersDelegate, context.Response); @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Diagnostics context.Response.Body.SetLength(0); } - await _options.ErrorHandler(context); + await _options.ExceptionHandler(context); // TODO: Optional re-throw? We'll re-throw the original exception by default if the error handler throws. return; } diff --git a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ErrorHandlerOptions.cs b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs similarity index 63% rename from src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ErrorHandlerOptions.cs rename to src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs index 0e5777d71f..eae58731fc 100644 --- a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ErrorHandlerOptions.cs +++ b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs @@ -6,10 +6,10 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Diagnostics { - public class ErrorHandlerOptions + public class ExceptionHandlerOptions { - public PathString ErrorHandlingPath { get; set; } + public PathString ExceptionHandlingPath { get; set; } - public RequestDelegate ErrorHandler { get; set; } + public RequestDelegate ExceptionHandler { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cs b/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cs rename to src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cshtml b/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.cshtml similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cshtml rename to src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.cshtml diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.css b/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.css similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.css rename to src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.css diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPageModel.cs b/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPageModel.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPageModel.cs rename to src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPageModel.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/WelcomePage.cs b/src/Microsoft.AspNet.Diagnostics/WelcomePage/Views/WelcomePage.cs similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/WelcomePage.cs rename to src/Microsoft.AspNet.Diagnostics/WelcomePage/Views/WelcomePage.cs diff --git a/src/Microsoft.AspNet.Diagnostics/Views/WelcomePage.cshtml b/src/Microsoft.AspNet.Diagnostics/WelcomePage/Views/WelcomePage.cshtml similarity index 100% rename from src/Microsoft.AspNet.Diagnostics/Views/WelcomePage.cshtml rename to src/Microsoft.AspNet.Diagnostics/WelcomePage/Views/WelcomePage.cshtml diff --git a/src/Microsoft.AspNet.Diagnostics/project.json b/src/Microsoft.AspNet.Diagnostics/project.json index b925031456..b1876933e8 100644 --- a/src/Microsoft.AspNet.Diagnostics/project.json +++ b/src/Microsoft.AspNet.Diagnostics/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "description": "ASP.NET 5 Middleware for error handling, error pages, and diagnostics information.", + "description": "ASP.NET 5 Middleware for exception handling, exception display pages, and diagnostics information.", "repository": { "type": "git", "url": "git://github.com/aspnet/diagnostics" diff --git a/src/PageGenerator/Program.cs b/src/PageGenerator/Program.cs index 11c96ee2c9..23746bb09d 100644 --- a/src/PageGenerator/Program.cs +++ b/src/PageGenerator/Program.cs @@ -35,20 +35,31 @@ namespace PageGenerator "Unable to open library {0}. Is it spelled correctly and listed as a dependency in project.json?", args[0])); } - var viewBasePath = Path.Combine(Path.GetDirectoryName(diagnosticsLibInfo.Path), "Views"); - Console.WriteLine("Generating code files for views in {0}", viewBasePath); - Console.WriteLine(); - - var cshtmlFiles = GetCshtmlFiles(viewBasePath); + var viewDirectories = Directory.EnumerateDirectories( + Path.GetDirectoryName(diagnosticsLibInfo.Path), "Views", SearchOption.AllDirectories); var fileCount = 0; - foreach (var fileName in cshtmlFiles) + foreach (var viewDir in viewDirectories) { - Console.WriteLine(" Generating code file for view {0}...", Path.GetFileName(fileName)); - GenerateCodeFile(fileName, string.Format("{0}.Views", args[0])); - Console.WriteLine(" Done!"); - fileCount++; + Console.WriteLine(); + Console.WriteLine(" Generating code files for views in {0}", viewDir); + + var cshtmlFiles = Directory.EnumerateFiles(viewDir, "*.cshtml"); + + if (!cshtmlFiles.Any()) + { + Console.WriteLine(" No .cshtml files were found."); + continue; + } + + foreach (var fileName in cshtmlFiles) + { + Console.WriteLine(" Generating code file for view {0}...", Path.GetFileName(fileName)); + GenerateCodeFile(fileName, string.Format("{0}.Views", args[0])); + Console.WriteLine(" Done!"); + fileCount++; + } } Console.WriteLine(); @@ -56,16 +67,6 @@ namespace PageGenerator Console.WriteLine(); } - private static IEnumerable GetCshtmlFiles(string path) - { - if (!Directory.Exists(path)) - { - throw new ArgumentException("path"); - } - - return Directory.EnumerateFiles(path, "*.cshtml"); - } - private static void GenerateCodeFile(string cshtmlFilePath, string rootNamespace) { var basePath = Path.GetDirectoryName(cshtmlFilePath); @@ -111,7 +112,7 @@ namespace PageGenerator } var includeFileName = source.Substring(startIndex + startMatch.Length, endIndex - (startIndex + startMatch.Length)); includeFileName = SanitizeFileName(includeFileName); - Console.WriteLine(" Inlining file {0}", includeFileName); + Console.WriteLine(" Inlining file {0}", includeFileName); var replacement = File.ReadAllText(Path.Combine(basePath, includeFileName)).Replace("\"", "\\\"").Replace("\r\n", "\\r\\n"); source = source.Substring(0, startIndex) + replacement + source.Substring(endIndex + endMatch.Length); startIndex = startIndex + replacement.Length; diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/ErrorPageMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs similarity index 98% rename from test/Microsoft.AspNet.Diagnostics.Tests/ErrorPageMiddlewareTest.cs rename to test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs index c0e354d771..7dc0fb5637 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/ErrorPageMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs @@ -19,7 +19,7 @@ using Microsoft.AspNet.Testing; namespace Microsoft.AspNet.Diagnostics { - public class ErrorPageMiddlewareTest + public class DeveloperExceptionPageMiddlewareTest { public static TheoryData RelativePathsData { @@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Diagnostics // Arrange var provider = new EmbeddedFileProvider( GetType().GetTypeInfo().Assembly, - baseNamespace: $"{typeof(ErrorPageMiddlewareTest).GetTypeInfo().Assembly.GetName().Name}.Resources"); + baseNamespace: $"{typeof(DeveloperExceptionPageMiddlewareTest).GetTypeInfo().Assembly.GetName().Name}.Resources"); // Act var middleware = GetErrorPageMiddleware(provider); diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/ErrorHandlerTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs similarity index 99% rename from test/Microsoft.AspNet.Diagnostics.Tests/ErrorHandlerTest.cs rename to test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs index dc154408a9..5fb589c95c 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/ErrorHandlerTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs @@ -6,17 +6,15 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.TestHost; using Xunit; namespace Microsoft.AspNet.Diagnostics { - public class ErrorHandlerTest + public class ExceptionHandlerTest { [Theory] [InlineData(HttpStatusCode.NotFound)]