зеркало из https://github.com/aspnet/Mvc.git
Update to use DiagnosticSource
This commit is contained in:
Родитель
054b39013c
Коммит
173f00fda7
|
@ -84,7 +84,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Locali
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Localization.Test", "test\Microsoft.AspNet.Mvc.Localization.Test\Microsoft.AspNet.Mvc.Localization.Test.xproj", "{8FC726B5-E766-44E0-8B38-1313B6D8D9A7}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestTelemetryListener.Sources", "test\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources", "test\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
2
Mvc.sln
2
Mvc.sln
|
@ -180,7 +180,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Locali
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Localization.Test", "test\Microsoft.AspNet.Mvc.Localization.Test\Microsoft.AspNet.Mvc.Localization.Test.xproj", "{8FC726B5-E766-44E0-8B38-1313B6D8D9A7}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestTelemetryListener.Sources", "test\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources", "test\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
|
@ -23,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
private readonly ControllerActionDescriptor _descriptor;
|
||||
private readonly IControllerFactory _controllerFactory;
|
||||
private readonly IControllerActionArgumentBinder _argumentBinder;
|
||||
#pragma warning disable 0618
|
||||
|
||||
public ControllerActionInvoker(
|
||||
ActionContext actionContext,
|
||||
IReadOnlyList<IFilterProvider> filterProviders,
|
||||
|
@ -37,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
IReadOnlyList<IValueProviderFactory> valueProviderFactories,
|
||||
IActionBindingContextAccessor actionBindingContextAccessor,
|
||||
ILogger logger,
|
||||
TelemetrySource telemetry,
|
||||
DiagnosticSource diagnosticSource,
|
||||
int maxModelValidationErrors)
|
||||
: base(
|
||||
actionContext,
|
||||
|
@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
valueProviderFactories,
|
||||
actionBindingContextAccessor,
|
||||
logger,
|
||||
telemetry,
|
||||
diagnosticSource,
|
||||
maxModelValidationErrors)
|
||||
{
|
||||
if (actionContext == null)
|
||||
|
@ -112,9 +111,9 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (telemetry == null)
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(telemetry));
|
||||
throw new ArgumentNullException(nameof(diagnosticSource));
|
||||
}
|
||||
|
||||
_descriptor = descriptor;
|
||||
|
@ -129,7 +128,6 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
"descriptor");
|
||||
}
|
||||
}
|
||||
#pragma warning disable 0618
|
||||
|
||||
protected override object CreateInstance()
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Abstractions;
|
||||
using Microsoft.AspNet.Mvc.Filters;
|
||||
|
@ -18,7 +18,6 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
{
|
||||
public class ControllerActionInvokerProvider : IActionInvokerProvider
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
private readonly IControllerActionArgumentBinder _argumentBinder;
|
||||
private readonly IControllerFactory _controllerFactory;
|
||||
private readonly IFilterProvider[] _filterProviders;
|
||||
|
@ -30,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
private readonly IActionBindingContextAccessor _actionBindingContextAccessor;
|
||||
private readonly int _maxModelValidationErrors;
|
||||
private readonly ILogger _logger;
|
||||
private readonly TelemetrySource _telemetry;
|
||||
private readonly DiagnosticSource _diagnosticSource;
|
||||
|
||||
public ControllerActionInvokerProvider(
|
||||
IControllerFactory controllerFactory,
|
||||
|
@ -39,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
IOptions<MvcOptions> optionsAccessor,
|
||||
IActionBindingContextAccessor actionBindingContextAccessor,
|
||||
ILoggerFactory loggerFactory,
|
||||
TelemetrySource telemetry)
|
||||
DiagnosticSource diagnosticSource)
|
||||
{
|
||||
_controllerFactory = controllerFactory;
|
||||
_filterProviders = filterProviders.OrderBy(item => item.Order).ToArray();
|
||||
|
@ -52,9 +51,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
_actionBindingContextAccessor = actionBindingContextAccessor;
|
||||
_maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors;
|
||||
_logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
|
||||
_telemetry = telemetry;
|
||||
_diagnosticSource = diagnosticSource;
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
public int Order
|
||||
{
|
||||
|
@ -86,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
_valueProviderFactories,
|
||||
_actionBindingContextAccessor,
|
||||
_logger,
|
||||
_telemetry,
|
||||
_diagnosticSource,
|
||||
_maxModelValidationErrors);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Abstractions;
|
||||
|
@ -31,9 +30,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
private readonly IReadOnlyList<IValueProviderFactory> _valueProviderFactories;
|
||||
private readonly IActionBindingContextAccessor _actionBindingContextAccessor;
|
||||
private readonly ILogger _logger;
|
||||
#pragma warning disable 0618
|
||||
private readonly TelemetrySource _telemetry;
|
||||
#pragma warning restore 0618
|
||||
private readonly DiagnosticSource _diagnosticSource;
|
||||
private readonly int _maxModelValidationErrors;
|
||||
|
||||
private IFilterMetadata[] _filters;
|
||||
|
@ -62,8 +59,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
"Request was short circuited at exception filter '{ExceptionFilter}'.";
|
||||
private const string ResultFilterShortCircuitLogMessage =
|
||||
"Request was short circuited at result filter '{ResultFilter}'.";
|
||||
|
||||
#pragma warning disable 0618
|
||||
|
||||
public FilterActionInvoker(
|
||||
ActionContext actionContext,
|
||||
IReadOnlyList<IFilterProvider> filterProviders,
|
||||
|
@ -74,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
IReadOnlyList<IValueProviderFactory> valueProviderFactories,
|
||||
IActionBindingContextAccessor actionBindingContextAccessor,
|
||||
ILogger logger,
|
||||
TelemetrySource telemetry,
|
||||
DiagnosticSource diagnosticSource,
|
||||
int maxModelValidationErrors)
|
||||
{
|
||||
if (actionContext == null)
|
||||
|
@ -122,9 +118,9 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (telemetry == null)
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(telemetry));
|
||||
throw new ArgumentNullException(nameof(diagnosticSource));
|
||||
}
|
||||
|
||||
ActionContext = actionContext;
|
||||
|
@ -137,10 +133,9 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
_valueProviderFactories = valueProviderFactories;
|
||||
_actionBindingContextAccessor = actionBindingContextAccessor;
|
||||
_logger = logger;
|
||||
_telemetry = telemetry;
|
||||
_diagnosticSource = diagnosticSource;
|
||||
_maxModelValidationErrors = maxModelValidationErrors;
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
protected ActionContext ActionContext { get; private set; }
|
||||
|
||||
|
@ -656,10 +651,9 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
|
||||
try
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionMethod"))
|
||||
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionMethod"))
|
||||
{
|
||||
_telemetry.WriteTelemetry(
|
||||
_diagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.BeforeActionMethod",
|
||||
new
|
||||
{
|
||||
|
@ -668,16 +662,14 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
controller = _actionExecutingContext.Controller
|
||||
});
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
result = await InvokeActionAsync(_actionExecutingContext);
|
||||
}
|
||||
finally
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterActionMethod"))
|
||||
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterActionMethod"))
|
||||
{
|
||||
_telemetry.WriteTelemetry(
|
||||
_diagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.AfterActionMethod",
|
||||
new
|
||||
{
|
||||
|
@ -687,7 +679,6 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
result = result
|
||||
});
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
|
||||
_actionExecutedContext = new ActionExecutedContext(
|
||||
|
@ -835,14 +826,12 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
|
||||
private async Task InvokeResultAsync(IActionResult result)
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionResult"))
|
||||
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionResult"))
|
||||
{
|
||||
_telemetry.WriteTelemetry(
|
||||
_diagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.BeforeActionResult",
|
||||
new { actionContext = ActionContext, result = result });
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -850,14 +839,12 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
}
|
||||
finally
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterActionResult"))
|
||||
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterActionResult"))
|
||||
{
|
||||
_telemetry.WriteTelemetry(
|
||||
_diagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.AfterActionResult",
|
||||
new { actionContext = ActionContext, result = result });
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Abstractions;
|
||||
|
@ -21,9 +21,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
private IActionInvokerFactory _actionInvokerFactory;
|
||||
private IActionSelector _actionSelector;
|
||||
private ILogger _logger;
|
||||
#pragma warning disable 0618
|
||||
private TelemetrySource _telemetry;
|
||||
#pragma warning restore 0618
|
||||
private DiagnosticSource _diagnosticSource;
|
||||
|
||||
public VirtualPathData GetVirtualPath(VirtualPathContext context)
|
||||
{
|
||||
|
@ -86,14 +84,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
{
|
||||
context.RouteData = newRouteData;
|
||||
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeAction"))
|
||||
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeAction"))
|
||||
{
|
||||
_telemetry.WriteTelemetry(
|
||||
_diagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.BeforeAction",
|
||||
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData });
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id))
|
||||
{
|
||||
|
@ -105,14 +101,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
}
|
||||
finally
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterAction"))
|
||||
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterAction"))
|
||||
{
|
||||
_telemetry.WriteTelemetry(
|
||||
_diagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.AfterAction",
|
||||
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData });
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
if (!context.IsHandled)
|
||||
{
|
||||
|
@ -159,13 +153,11 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
var factory = context.RequestServices.GetRequiredService<ILoggerFactory>();
|
||||
_logger = factory.CreateLogger<MvcRouteHandler>();
|
||||
}
|
||||
|
||||
#pragma warning disable 0618
|
||||
if (_telemetry == null)
|
||||
|
||||
if (_diagnosticSource == null)
|
||||
{
|
||||
_telemetry = context.RequestServices.GetRequiredService<TelemetrySource>();
|
||||
_diagnosticSource = context.RequestServices.GetRequiredService<DiagnosticSource>();
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
"version": "1.0.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*"
|
||||
"System.Diagnostics.DiagnosticSource": "4.0.0-beta-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Infrastructure;
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
|
@ -16,22 +16,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
/// </summary>
|
||||
public class PartialViewResultExecutor : ViewExecutor
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PartialViewResultExecutor"/>.
|
||||
/// </summary>
|
||||
/// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
|
||||
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
|
||||
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
|
||||
/// <param name="telemetry">The <see cref="TelemetrySource"/>.</param>
|
||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
||||
public PartialViewResultExecutor(
|
||||
IOptions<MvcViewOptions> viewOptions,
|
||||
IHttpResponseStreamWriterFactory writerFactory,
|
||||
ICompositeViewEngine viewEngine,
|
||||
TelemetrySource telemetry,
|
||||
DiagnosticSource diagnosticSource,
|
||||
ILoggerFactory loggerFactory)
|
||||
: base(viewOptions, writerFactory, viewEngine, telemetry)
|
||||
: base(viewOptions, writerFactory, viewEngine, diagnosticSource)
|
||||
{
|
||||
if (loggerFactory == null)
|
||||
{
|
||||
|
@ -40,7 +39,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
|
||||
Logger = loggerFactory.CreateLogger<PartialViewResultExecutor>();
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ILogger"/>.
|
||||
|
@ -71,10 +69,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
var result = viewEngine.FindPartialView(actionContext, viewName);
|
||||
if (result.Success)
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewFound"))
|
||||
if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewFound"))
|
||||
{
|
||||
Telemetry.WriteTelemetry(
|
||||
DiagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.ViewFound",
|
||||
new
|
||||
{
|
||||
|
@ -85,15 +82,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
view = result.View,
|
||||
});
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
Logger.LogVerbose("The partial view '{PartialViewName}' was found.", viewName);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound"))
|
||||
if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound"))
|
||||
{
|
||||
Telemetry.WriteTelemetry(
|
||||
DiagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.ViewNotFound",
|
||||
new
|
||||
{
|
||||
|
@ -104,7 +100,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
searchedLocations = result.SearchedLocations
|
||||
});
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
Logger.LogError(
|
||||
"The partial view '{PartialViewName}' was not found. Searched locations: {SearchedViewLocations}",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Infrastructure;
|
||||
|
@ -26,19 +26,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
Encoding = Encoding.UTF8
|
||||
}.CopyAsReadOnly();
|
||||
|
||||
#pragma warning disable 0618
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ViewExecutor"/>.
|
||||
/// </summary>
|
||||
/// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
|
||||
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
|
||||
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
|
||||
/// <param name="telemetry">The <see cref="TelemetrySource"/>.</param>
|
||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||
public ViewExecutor(
|
||||
IOptions<MvcViewOptions> viewOptions,
|
||||
IHttpResponseStreamWriterFactory writerFactory,
|
||||
ICompositeViewEngine viewEngine,
|
||||
TelemetrySource telemetry)
|
||||
DiagnosticSource diagnosticSource)
|
||||
{
|
||||
if (viewOptions == null)
|
||||
{
|
||||
|
@ -55,22 +54,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
throw new ArgumentNullException(nameof(viewEngine));
|
||||
}
|
||||
|
||||
if (telemetry == null)
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(telemetry));
|
||||
throw new ArgumentNullException(nameof(diagnosticSource));
|
||||
}
|
||||
|
||||
ViewOptions = viewOptions.Value;
|
||||
WriterFactory = writerFactory;
|
||||
ViewEngine = viewEngine;
|
||||
Telemetry = telemetry;
|
||||
DiagnosticSource = diagnosticSource;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="TelemetrySource"/>.
|
||||
/// Gets the <see cref="DiagnosticSource"/>.
|
||||
/// </summary>
|
||||
protected TelemetrySource Telemetry { get; }
|
||||
#pragma warning restore 0618
|
||||
protected DiagnosticSource DiagnosticSource { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default <see cref="IViewEngine"/>.
|
||||
|
@ -159,26 +157,22 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
tempData,
|
||||
writer,
|
||||
ViewOptions.HtmlHelperOptions);
|
||||
|
||||
#pragma warning disable 0618
|
||||
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeView"))
|
||||
|
||||
if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeView"))
|
||||
{
|
||||
Telemetry.WriteTelemetry(
|
||||
DiagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.BeforeView",
|
||||
new { view = view, viewContext = viewContext, });
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
await view.RenderAsync(viewContext);
|
||||
|
||||
#pragma warning disable 0618
|
||||
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterView"))
|
||||
|
||||
if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterView"))
|
||||
{
|
||||
Telemetry.WriteTelemetry(
|
||||
DiagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.AfterView",
|
||||
new { view = view, viewContext = viewContext, });
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
// Perf: Invoke FlushAsync to ensure any buffered content is asynchronously written to the underlying
|
||||
// response asynchronously. In the absence of this line, the buffer gets synchronously written to the
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Infrastructure;
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
|
@ -16,22 +16,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
/// </summary>
|
||||
public class ViewResultExecutor : ViewExecutor
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ViewResultExecutor"/>.
|
||||
/// </summary>
|
||||
/// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
|
||||
/// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
|
||||
/// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
|
||||
/// <param name="telemetry">The <see cref="TelemetrySource"/>.</param>
|
||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
||||
public ViewResultExecutor(
|
||||
IOptions<MvcViewOptions> viewOptions,
|
||||
IHttpResponseStreamWriterFactory writerFactory,
|
||||
ICompositeViewEngine viewEngine,
|
||||
TelemetrySource telemetry,
|
||||
DiagnosticSource diagnosticSource,
|
||||
ILoggerFactory loggerFactory)
|
||||
: base(viewOptions, writerFactory, viewEngine, telemetry)
|
||||
: base(viewOptions, writerFactory, viewEngine, diagnosticSource)
|
||||
{
|
||||
if (loggerFactory == null)
|
||||
{
|
||||
|
@ -40,7 +39,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
|
||||
Logger = loggerFactory.CreateLogger<ViewResultExecutor>();
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ILogger"/>.
|
||||
|
@ -71,10 +69,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
var result = viewEngine.FindView(actionContext, viewName);
|
||||
if (result.Success)
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewFound"))
|
||||
if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewFound"))
|
||||
{
|
||||
Telemetry.WriteTelemetry(
|
||||
DiagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.ViewFound",
|
||||
new
|
||||
{
|
||||
|
@ -85,16 +82,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
view = result.View,
|
||||
});
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
Logger.LogVerbose("The view '{ViewName}' was found.", viewName);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound"))
|
||||
if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound"))
|
||||
{
|
||||
Telemetry.WriteTelemetry(
|
||||
DiagnosticSource.Write(
|
||||
"Microsoft.AspNet.Mvc.ViewNotFound",
|
||||
new
|
||||
{
|
||||
|
@ -105,7 +100,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
searchedLocations = result.SearchedLocations
|
||||
});
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
Logger.LogError(
|
||||
"The view '{ViewName}' was not found. Searched locations: {SearchedViewLocations}",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -2041,7 +2041,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
filterProvider
|
||||
.SetupGet(fp => fp.Order)
|
||||
.Returns(-1000);
|
||||
#pragma warning disable 0618
|
||||
|
||||
var invoker = new TestControllerActionInvoker(
|
||||
actionContext,
|
||||
new[] { filterProvider.Object },
|
||||
|
@ -2055,9 +2055,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
new IValueProviderFactory[0],
|
||||
new ActionBindingContextAccessor(),
|
||||
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
|
||||
new TelemetryListener("Microsoft.AspNet"),
|
||||
new DiagnosticListener("Microsoft.AspNet"),
|
||||
maxAllowedErrorsInModelState);
|
||||
#pragma warning restore 0618
|
||||
return invoker;
|
||||
}
|
||||
|
||||
|
@ -2101,7 +2100,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
.Returns(new TestController());
|
||||
|
||||
var metadataProvider = new EmptyModelMetadataProvider();
|
||||
#pragma warning disable 0618
|
||||
|
||||
var invoker = new ControllerActionInvoker(
|
||||
actionContext,
|
||||
new List<IFilterProvider>(),
|
||||
|
@ -2117,9 +2116,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
new IValueProviderFactory[0],
|
||||
new ActionBindingContextAccessor(),
|
||||
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
|
||||
new TelemetryListener("Microsoft.AspNet"),
|
||||
new DiagnosticListener("Microsoft.AspNet"),
|
||||
200);
|
||||
#pragma warning restore 0618
|
||||
|
||||
// Act
|
||||
await invoker.InvokeAsync();
|
||||
|
@ -2206,7 +2204,6 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
|
||||
private class TestControllerActionInvoker : ControllerActionInvoker
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
public TestControllerActionInvoker(
|
||||
ActionContext actionContext,
|
||||
IFilterProvider[] filterProvider,
|
||||
|
@ -2220,7 +2217,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
IReadOnlyList<IValueProviderFactory> valueProviderFactories,
|
||||
IActionBindingContextAccessor actionBindingContext,
|
||||
ILogger logger,
|
||||
TelemetrySource telemetry,
|
||||
DiagnosticSource diagnosticSource,
|
||||
int maxAllowedErrorsInModelState)
|
||||
: base(
|
||||
actionContext,
|
||||
|
@ -2235,12 +2232,11 @@ namespace Microsoft.AspNet.Mvc.Controllers
|
|||
valueProviderFactories,
|
||||
actionBindingContext,
|
||||
logger,
|
||||
telemetry,
|
||||
diagnosticSource,
|
||||
maxAllowedErrorsInModelState)
|
||||
{
|
||||
ControllerFactory = controllerFactory;
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
public MockControllerFactory ControllerFactory { get; }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Abstractions;
|
||||
|
@ -193,12 +193,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RouteAsync_Notifies_ActionSelected()
|
||||
public async Task RouteAsync_WritesDiagnostic_ActionSelected()
|
||||
{
|
||||
// Arrange
|
||||
var listener = new TestTelemetryListener();
|
||||
var listener = new TestDiagnosticListener();
|
||||
|
||||
var context = CreateRouteContext(telemetryListener: listener);
|
||||
var context = CreateRouteContext(diagnosticListener: listener);
|
||||
context.RouteData.Values.Add("tag", "value");
|
||||
|
||||
var handler = new MvcRouteHandler();
|
||||
|
@ -218,12 +218,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RouteAsync_Notifies_ActionInvoked()
|
||||
public async Task RouteAsync_WritesDiagnostic_ActionInvoked()
|
||||
{
|
||||
// Arrange
|
||||
var listener = new TestTelemetryListener();
|
||||
var listener = new TestDiagnosticListener();
|
||||
|
||||
var context = CreateRouteContext(telemetryListener: listener);
|
||||
var context = CreateRouteContext(diagnosticListener: listener);
|
||||
|
||||
var handler = new MvcRouteHandler();
|
||||
|
||||
|
@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
IActionInvokerFactory invokerFactory = null,
|
||||
ILoggerFactory loggerFactory = null,
|
||||
IOptions<MvcOptions> optionsAccessor = null,
|
||||
object telemetryListener = null)
|
||||
object diagnosticListener = null)
|
||||
{
|
||||
if (actionDescriptor == null)
|
||||
{
|
||||
|
@ -280,13 +280,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
{
|
||||
optionsAccessor = new TestOptionsManager<MvcOptions>();
|
||||
}
|
||||
#pragma warning disable 0618
|
||||
var telemetry = new TelemetryListener("Microsoft.AspNet");
|
||||
if (telemetryListener != null)
|
||||
|
||||
var diagnosticSource = new DiagnosticListener("Microsoft.AspNet");
|
||||
if (diagnosticListener != null)
|
||||
{
|
||||
telemetry.SubscribeWithAdapter(telemetryListener);
|
||||
diagnosticSource.SubscribeWithAdapter(diagnosticListener);
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
var httpContext = new Mock<HttpContext>();
|
||||
httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor)))
|
||||
.Returns(new ActionContextAccessor());
|
||||
|
@ -300,10 +300,8 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
|
|||
.Returns(new MvcMarkerService());
|
||||
httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
|
||||
.Returns(optionsAccessor);
|
||||
#pragma warning disable 0618
|
||||
httpContext.Setup(h => h.RequestServices.GetService(typeof(TelemetrySource)))
|
||||
.Returns(telemetry);
|
||||
#pragma warning restore 0618
|
||||
httpContext.Setup(h => h.RequestServices.GetService(typeof(DiagnosticSource)))
|
||||
.Returns(diagnosticSource);
|
||||
return new RouteContext(httpContext.Object);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
"type": "build"
|
||||
},
|
||||
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestTelemetryListener.Sources": {
|
||||
"Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources": {
|
||||
"version": "6.0.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||
"Microsoft.Extensions.Logging.Testing": "1.0.0-*",
|
||||
"Microsoft.Extensions.TelemetryAdapter": "1.0.0-*",
|
||||
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
|
||||
"Microsoft.Extensions.WebEncoders.Testing": "1.0.0-*",
|
||||
"Moq": "4.2.1312.1622",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>9879b5d5-2325-4a81-b4df-f279fe8feeb4</ProjectGuid>
|
||||
<RootNamespace>Microsoft.AspNet.Mvc.TestTelemetryListener.Sources</RootNamespace>
|
||||
<RootNamespace>Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
|
@ -2,11 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.TelemetryAdapter;
|
||||
using Microsoft.Extensions.DiagnosticAdapter;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class TestTelemetryListener
|
||||
public class TestDiagnosticListener
|
||||
{
|
||||
public class OnBeforeActionEventData
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnBeforeActionEventData BeforeAction { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.BeforeAction")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.BeforeAction")]
|
||||
public virtual void OnBeforeAction(
|
||||
IProxyHttpContext httpContext,
|
||||
IProxyRouteData routeData,
|
||||
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnAfterActionEventData AfterAction { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.AfterAction")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.AfterAction")]
|
||||
public virtual void OnAfterAction(
|
||||
IProxyHttpContext httpContext,
|
||||
IProxyActionDescriptor actionDescriptor)
|
||||
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnBeforeActionMethodEventData BeforeActionMethod { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.BeforeActionMethod")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.BeforeActionMethod")]
|
||||
public virtual void OnBeforeActionMethod(
|
||||
IProxyActionContext actionContext,
|
||||
IReadOnlyDictionary<string, object> arguments)
|
||||
|
@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnAfterActionMethodEventData AfterActionMethod { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.AfterActionMethod")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.AfterActionMethod")]
|
||||
public virtual void OnAfterActionMethod(
|
||||
IProxyActionContext actionContext,
|
||||
IProxyActionResult result)
|
||||
|
@ -99,7 +99,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnBeforeActionResultEventData BeforeActionResult { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.BeforeActionResult")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.BeforeActionResult")]
|
||||
public virtual void OnBeforeActionResult(IProxyActionContext actionContext, IProxyActionResult result)
|
||||
{
|
||||
BeforeActionResult = new OnBeforeActionResultEventData()
|
||||
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnAfterActionResultEventData AfterActionResult { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.AfterActionResult")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.AfterActionResult")]
|
||||
public virtual void OnAfterActionResult(IProxyActionContext actionContext, IProxyActionResult result)
|
||||
{
|
||||
AfterActionResult = new OnAfterActionResultEventData()
|
||||
|
@ -138,7 +138,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnViewFoundEventData ViewFound { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.ViewFound")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.ViewFound")]
|
||||
public virtual void OnViewFound(
|
||||
IProxyActionContext actionContext,
|
||||
bool isPartial,
|
||||
|
@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnViewNotFoundEventData ViewNotFound { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.ViewNotFound")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.ViewNotFound")]
|
||||
public virtual void OnViewNotFound(
|
||||
IProxyActionContext actionContext,
|
||||
bool isPartial,
|
||||
|
@ -193,7 +193,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnBeforeViewEventData BeforeView { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.BeforeView")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.BeforeView")]
|
||||
public virtual void OnBeforeView(IProxyView view, IProxyViewContext viewContext)
|
||||
{
|
||||
BeforeView = new OnBeforeViewEventData()
|
||||
|
@ -211,7 +211,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public OnAfterViewEventData AfterView { get; set; }
|
||||
|
||||
[TelemetryName("Microsoft.AspNet.Mvc.AfterView")]
|
||||
[DiagnosticName("Microsoft.AspNet.Mvc.AfterView")]
|
||||
public virtual void OnAfterView(IProxyView view, IProxyViewContext viewContext)
|
||||
{
|
||||
AfterView = new OnAfterViewEventData()
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#if MOCK_SUPPORT
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
|
@ -105,14 +105,13 @@ namespace Microsoft.AspNet.Mvc
|
|||
private HttpContext GetHttpContext()
|
||||
{
|
||||
var options = new TestOptionsManager<MvcViewOptions>();
|
||||
#pragma warning disable 0618
|
||||
|
||||
var viewExecutor = new PartialViewResultExecutor(
|
||||
options,
|
||||
new TestHttpResponseStreamWriterFactory(),
|
||||
new CompositeViewEngine(options),
|
||||
new TelemetryListener("Microsoft.AspNet"),
|
||||
new DiagnosticListener("Microsoft.AspNet"),
|
||||
NullLoggerFactory.Instance);
|
||||
#pragma warning restore 0618
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddInstance(viewExecutor);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
#if MOCK_SUPPORT
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.Abstractions;
|
||||
|
@ -70,18 +70,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
// Assert
|
||||
Assert.Equal(viewName, viewEngineResult.ViewName);
|
||||
}
|
||||
|
||||
#pragma warning disable 0618
|
||||
|
||||
[Fact]
|
||||
public void FindView_Notifies_ViewFound()
|
||||
public void FindView_WritesDiagnostic_ViewFound()
|
||||
{
|
||||
// Arrange
|
||||
var telemetry = new TelemetryListener("Test");
|
||||
var listener = new TestTelemetryListener();
|
||||
telemetry.SubscribeWithAdapter(listener);
|
||||
var diagnosticSource = new DiagnosticListener("Test");
|
||||
var listener = new TestDiagnosticListener();
|
||||
diagnosticSource.SubscribeWithAdapter(listener);
|
||||
|
||||
var context = GetActionContext();
|
||||
var executor = GetViewExecutor(telemetry);
|
||||
var executor = GetViewExecutor(diagnosticSource);
|
||||
|
||||
var viewName = "myview";
|
||||
var viewResult = new PartialViewResult
|
||||
|
@ -106,15 +105,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void FindView_Notifies_ViewNotFound()
|
||||
public void FindView_WritesDiagnostic_ViewNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var telemetry = new TelemetryListener("Test");
|
||||
var listener = new TestTelemetryListener();
|
||||
telemetry.SubscribeWithAdapter(listener);
|
||||
var diagnosticSource = new DiagnosticListener("Test");
|
||||
var listener = new TestDiagnosticListener();
|
||||
diagnosticSource.SubscribeWithAdapter(listener);
|
||||
|
||||
var context = GetActionContext();
|
||||
var executor = GetViewExecutor(telemetry);
|
||||
var executor = GetViewExecutor(diagnosticSource);
|
||||
|
||||
var viewName = "myview";
|
||||
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
|
||||
|
@ -142,7 +141,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
Assert.Equal(new string[] { "location/myview" }, listener.ViewNotFound.SearchedLocations);
|
||||
Assert.Equal("myview", listener.ViewNotFound.ViewName);
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_UsesContentType_FromPartialViewResult()
|
||||
|
@ -201,13 +199,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
{
|
||||
return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||
}
|
||||
|
||||
#pragma warning disable 0618
|
||||
private PartialViewResultExecutor GetViewExecutor(TelemetrySource telemetry = null)
|
||||
|
||||
private PartialViewResultExecutor GetViewExecutor(DiagnosticSource diagnosticSource = null)
|
||||
{
|
||||
if (telemetry == null)
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
telemetry = new TelemetryListener("Test");
|
||||
diagnosticSource = new DiagnosticListener("Test");
|
||||
}
|
||||
|
||||
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
|
||||
|
@ -222,12 +219,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
options,
|
||||
new TestHttpResponseStreamWriterFactory(),
|
||||
new CompositeViewEngine(options),
|
||||
telemetry,
|
||||
diagnosticSource,
|
||||
NullLoggerFactory.Instance);
|
||||
|
||||
return viewExecutor;
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#if MOCK_SUPPORT
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
@ -146,9 +146,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
Assert.Equal(500, context.Response.StatusCode);
|
||||
Assert.Equal("abcd", Encoding.UTF8.GetString(memoryStream.ToArray()));
|
||||
}
|
||||
#pragma warning disable 0618
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WritesTelemetry()
|
||||
public async Task ExecuteAsync_WritesDiagnostic()
|
||||
{
|
||||
// Arrange
|
||||
var view = CreateView(async (v) =>
|
||||
|
@ -166,12 +166,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
new ActionDescriptor());
|
||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
||||
|
||||
var adapter = new TestTelemetryListener();
|
||||
var adapter = new TestDiagnosticListener();
|
||||
|
||||
var telemetryListener = new TelemetryListener("Test");
|
||||
telemetryListener.SubscribeWithAdapter(adapter);
|
||||
var diagnosticSource = new DiagnosticListener("Test");
|
||||
diagnosticSource.SubscribeWithAdapter(adapter);
|
||||
|
||||
var viewExecutor = CreateViewExecutor(telemetryListener);
|
||||
var viewExecutor = CreateViewExecutor(diagnosticSource);
|
||||
|
||||
// Act
|
||||
await viewExecutor.ExecuteAsync(
|
||||
|
@ -190,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
Assert.NotNull(adapter.AfterView?.View);
|
||||
Assert.NotNull(adapter.AfterView?.ViewContext);
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_DoesNotWriteToResponse_OnceExceptionIsThrown()
|
||||
{
|
||||
|
@ -277,21 +277,20 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
|
||||
return view.Object;
|
||||
}
|
||||
#pragma warning disable 0618
|
||||
private ViewExecutor CreateViewExecutor(TelemetryListener listener = null)
|
||||
|
||||
private ViewExecutor CreateViewExecutor(DiagnosticListener diagnosticSource = null)
|
||||
{
|
||||
if (listener == null)
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
listener = new TelemetryListener("Test");
|
||||
diagnosticSource = new DiagnosticListener("Test");
|
||||
}
|
||||
|
||||
return new ViewExecutor(
|
||||
new TestOptionsManager<MvcViewOptions>(),
|
||||
new TestHttpResponseStreamWriterFactory(),
|
||||
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
|
||||
listener);
|
||||
diagnosticSource);
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
#if MOCK_SUPPORT
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.Abstractions;
|
||||
|
@ -71,17 +71,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
Assert.Equal(viewName, viewEngineResult.ViewName);
|
||||
}
|
||||
|
||||
#pragma warning disable 0618
|
||||
[Fact]
|
||||
public void FindView_Notifies_ViewFound()
|
||||
public void FindView_WritesDiagnostic_ViewFound()
|
||||
{
|
||||
// Arrange
|
||||
var telemetry = new TelemetryListener("Test");
|
||||
var listener = new TestTelemetryListener();
|
||||
telemetry.SubscribeWithAdapter(listener);
|
||||
var diagnosticSource = new DiagnosticListener("Test");
|
||||
var listener = new TestDiagnosticListener();
|
||||
diagnosticSource.SubscribeWithAdapter(listener);
|
||||
|
||||
var context = GetActionContext();
|
||||
var executor = GetViewExecutor(telemetry);
|
||||
var executor = GetViewExecutor(diagnosticSource);
|
||||
|
||||
var viewName = "myview";
|
||||
var viewResult = new ViewResult
|
||||
|
@ -106,15 +105,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void FindView_Notifies_ViewNotFound()
|
||||
public void FindView_WritesDiagnostic_ViewNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var telemetry = new TelemetryListener("Test");
|
||||
var listener = new TestTelemetryListener();
|
||||
telemetry.SubscribeWithAdapter(listener);
|
||||
var diagnosticSource = new DiagnosticListener("Test");
|
||||
var listener = new TestDiagnosticListener();
|
||||
diagnosticSource.SubscribeWithAdapter(listener);
|
||||
|
||||
var context = GetActionContext();
|
||||
var executor = GetViewExecutor(telemetry);
|
||||
var executor = GetViewExecutor(diagnosticSource);
|
||||
|
||||
var viewName = "myview";
|
||||
var viewEngine = new Mock<IViewEngine>();
|
||||
|
@ -142,7 +141,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
Assert.Equal(new string[] { "location/myview" }, listener.ViewNotFound.SearchedLocations);
|
||||
Assert.Equal("myview", listener.ViewNotFound.ViewName);
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_UsesContentType_FromViewResult()
|
||||
|
@ -201,13 +199,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
{
|
||||
return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||
}
|
||||
|
||||
#pragma warning disable 0618
|
||||
private ViewResultExecutor GetViewExecutor(TelemetrySource telemetry = null)
|
||||
|
||||
private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticSource = null)
|
||||
{
|
||||
if (telemetry == null)
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
telemetry = new TelemetryListener("Test");
|
||||
diagnosticSource = new DiagnosticListener("Test");
|
||||
}
|
||||
|
||||
var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
|
||||
|
@ -222,12 +219,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
options,
|
||||
new TestHttpResponseStreamWriterFactory(),
|
||||
new CompositeViewEngine(options),
|
||||
telemetry,
|
||||
diagnosticSource,
|
||||
NullLoggerFactory.Instance);
|
||||
|
||||
return viewExecutor;
|
||||
}
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#if MOCK_SUPPORT
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
|
@ -105,14 +105,13 @@ namespace Microsoft.AspNet.Mvc
|
|||
private HttpContext GetHttpContext()
|
||||
{
|
||||
var options = new TestOptionsManager<MvcViewOptions>();
|
||||
#pragma warning disable 0618
|
||||
|
||||
var viewExecutor = new ViewResultExecutor(
|
||||
options,
|
||||
new TestHttpResponseStreamWriterFactory(),
|
||||
new CompositeViewEngine(options),
|
||||
new TelemetryListener("Microsoft.AspNet"),
|
||||
new DiagnosticListener("Microsoft.AspNet"),
|
||||
NullLoggerFactory.Instance);
|
||||
#pragma warning restore 0618
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddInstance(viewExecutor);
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
"version": "6.0.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.AspNet.Mvc.TestTelemetryListener.Sources": {
|
||||
"Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources": {
|
||||
"version": "6.0.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||
"Microsoft.Extensions.Logging.Testing": "1.0.0-*",
|
||||
"Microsoft.Extensions.TelemetryAdapter": "1.0.0-*",
|
||||
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
|
||||
"Microsoft.Extensions.WebEncoders.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче