44// Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 55
66using Longbow . Tasks ;
7- using Microsoft . Extensions . Options ;
87
98namespace BootstrapBlazor . Service . Services ;
109
1110/// <summary>
1211/// 后台任务服务类
1312/// </summary>
14- internal class ClearTempFilesService : BackgroundService
13+ internal class ClearTempFilesService ( IWebHostEnvironment env ) : BackgroundService
1514{
16- private readonly IWebHostEnvironment _env ;
17-
18- /// <summary>
19- ///
20- /// </summary>
21- /// <param name="env"></param>
22- /// <param name="websiteOption"></param>
23- public ClearTempFilesService ( IWebHostEnvironment env , IOptionsMonitor < WebsiteOptions > websiteOption )
24- {
25- _env = env ;
26- websiteOption . CurrentValue . WebRootPath = env . WebRootPath ;
27- websiteOption . CurrentValue . ContentRootPath = env . ContentRootPath ;
28- websiteOption . CurrentValue . IsDevelopment = env . IsDevelopment ( ) ;
29- }
30-
3115 /// <summary>
3216 /// 运行任务
3317 /// </summary>
@@ -37,14 +21,14 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
3721 {
3822 TaskServicesManager . GetOrAdd ( "Clear Upload Files" , ( provider , token ) =>
3923 {
40- var filePath = Path . Combine ( _env . WebRootPath , "images" , "uploader" ) ;
24+ var filePath = Path . Combine ( env . WebRootPath , "images" , "uploader" ) ;
4125 if ( Directory . Exists ( filePath ) )
4226 {
4327 Directory . EnumerateFiles ( filePath ) . Take ( 10 ) . ToList ( ) . ForEach ( file => DeleteFile ( file , token ) ) ;
4428 }
4529
4630 // 清除导出临时文件
47- var exportFilePath = Path . Combine ( _env . WebRootPath , "pdf" ) ;
31+ var exportFilePath = Path . Combine ( env . WebRootPath , "pdf" ) ;
4832 if ( Directory . Exists ( exportFilePath ) )
4933 {
5034 Directory . EnumerateFiles ( exportFilePath , "*.html" ) . Take ( 10 ) . Where ( file =>
0 commit comments