Suppress [Obsolete] warnings from DiagnosticSource

This commit is contained in:
Ryan Nowak 2015-10-08 12:47:08 -07:00
parent 91cb6281e4
commit 9342cb0ab7
14 changed files with 68 additions and 10 deletions

View File

@ -23,7 +23,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,
@ -129,6 +129,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
"descriptor");
}
}
#pragma warning disable 0618
protected override object CreateInstance()
{

View File

@ -18,6 +18,7 @@ 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;
@ -53,6 +54,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
_logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
_telemetry = telemetry;
}
#pragma warning restore 0618
public int Order
{

View File

@ -31,7 +31,9 @@ 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 int _maxModelValidationErrors;
private IFilterMetadata[] _filters;
@ -61,6 +63,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
private const string ResultFilterShortCircuitLogMessage =
"Request was short circuited at result filter '{ResultFilter}'.";
#pragma warning disable 0618
public FilterActionInvoker(
ActionContext actionContext,
IReadOnlyList<IFilterProvider> filterProviders,
@ -137,6 +140,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
_telemetry = telemetry;
_maxModelValidationErrors = maxModelValidationErrors;
}
#pragma warning restore 0618
protected ActionContext ActionContext { get; private set; }
@ -652,6 +656,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
try
{
#pragma warning disable 0618
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionMethod"))
{
_telemetry.WriteTelemetry(
@ -663,11 +668,13 @@ 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"))
{
_telemetry.WriteTelemetry(
@ -680,6 +687,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
result = result
});
}
#pragma warning restore 0618
}
_actionExecutedContext = new ActionExecutedContext(
@ -827,12 +835,14 @@ namespace Microsoft.AspNet.Mvc.Controllers
private async Task InvokeResultAsync(IActionResult result)
{
#pragma warning disable 0618
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionResult"))
{
_telemetry.WriteTelemetry(
"Microsoft.AspNet.Mvc.BeforeActionResult",
new { actionContext = ActionContext, result = result });
}
#pragma warning restore 0618
try
{
@ -840,12 +850,14 @@ namespace Microsoft.AspNet.Mvc.Controllers
}
finally
{
#pragma warning disable 0618
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterActionResult"))
{
_telemetry.WriteTelemetry(
"Microsoft.AspNet.Mvc.AfterActionResult",
new { actionContext = ActionContext, result = result });
}
#pragma warning restore 0618
}
}

View File

@ -20,7 +20,9 @@ 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
public VirtualPathData GetVirtualPath(VirtualPathContext context)
{
@ -80,12 +82,14 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{
context.RouteData = newRouteData;
#pragma warning disable 0618
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeAction"))
{
_telemetry.WriteTelemetry(
"Microsoft.AspNet.Mvc.BeforeAction",
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData });
}
#pragma warning restore 0618
using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id))
{
@ -97,12 +101,14 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
}
finally
{
#pragma warning disable 0618
if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterAction"))
{
_telemetry.WriteTelemetry(
"Microsoft.AspNet.Mvc.AfterAction",
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData });
}
#pragma warning restore 0618
if (!context.IsHandled)
{
@ -150,10 +156,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
_logger = factory.CreateLogger<MvcRouteHandler>();
}
#pragma warning disable 0618
if (_telemetry == null)
{
_telemetry = context.RequestServices.GetRequiredService<TelemetrySource>();
}
#pragma warning restore 0618
}
}
}

View File

