Updated interface for HttpContextFileExtensions

This commit is contained in:
Jimmy Campbell 2016-11-30 14:51:37 -08:00
Родитель 48906d656f
Коммит 2da7e026c6
4 изменённых файлов: 19 добавлений и 19 удалений

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.IIS.Administration.Files
return NotFound();
}
return Context.GetFileContentHeaders(_fileProvider, _fileProvider.GetFileInfo(dl.PhysicalPath));
return Context.GetFileContentHeaders(dl.PhysicalPath, _fileProvider);
}
[HttpGet]
@ -40,7 +40,7 @@ namespace Microsoft.IIS.Administration.Files
return NotFound();
}
return await Context.GetFileContentAsync(_fileProvider, _fileProvider.GetFileInfo(dl.PhysicalPath));
return await Context.GetFileContentAsync(dl.PhysicalPath, _fileProvider);
}
[HttpDelete]

Просмотреть файл

@ -6,28 +6,27 @@ namespace Microsoft.IIS.Administration.Files
{
using AspNetCore.Http;
using AspNetCore.Mvc;
using System.IO;
using System.Threading.Tasks;
public static class HttpContextFileExtensions
{
public static async Task<IActionResult> GetFileContentAsync(this HttpContext context, IFileProvider fileProvider, FileInfo fileInfo, IHeaderDictionary headers = null)
public static async Task<IActionResult> GetFileContentAsync(this HttpContext context, string filePath, IFileProvider fileProvider, IHeaderDictionary headers = null)
{
var handler = new HttpFileHandler(fileProvider, context, fileInfo, headers);
var handler = new HttpFileHandler(fileProvider, context, filePath, headers);
return await handler.GetFileContent();
}
public static async Task<IActionResult> PutFileContentAsync(this HttpContext context, IFileProvider fileProvider, FileInfo fileInfo, IHeaderDictionary headers = null)
public static async Task<IActionResult> PutFileContentAsync(this HttpContext context, string filePath, IFileProvider fileProvider, IHeaderDictionary headers = null)
{
var handler = new HttpFileHandler(fileProvider, context, fileInfo, headers);
var handler = new HttpFileHandler(fileProvider, context, filePath, headers);
return await handler.PutFileContent();
}
public static IActionResult GetFileContentHeaders(this HttpContext context, IFileProvider fileProvider, FileInfo fileInfo, IHeaderDictionary headers = null)
public static IActionResult GetFileContentHeaders(this HttpContext context, string filePath, IFileProvider fileProvider, IHeaderDictionary headers = null)
{
var handler = new HttpFileHandler(fileProvider, context, fileInfo, headers);
var handler = new HttpFileHandler(fileProvider, context, filePath, headers);
return handler.GetFileContentHeaders();
}

Просмотреть файл

@ -25,7 +25,7 @@ namespace Microsoft.IIS.Administration.Files
private HttpContext _context;
private IHeaderDictionary _customHeaders;
public HttpFileHandler(IFileProvider fileProvider, HttpContext context, FileInfo fileInfo, IHeaderDictionary customHeaders = null)
public HttpFileHandler(IFileProvider fileProvider, HttpContext context, string filePath, IHeaderDictionary customHeaders = null)
{
if (fileProvider == null) {
throw new ArgumentNullException(nameof(fileProvider));
@ -33,14 +33,15 @@ namespace Microsoft.IIS.Administration.Files
if (context == null) {
throw new ArgumentNullException(nameof(context));
}
if (fileInfo == null) {
throw new ArgumentNullException(nameof(fileInfo));
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException(nameof(filePath));
}
this._context = context;
this._file = fileInfo;
this._service = fileProvider;
this._customHeaders = customHeaders;
_context = context;
_service = fileProvider;
_customHeaders = customHeaders;
_file = _service.GetFileInfo(filePath);
}
public async Task<IActionResult> GetFileContent()

Просмотреть файл

@ -38,7 +38,7 @@ namespace Microsoft.IIS.Administration.WebServer.Files
AddHttpLinkHeader(fileId);
return Context.GetFileContentHeaders(_fileService, _fileService.GetFileInfo(physicalPath));
return Context.GetFileContentHeaders(physicalPath, _fileService);
}
@ -59,7 +59,7 @@ namespace Microsoft.IIS.Administration.WebServer.Files
AddHttpLinkHeader(fileId);
return await Context.GetFileContentAsync(_fileService, _fileService.GetFileInfo(physicalPath));
return await Context.GetFileContentAsync(physicalPath, _fileService);
}
[HttpPut]
@ -80,7 +80,7 @@ namespace Microsoft.IIS.Administration.WebServer.Files
AddHttpLinkHeader(fileId);
return await Context.PutFileContentAsync(_fileService, _fileService.GetFileInfo(physicalPath));
return await Context.PutFileContentAsync(physicalPath, _fileService);
}