2013-03-04 21:37:33 -08:00
|
|
|
using System;
|
2012-09-10 12:04:17 -07:00
|
|
|
using System.Collections.Generic;
|
2011-11-25 23:52:54 -08:00
|
|
|
using System.Linq;
|
2011-08-22 22:29:12 -07:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2013-03-04 21:37:33 -08:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-08-22 22:29:12 -07:00
|
|
|
|
2013-03-04 21:37:33 -08:00
|
|
|
namespace NzbDrone.Core.Jobs.Implementations
|
2011-08-22 22:29:12 -07:00
|
|
|
{
|
|
|
|
public class SeriesSearchJob : IJob
|
|
|
|
{
|
2011-08-27 23:37:34 -07:00
|
|
|
private readonly SeasonSearchJob _seasonSearchJob;
|
2013-02-19 18:05:15 -08:00
|
|
|
private readonly ISeasonRepository _seasonRepository;
|
2011-08-22 22:29:12 -07:00
|
|
|
|
2012-02-27 21:50:56 -08:00
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
2011-08-22 22:29:12 -07:00
|
|
|
|
2013-02-19 18:05:15 -08:00
|
|
|
public SeriesSearchJob(SeasonSearchJob seasonSearchJob, ISeasonRepository seasonRepository)
|
2011-08-22 22:29:12 -07:00
|
|
|
{
|
2011-08-27 23:37:34 -07:00
|
|
|
_seasonSearchJob = seasonSearchJob;
|
2013-02-19 18:05:15 -08:00
|
|
|
_seasonRepository = seasonRepository;
|
2011-08-22 22:29:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "Series Search"; }
|
|
|
|
}
|
|
|
|
|
2012-01-14 18:47:23 -08:00
|
|
|
public TimeSpan DefaultInterval
|
2011-08-22 22:29:12 -07:00
|
|
|
{
|
2012-01-14 18:47:23 -08:00
|
|
|
get { return TimeSpan.FromTicks(0); }
|
2011-08-22 22:29:12 -07:00
|
|
|
}
|
|
|
|
|
2012-09-10 12:04:17 -07:00
|
|
|
public void Start(ProgressNotification notification, dynamic options)
|
2011-08-22 22:29:12 -07:00
|
|
|
{
|
2012-09-10 12:04:17 -07:00
|
|
|
if (options == null || options.SeriesId <= 0)
|
|
|
|
throw new ArgumentException("options.SeriesId");
|
2011-08-22 22:29:12 -07:00
|
|
|
|
2012-09-10 12:04:17 -07:00
|
|
|
logger.Debug("Getting seasons from database for series: {0}", options.SeriesId);
|
2013-02-22 15:55:43 -08:00
|
|
|
IList<int> seasons = _seasonRepository.GetSeasonNumbers((int)options.SeriesId);
|
2011-08-22 22:29:12 -07:00
|
|
|
|
2012-09-10 12:04:17 -07:00
|
|
|
foreach (var season in seasons.Where(s => s > 0))
|
2011-08-22 22:29:12 -07:00
|
|
|
{
|
2013-02-22 15:55:43 -08:00
|
|
|
if (!_seasonRepository.IsIgnored((int)options.SeriesId, season))
|
2012-02-27 21:50:56 -08:00
|
|
|
{
|
2012-09-10 12:04:17 -07:00
|
|
|
_seasonSearchJob.Start(notification, new { SeriesId = options.SeriesId, SeasonNumber = season });
|
2012-02-27 21:50:56 -08:00
|
|
|
}
|
2011-08-22 22:29:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|