1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

No longer saving download client for entire the life cycle

This commit is contained in:
Mark McDowall 2013-11-19 22:24:45 -08:00
parent e89c337bbe
commit bc0bd647df

View File

@ -21,8 +21,6 @@ public class FailedDownloadService : IFailedDownloadService, IExecute<FailedDown
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly Logger _logger; private readonly Logger _logger;
private readonly IDownloadClient _downloadClient;
private static string DOWNLOAD_CLIENT = "downloadClient"; private static string DOWNLOAD_CLIENT = "downloadClient";
private static string DOWNLOAD_CLIENT_ID = "downloadClientId"; private static string DOWNLOAD_CLIENT_ID = "downloadClientId";
@ -37,8 +35,6 @@ public FailedDownloadService(IProvideDownloadClient downloadClientProvider,
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_configService = configService; _configService = configService;
_logger = logger; _logger = logger;
_downloadClient = _downloadClientProvider.GetDownloadClient();
} }
public void MarkAsFailed(int historyId) public void MarkAsFailed(int historyId)
@ -64,7 +60,7 @@ private void CheckForFailedDownloads()
private void CheckQueue(List<History.History> grabbedHistory, List<History.History> failedHistory) private void CheckQueue(List<History.History> grabbedHistory, List<History.History> failedHistory)
{ {
var downloadClientQueue = _downloadClient.GetQueue().ToList(); var downloadClientQueue = GetDownloadClient().GetQueue().ToList();
var failedItems = downloadClientQueue.Where(q => q.Title.StartsWith("ENCRYPTED / ")).ToList(); var failedItems = downloadClientQueue.Where(q => q.Title.StartsWith("ENCRYPTED / ")).ToList();
if (!failedItems.Any()) if (!failedItems.Any())
@ -96,14 +92,14 @@ private void CheckQueue(List<History.History> grabbedHistory, List<History.Histo
if (_configService.RemoveFailedDownloads) if (_configService.RemoveFailedDownloads)
{ {
_logger.Info("Removing encrypted download from queue: {0}", failedItem.Title.Replace("ENCRYPTED / ", "")); _logger.Info("Removing encrypted download from queue: {0}", failedItem.Title.Replace("ENCRYPTED / ", ""));
_downloadClient.RemoveFromQueue(failedItem.Id); GetDownloadClient().RemoveFromQueue(failedItem.Id);
} }
} }
} }
private void CheckHistory(List<History.History> grabbedHistory, List<History.History> failedHistory) private void CheckHistory(List<History.History> grabbedHistory, List<History.History> failedHistory)
{ {
var downloadClientHistory = _downloadClient.GetHistory(0, 20).ToList(); var downloadClientHistory = GetDownloadClient().GetHistory(0, 20).ToList();
var failedItems = downloadClientHistory.Where(h => h.Status == HistoryStatus.Failed).ToList(); var failedItems = downloadClientHistory.Where(h => h.Status == HistoryStatus.Failed).ToList();
if (!failedItems.Any()) if (!failedItems.Any())
@ -135,7 +131,7 @@ private void CheckHistory(List<History.History> grabbedHistory, List<History.His
if (_configService.RemoveFailedDownloads) if (_configService.RemoveFailedDownloads)
{ {
_logger.Info("Removing failed download from history: {0}", failedItem.Title); _logger.Info("Removing failed download from history: {0}", failedItem.Title);
_downloadClient.RemoveFromHistory(failedItem.Id); GetDownloadClient().RemoveFromHistory(failedItem.Id);
} }
} }
} }
@ -162,6 +158,11 @@ private void PublishDownloadFailedEvent(List<History.History> historyItems, stri
}); });
} }
private IDownloadClient GetDownloadClient()
{
return _downloadClientProvider.GetDownloadClient();
}
public void Execute(FailedDownloadCommand message) public void Execute(FailedDownloadCommand message)
{ {
CheckForFailedDownloads(); CheckForFailedDownloads();