@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </summary>
public class PartialViewResultExecutor : ViewExecutor
{
#pragma warning disable 0618
/// <summary>
/// Creates a new <see cref="PartialViewResultExecutor"/>.
/// </summary>
@ -39,6 +40,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Logger = loggerFactory.CreateLogger<PartialViewResultExecutor>();
}
#pragma warning restore 0618
/// <summary>
/// Gets the <see cref="ILogger"/>.
@ -69,6 +71,7 @@ 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"))
{
Telemetry.WriteTelemetry(
@ -82,11 +85,12 @@ 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"))
{
Telemetry.WriteTelemetry(
@ -100,6 +104,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
searchedLocations = result.SearchedLocations
});
}
#pragma warning restore 0618
Logger.LogError(
"The partial view '{PartialViewName}' was not found. Searched locations: {SearchedViewLocations}",

View File

@ -26,6 +26,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Encoding = Encoding.UTF8
}.CopyAsReadOnly();
#pragma warning disable 0618
/// <summary>
/// Creates a new <see cref="ViewExecutor"/>.
/// </summary>
@ -69,6 +70,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// Gets the <see cref="TelemetrySource"/>.
/// </summary>
protected TelemetrySource Telemetry { get; }
#pragma warning restore 0618
/// <summary>
/// Gets the default <see cref="IViewEngine"/>.
@ -158,21 +160,25 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
writer,
ViewOptions.HtmlHelperOptions);
#pragma warning disable 0618
if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeView"))
{
Telemetry.WriteTelemetry(
"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"))
{
Telemetry.WriteTelemetry(
"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

View File

@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </summary>
public class ViewResultExecutor : ViewExecutor
{
#pragma warning disable 0618
/// <summary>
/// Creates a new <see cref="ViewResultExecutor"/>.
/// </summary>
@ -39,6 +40,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Logger = loggerFactory.CreateLogger<ViewResultExecutor>();
}
#pragma warning restore 0618
/// <summary>
/// Gets the <see cref="ILogger"/>.
@ -69,6 +71,7 @@ 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"))
{
Telemetry.WriteTelemetry(
@ -82,11 +85,13 @@ 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"))
{
Telemetry.WriteTelemetry(
@ -100,6 +105,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
searchedLocations = result.SearchedLocations
});
}
#pragma warning restore 0618
Logger.LogError(
"The view '{ViewName}' was not found. Searched locations: {SearchedViewLocations}",

View File

@ -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 },
@ -2057,7 +2057,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
new TelemetryListener("Microsoft.AspNet"),
maxAllowedErrorsInModelState);
#pragma warning restore 0618
return invoker;
}
@ -2101,6 +2101,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>(),
@ -2118,6 +2119,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
new TelemetryListener("Microsoft.AspNet"),
200);
#pragma warning restore 0618
// Act
await invoker.InvokeAsync();
@ -2204,6 +2206,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
private class TestControllerActionInvoker : ControllerActionInvoker
{
#pragma warning disable 0618
public TestControllerActionInvoker(
ActionContext actionContext,
IFilterProvider[] filterProvider,
@ -2237,6 +2240,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
{
ControllerFactory = controllerFactory;
}
#pragma warning restore 0618
public MockControllerFactory ControllerFactory { get; }

View File

@ -242,13 +242,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{
optionsAccessor = new TestOptionsManager<MvcOptions>();
}
#pragma warning disable 0618
var telemetry = new TelemetryListener("Microsoft.AspNet");
if (telemetryListener != null)
{
telemetry.SubscribeWithAdapter(telemetryListener);
}
#pragma warning restore 0618
var httpContext = new Mock<HttpContext>();
httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor)))
.Returns(new ActionContextAccessor());
@ -262,9 +262,10 @@ 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
return new RouteContext(httpContext.Object);
}
}

View File

@ -105,12 +105,14 @@ 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"),
NullLoggerFactory.Instance);
#pragma warning restore 0618
var services = new ServiceCollection();
services.AddInstance(viewExecutor);

View File

@ -71,6 +71,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Assert.Equal(viewName, viewEngineResult.ViewName);
}
#pragma warning disable 0618
[Fact]
public void FindView_Notifies_ViewFound()
{
@ -141,6 +142,7 @@ 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()
@ -200,6 +202,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
}
#pragma warning disable 0618
private PartialViewResultExecutor GetViewExecutor(TelemetrySource telemetry = null)
{
if (telemetry == null)
@ -224,6 +227,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return viewExecutor;
}
#pragma warning restore 0618
}
}
#endif

View File

@ -146,7 +146,7 @@ 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()
{
@ -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,7 +277,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return view.Object;
}
#pragma warning disable 0618
private ViewExecutor CreateViewExecutor(TelemetryListener listener = null)
{
if (listener == null)
@ -291,6 +291,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
listener);
}
#pragma warning restore 0618
}
}
#endif

View File

@ -71,6 +71,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Assert.Equal(viewName, viewEngineResult.ViewName);
}
#pragma warning disable 0618
[Fact]
public void FindView_Notifies_ViewFound()
{
@ -141,6 +142,7 @@ 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()
@ -200,6 +202,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
}
#pragma warning disable 0618
private ViewResultExecutor GetViewExecutor(TelemetrySource telemetry = null)
{
if (telemetry == null)
@ -224,6 +227,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return viewExecutor;
}
#pragma warning restore 0618
}
}
#endif

View File

@ -105,12 +105,14 @@ 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"),
NullLoggerFactory.Instance);
#pragma warning restore 0618
var services = new ServiceCollection();
services.AddInstance(viewExecutor);