using Masuit.Tools.Mime;
using Masuit.Tools.AspNetCore.ResumeFileResults.ResumeFileResult;
using Microsoft.AspNetCore.Mvc;
using System.IO;
namespace Masuit.Tools.AspNetCore.ResumeFileResults.Extensions
{
///
/// Controller扩展方法
///
public static class ControllerExtensions
{
private static readonly IMimeMapper _mimeMapper = new MimeMapper();
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 文件二进制流
/// Content-Type
/// 下载的文件名
///
public static ResumeFileContentResult ResumeFile(this ControllerBase controller, byte[] fileContents, string contentType, string fileDownloadName)
{
return ResumeFile(controller, fileContents, contentType, fileDownloadName, null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 文件二进制流
/// 下载的文件名
///
public static ResumeFileContentResult ResumeFile(this ControllerBase controller, byte[] fileContents, string fileDownloadName)
{
return ResumeFile(controller, fileContents, _mimeMapper.GetMimeFromPath(fileDownloadName), fileDownloadName, null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 文件二进制流
/// Content-Type
/// 下载的文件名
/// ETag
///
public static ResumeFileContentResult ResumeFile(this ControllerBase controller, byte[] fileContents, string contentType, string fileDownloadName, string etag)
{
return new ResumeFileContentResult(fileContents, contentType, etag)
{
FileDownloadName = fileDownloadName
};
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 文件二进制流
/// Content-Type
/// 下载的文件名
///
public static ResumeFileStreamResult ResumeFile(this ControllerBase controller, FileStream fileStream, string contentType, string fileDownloadName)
{
return ResumeFile(controller, fileStream, contentType, fileDownloadName, null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 文件二进制流
/// 下载的文件名
///
public static ResumeFileStreamResult ResumeFile(this ControllerBase controller, FileStream fileStream, string fileDownloadName)
{
return ResumeFile(controller, fileStream, _mimeMapper.GetMimeFromPath(fileDownloadName), fileDownloadName, null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 文件二进制流
/// Content-Type
/// 下载的文件名
/// ETag
///
public static ResumeFileStreamResult ResumeFile(this ControllerBase controller, FileStream fileStream, string contentType, string fileDownloadName, string etag)
{
return new ResumeFileStreamResult(fileStream, contentType, etag)
{
FileDownloadName = fileDownloadName
};
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 服务端本地文件的虚拟路径
/// Content-Type
/// 下载的文件名
///
public static ResumeVirtualFileResult ResumeFile(this ControllerBase controller, string virtualPath, string contentType, string fileDownloadName)
{
return ResumeFile(controller, virtualPath, contentType, fileDownloadName, null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 服务端本地文件的虚拟路径
/// 下载的文件名
///
public static ResumeVirtualFileResult ResumeFile(this ControllerBase controller, string virtualPath, string fileDownloadName)
{
return ResumeFile(controller, virtualPath, _mimeMapper.GetMimeFromPath(virtualPath), fileDownloadName, null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 服务端本地文件的虚拟路径
/// Content-Type
/// 下载的文件名
/// ETag
///
public static ResumeVirtualFileResult ResumeFile(this ControllerBase controller, string virtualPath, string contentType, string fileDownloadName, string etag)
{
return new ResumeVirtualFileResult(virtualPath, contentType, etag)
{
FileDownloadName = fileDownloadName
};
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 服务端本地文件的物理路径
/// Content-Type
/// 下载的文件名
///
public static ResumePhysicalFileResult ResumePhysicalFile(this ControllerBase controller, string physicalPath, string contentType, string fileDownloadName)
{
return ResumePhysicalFile(controller, physicalPath, contentType, fileDownloadName, etag: null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 服务端本地文件的物理路径
/// 下载的文件名
///
public static ResumePhysicalFileResult ResumePhysicalFile(this ControllerBase controller, string physicalPath, string fileDownloadName)
{
return ResumePhysicalFile(controller, physicalPath, _mimeMapper.GetMimeFromPath(physicalPath), fileDownloadName, etag: null);
}
///
/// 可断点续传和多线程下载的FileResult
///
///
/// 服务端本地文件的物理路径
/// Content-Type
/// 下载的文件名
/// ETag
///
public static ResumePhysicalFileResult ResumePhysicalFile(this ControllerBase controller, string physicalPath, string contentType, string fileDownloadName, string etag)
{
return new ResumePhysicalFileResult(physicalPath, contentType, etag)
{
FileDownloadName = fileDownloadName
};
}
}
}