You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.0 KiB
89 lines
3.0 KiB
12 years ago
|
using System;
|
||
13 years ago
|
using System.Collections.Generic;
|
||
14 years ago
|
using System.Linq;
|
||
13 years ago
|
using NLog;
|
||
12 years ago
|
using NzbDrone.Core.Configuration;
|
||
13 years ago
|
using NzbDrone.Core.Helpers;
|
||
14 years ago
|
using NzbDrone.Core.Model.Notification;
|
||
12 years ago
|
using NzbDrone.Core.ReferenceData;
|
||
|
using NzbDrone.Core.Tv;
|
||
14 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.Jobs.Implementations
|
||
14 years ago
|
{
|
||
|
public class UpdateInfoJob : IJob
|
||
|
{
|
||
12 years ago
|
private readonly ISeriesService _seriesService;
|
||
12 years ago
|
private readonly IEpisodeService _episodeService;
|
||
12 years ago
|
private readonly DailySeriesService _dailySeriesService;
|
||
12 years ago
|
private readonly IConfigService _configService;
|
||
12 years ago
|
private readonly ISeriesRepository _seriesRepository;
|
||
13 years ago
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||
14 years ago
|
|
||
12 years ago
|
public UpdateInfoJob(ISeriesService seriesService, IEpisodeService episodeService,
|
||
12 years ago
|
DailySeriesService dailySeriesService, IConfigService configService, ISeriesRepository seriesRepository)
|
||
14 years ago
|
{
|
||
12 years ago
|
_seriesService = seriesService;
|
||
|
_episodeService = episodeService;
|
||
12 years ago
|
_dailySeriesService = dailySeriesService;
|
||
12 years ago
|
_configService = configService;
|
||
12 years ago
|
_seriesRepository = seriesRepository;
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
public UpdateInfoJob()
|
||
|
{
|
||
14 years ago
|
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
public string Name
|
||
|
{
|
||
14 years ago
|
get { return "Update Episode Info"; }
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
public TimeSpan DefaultInterval
|
||
14 years ago
|
{
|
||
13 years ago
|
get { return TimeSpan.FromHours(12); }
|
||
14 years ago
|
}
|
||
|
|
||
12 years ago
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
||
14 years ago
|
{
|
||
12 years ago
|
IList<Series> ListOfSeriesToUpdate;
|
||
12 years ago
|
if (options == null || options.SeriesId == 0)
|
||
14 years ago
|
{
|
||
12 years ago
|
if (_configService.IgnoreArticlesWhenSortingSeries)
|
||
12 years ago
|
ListOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
||
12 years ago
|
|
||
|
else
|
||
12 years ago
|
ListOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
||
14 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
ListOfSeriesToUpdate = new List<Series>
|
||
12 years ago
|
{
|
||
|
_seriesRepository.Get((int)options.SeriesId)
|
||
|
};
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
//Update any Daily Series in the DB with the IsDaily flag
|
||
12 years ago
|
_dailySeriesService.UpdateDailySeries();
|
||
13 years ago
|
|
||
12 years ago
|
foreach (var seriesToUpdate in ListOfSeriesToUpdate)
|
||
14 years ago
|
{
|
||
12 years ago
|
var series = seriesToUpdate;
|
||
|
|
||
13 years ago
|
try
|
||
|
{
|
||
|
notification.CurrentMessage = "Updating " + series.Title;
|
||
12 years ago
|
series = _seriesService.UpdateSeriesInfo(series.Id);
|
||
12 years ago
|
_episodeService.RefreshEpisodeInfo(series);
|
||
13 years ago
|
notification.CurrentMessage = "Update completed for " + series.Title;
|
||
|
}
|
||
|
|
||
12 years ago
|
catch (Exception ex)
|
||
13 years ago
|
{
|
||
|
Logger.ErrorException("Failed to update episode info for series: " + series.Title, ex);
|
||
|
}
|
||
12 years ago
|
|
||
14 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|