2013-03-04 21:37:33 -08:00
|
|
|
using System;
|
2011-04-27 23:46:56 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2011-05-23 17:44:44 -07:00
|
|
|
using NLog;
|
2013-02-23 22:48:52 -08:00
|
|
|
using NzbDrone.Core.Configuration;
|
2011-11-21 22:27:08 -08:00
|
|
|
using NzbDrone.Core.Helpers;
|
2011-04-27 23:46:56 -07:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-01 17:33:17 -08:00
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-04 21:37:33 -08:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-04-27 23:46:56 -07:00
|
|
|
|
2013-03-04 21:37:33 -08:00
|
|
|
namespace NzbDrone.Core.Jobs.Implementations
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
2011-05-20 17:23:49 -07:00
|
|
|
public class DiskScanJob : IJob
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
2011-06-19 20:04:08 -07:00
|
|
|
private readonly DiskScanProvider _diskScanProvider;
|
2013-02-23 22:48:52 -08:00
|
|
|
private readonly IConfigService _configService;
|
2013-02-19 18:05:15 -08:00
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2011-05-23 17:44:44 -07:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-27 23:46:56 -07:00
|
|
|
|
2013-03-05 11:58:53 -08:00
|
|
|
public DiskScanJob(DiskScanProvider diskScanProvider,
|
2013-02-23 22:48:52 -08:00
|
|
|
IConfigService configService, ISeriesRepository seriesRepository)
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
2011-06-19 20:04:08 -07:00
|
|
|
_diskScanProvider = diskScanProvider;
|
2013-02-23 22:48:52 -08:00
|
|
|
_configService = configService;
|
2013-02-19 18:05:15 -08:00
|
|
|
_seriesRepository = seriesRepository;
|
2011-04-27 23:46:56 -07:00
|
|
|
}
|
|
|
|
|
2011-05-20 17:23:49 -07:00
|
|
|
public DiskScanJob()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-27 23:46:56 -07:00
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "Media File Scan"; }
|
|
|
|
}
|
|
|
|
|
2012-01-14 18:47:23 -08:00
|
|
|
public TimeSpan DefaultInterval
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
2012-01-14 18:47:23 -08:00
|
|
|
get { return TimeSpan.FromHours(6); }
|
2011-04-27 23:46:56 -07:00
|
|
|
}
|
|
|
|
|
2012-09-10 12:04:17 -07:00
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
|
|
|
IList<Series> seriesToScan;
|
2012-09-10 12:04:17 -07:00
|
|
|
if (options == null || options.SeriesId == 0)
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
2013-02-23 22:48:52 -08:00
|
|
|
if (_configService.IgnoreArticlesWhenSortingSeries)
|
2013-02-19 18:05:15 -08:00
|
|
|
seriesToScan = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
2012-12-20 21:36:48 -08:00
|
|
|
|
|
|
|
else
|
2013-02-19 18:05:15 -08:00
|
|
|
seriesToScan = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
2011-04-27 23:46:56 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-22 15:55:43 -08:00
|
|
|
seriesToScan = new List<Series>() { _seriesRepository.Get((int)options.SeriesId) };
|
2011-04-27 23:46:56 -07:00
|
|
|
}
|
|
|
|
|
2011-06-17 21:08:17 -07:00
|
|
|
foreach (var series in seriesToScan)
|
2011-04-27 23:46:56 -07:00
|
|
|
{
|
2011-05-23 17:44:44 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title);
|
2011-06-19 20:04:08 -07:00
|
|
|
_diskScanProvider.Scan(series);
|
2011-07-05 23:17:21 -07:00
|
|
|
notification.CurrentMessage = string.Format("Disk Scan completed for '{0}'", series.Title);
|
2011-05-23 17:44:44 -07:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2011-07-05 23:17:21 -07:00
|
|
|
Logger.ErrorException("An error has occurred while scanning " + series.Title, e);
|
2011-05-23 17:44:44 -07:00
|
|
|
}
|
2011-04-27 23:46:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|