-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worker.cs
41 lines (39 loc) · 1.52 KB
/
Worker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
namespace FileManager
{
public class Worker : BackgroundService
{
private readonly string[] softDirectories;
private readonly string[] hardDirectories;
private readonly FileCleanUpService cleanUpService;
public Worker(HostBuilderContext targetPath)
{
softDirectories = targetPath.Configuration.GetSection("Application:SoftDirs").Get<string[]>();
hardDirectories = targetPath.Configuration.GetSection("Application:HardDirs").Get<string[]>();
cleanUpService = new FileCleanUpService(
new ISoftRule[]
{
new DocumentRule(targetPath.Configuration.GetSection("Application:DocumentsDir").Value),
new ImageRule(targetPath.Configuration.GetSection("Application:ImagesDir").Value),
new LinkRule(),
},
new IHardRule[]
{
new DeleteUntouchedFilesFromDownloadFolderRule()
}
);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
cleanUpService.SoftCleanUp(softDirectories);
cleanUpService.HardCleanUp(hardDirectories);
await Task.Delay(3600, stoppingToken);
}
}
}
}