2013-10-23 09:36:31 +03:00
|
|
|
using System;
|
2014-02-02 01:07:30 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-10-23 09:36:31 +03:00
|
|
|
using NzbDrone.Core.Download;
|
2014-02-02 01:07:30 +03:00
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
2013-10-23 09:36:31 +03:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Blacklisting
|
|
|
|
{
|
|
|
|
public interface IBlacklistService
|
|
|
|
{
|
|
|
|
bool Blacklisted(string sourceTitle);
|
2014-02-02 01:07:30 +03:00
|
|
|
PagingSpec<Blacklist> Paged(PagingSpec<Blacklist> pagingSpec);
|
|
|
|
void Delete(int id);
|
2013-10-23 09:36:31 +03:00
|
|
|
}
|
|
|
|
|
2014-02-02 01:07:30 +03:00
|
|
|
public class BlacklistService : IBlacklistService, IHandle<DownloadFailedEvent>, IExecute<ClearBlacklistCommand>
|
2013-10-23 09:36:31 +03:00
|
|
|
{
|
|
|
|
private readonly IBlacklistRepository _blacklistRepository;
|
2013-10-24 08:13:04 +03:00
|
|
|
private readonly IRedownloadFailedDownloads _redownloadFailedDownloadService;
|
2013-10-23 09:36:31 +03:00
|
|
|
|
2013-10-24 08:13:04 +03:00
|
|
|
public BlacklistService(IBlacklistRepository blacklistRepository, IRedownloadFailedDownloads redownloadFailedDownloadService)
|
2013-10-23 09:36:31 +03:00
|
|
|
{
|
|
|
|
_blacklistRepository = blacklistRepository;
|
2013-10-24 08:13:04 +03:00
|
|
|
_redownloadFailedDownloadService = redownloadFailedDownloadService;
|
2013-10-23 09:36:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool Blacklisted(string sourceTitle)
|
|
|
|
{
|
|
|
|
return _blacklistRepository.Blacklisted(sourceTitle);
|
|
|
|
}
|
|
|
|
|
2014-02-02 01:07:30 +03:00
|
|
|
public PagingSpec<Blacklist> Paged(PagingSpec<Blacklist> pagingSpec)
|
|
|
|
{
|
|
|
|
return _blacklistRepository.GetPaged(pagingSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
{
|
|
|
|
_blacklistRepository.Delete(id);
|
|
|
|
}
|
|
|
|
|
2013-10-23 09:36:31 +03:00
|
|
|
public void Handle(DownloadFailedEvent message)
|
|
|
|
{
|
|
|
|
var blacklist = new Blacklist
|
|
|
|
{
|
2013-10-24 08:13:04 +03:00
|
|
|
SeriesId = message.SeriesId,
|
|
|
|
EpisodeIds = message.EpisodeIds,
|
2013-10-23 09:36:31 +03:00
|
|
|
SourceTitle = message.SourceTitle,
|
|
|
|
Quality = message.Quality,
|
|
|
|
Date = DateTime.UtcNow
|
|
|
|
};
|
|
|
|
|
|
|
|
_blacklistRepository.Insert(blacklist);
|
2013-10-24 08:13:04 +03:00
|
|
|
|
|
|
|
_redownloadFailedDownloadService.Redownload(message.SeriesId, message.EpisodeIds);
|
2013-10-23 09:36:31 +03:00
|
|
|
}
|
2014-02-02 01:07:30 +03:00
|
|
|
|
|
|
|
public void Execute(ClearBlacklistCommand message)
|
|
|
|
{
|
|
|
|
_blacklistRepository.Purge();
|
|
|
|
}
|
2013-10-23 09:36:31 +03:00
|
|
|
}
|
|
|
|
}
|