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