-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
DownloadProcessingService.cs
62 lines (56 loc) · 2.58 KB
/
DownloadProcessingService.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Download
{
public class DownloadProcessingService : IExecute<ProcessMonitoredDownloadsCommand>
{
private readonly IConfigService _configService;
private readonly ICompletedDownloadService _completedDownloadService;
private readonly IFailedDownloadService _failedDownloadService;
private readonly ITrackedDownloadService _trackedDownloadService;
private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
public DownloadProcessingService(IConfigService configService,
ICompletedDownloadService completedDownloadService,
IFailedDownloadService failedDownloadService,
ITrackedDownloadService trackedDownloadService,
IEventAggregator eventAggregator,
Logger logger)
{
_configService = configService;
_completedDownloadService = completedDownloadService;
_failedDownloadService = failedDownloadService;
_trackedDownloadService = trackedDownloadService;
_eventAggregator = eventAggregator;
_logger = logger;
}
public void Execute(ProcessMonitoredDownloadsCommand message)
{
var enableCompletedDownloadHandling = _configService.EnableCompletedDownloadHandling;
var trackedDownloads = _trackedDownloadService.GetTrackedDownloads();
foreach (var trackedDownload in trackedDownloads)
{
try
{
if (trackedDownload.State == TrackedDownloadState.DownloadFailedPending)
{
_failedDownloadService.ProcessFailed(trackedDownload);
}
if (enableCompletedDownloadHandling && trackedDownload.State == TrackedDownloadState.ImportPending)
{
_completedDownloadService.Import(trackedDownload);
}
}
catch (Exception e)
{
_logger.Debug(e, "Failed to process download: {0}", trackedDownload.DownloadItem.Title);
}
}
_eventAggregator.PublishEvent(new DownloadsProcessedEvent());
}
}
}