Make our executor methods virtual
Fixes #5874 - we are marking these methods virtual just in case someone wants to customize the executors. These are in the 'public internal' namespace but can't really be replaced because they aren't sufficiently virtual.
This commit is contained in:
parent
af7303cd8d
commit
4d905a4110
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_httpResponseStreamWriterFactory = httpResponseStreamWriterFactory;
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync(ActionContext context, ContentResult result)
|
||||
public virtual async Task ExecuteAsync(ActionContext context, ContentResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -13,14 +14,34 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
{
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(ActionContext context, FileContentResult result)
|
||||
public virtual Task ExecuteAsync(ActionContext context, FileContentResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
SetHeadersAndLog(context, result);
|
||||
return WriteFileAsync(context, result);
|
||||
}
|
||||
|
||||
private static Task WriteFileAsync(ActionContext context, FileContentResult result)
|
||||
protected virtual Task WriteFileAsync(ActionContext context, FileContentResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var response = context.HttpContext.Response;
|
||||
|
||||
return response.Body.WriteAsync(result.FileContents, offset: 0, count: result.FileContents.Length);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
|
||||
protected ILogger Logger { get; }
|
||||
|
||||
protected void SetHeadersAndLog(ActionContext context, FileResult result)
|
||||
protected virtual void SetHeadersAndLog(ActionContext context, FileResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
SetContentType(context, result);
|
||||
SetContentDispositionHeader(context, result);
|
||||
Logger.FileResultExecuting(result.FileDownloadName);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -16,14 +17,34 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
{
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(ActionContext context, FileStreamResult result)
|
||||
public virtual Task ExecuteAsync(ActionContext context, FileStreamResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
SetHeadersAndLog(context, result);
|
||||
return WriteFileAsync(context, result);
|
||||
}
|
||||
|
||||
private static async Task WriteFileAsync(ActionContext context, FileStreamResult result)
|
||||
protected virtual async Task WriteFileAsync(ActionContext context, FileStreamResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var response = context.HttpContext.Response;
|
||||
var outputStream = response.Body;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_urlHelperFactory = urlHelperFactory;
|
||||
}
|
||||
|
||||
public void Execute(ActionContext context, LocalRedirectResult result)
|
||||
public virtual void Execute(ActionContext context, LocalRedirectResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context);
|
||||
|
||||
// IsLocalUrl is called to handle Urls starting with '~/'.
|
||||
|
|
|
|||
|
|
@ -20,14 +20,34 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
{
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(ActionContext context, PhysicalFileResult result)
|
||||
public virtual Task ExecuteAsync(ActionContext context, PhysicalFileResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
SetHeadersAndLog(context, result);
|
||||
return WriteFileAsync(context, result);
|
||||
}
|
||||
|
||||
private async Task WriteFileAsync(ActionContext context, PhysicalFileResult result)
|
||||
protected virtual async Task WriteFileAsync(ActionContext context, PhysicalFileResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var response = context.HttpContext.Response;
|
||||
|
||||
if (!Path.IsPathRooted(result.FileName))
|
||||
|
|
|
|||
|
|
@ -30,8 +30,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_urlHelperFactory = urlHelperFactory;
|
||||
}
|
||||
|
||||
public void Execute(ActionContext context, RedirectResult result)
|
||||
public virtual void Execute(ActionContext context, RedirectResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context);
|
||||
|
||||
// IsLocalUrl is called to handle URLs starting with '~/'.
|
||||
|
|
|
|||
|
|
@ -31,8 +31,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_urlHelperFactory = urlHelperFactory;
|
||||
}
|
||||
|
||||
public void Execute(ActionContext context, RedirectToActionResult result)
|
||||
public virtual void Execute(ActionContext context, RedirectToActionResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context);
|
||||
|
||||
var destinationUrl = urlHelper.Action(
|
||||
|
|
|
|||
|
|
@ -31,8 +31,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_urlHelperFactory = urlHelperFactory;
|
||||
}
|
||||
|
||||
public void Execute(ActionContext context, RedirectToPageResult result)
|
||||
public virtual void Execute(ActionContext context, RedirectToPageResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context);
|
||||
var destinationUrl = urlHelper.Page(
|
||||
result.PageName,
|
||||
|
|
|
|||
|
|
@ -29,14 +29,34 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(ActionContext context, VirtualFileResult result)
|
||||
public virtual Task ExecuteAsync(ActionContext context, VirtualFileResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
SetHeadersAndLog(context, result);
|
||||
return WriteFileAsync(context, result);
|
||||
}
|
||||
|
||||
private async Task WriteFileAsync(ActionContext context, VirtualFileResult result)
|
||||
protected virtual async Task WriteFileAsync(ActionContext context, VirtualFileResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var response = context.HttpContext.Response;
|
||||
var fileProvider = GetFileProvider(result);
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
|||
/// <param name="context">The <see cref="ActionContext"/>.</param>
|
||||
/// <param name="result">The <see cref="JsonResult"/>.</param>
|
||||
/// <returns>A <see cref="Task"/> which will complete when writing has completed.</returns>
|
||||
public Task ExecuteAsync(ActionContext context, JsonResult result)
|
||||
public virtual Task ExecuteAsync(ActionContext context, JsonResult result)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -49,6 +50,16 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
/// </summary>
|
||||
public virtual Task ExecuteAsync(PageContext pageContext, PageResult result)
|
||||
{
|
||||
if (pageContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pageContext));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
if (result.Model != null)
|
||||
{
|
||||
pageContext.ViewData.Model = result.Model;
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
|
|
|||
|
|
@ -63,8 +63,18 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
_tempDataDictionaryFactory = tempDataDictionaryFactory;
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync(ActionContext context, ViewComponentResult viewComponentResult)
|
||||
public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResult viewComponentResult)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (viewComponentResult == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(viewComponentResult));
|
||||
}
|
||||
|
||||
var response = context.HttpContext.Response;
|
||||
|
||||
var viewData = viewComponentResult.ViewData;
|
||||
|
|
|
|||
Loading…
Reference in New Issue