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.
76 lines
2.5 KiB
76 lines
2.5 KiB
12 years ago
|
using System;
|
||
14 years ago
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
14 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;
|
||
13 years ago
|
using NzbDrone.Core.Providers;
|
||
12 years ago
|
using NzbDrone.Core.Tv;
|
||
14 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.Jobs.Implementations
|
||
14 years ago
|
{
|
||
14 years ago
|
public class DiskScanJob : IJob
|
||
14 years ago
|
{
|
||
12 years ago
|
private readonly ISeriesService _seriesService;
|
||
14 years ago
|
private readonly DiskScanProvider _diskScanProvider;
|
||
12 years ago
|
private readonly IConfigService _configService;
|
||
12 years ago
|
private readonly ISeriesRepository _seriesRepository;
|
||
14 years ago
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||
14 years ago
|
|
||
12 years ago
|
public DiskScanJob(ISeriesService seriesService, DiskScanProvider diskScanProvider,
|
||
12 years ago
|
IConfigService configService, ISeriesRepository seriesRepository)
|
||
14 years ago
|
{
|
||
12 years ago
|
_seriesService = seriesService;
|
||
14 years ago
|
_diskScanProvider = diskScanProvider;
|
||
12 years ago
|
_configService = configService;
|
||
12 years ago
|
_seriesRepository = seriesRepository;
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
public DiskScanJob()
|
||
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
public string Name
|
||
|
{
|
||
|
get { return "Media File Scan"; }
|
||
|
}
|
||
|
|
||
13 years ago
|
public TimeSpan DefaultInterval
|
||
14 years ago
|
{
|
||
13 years ago
|
get { return TimeSpan.FromHours(6); }
|
||
14 years ago
|
}
|
||
|
|
||
12 years ago
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
||
14 years ago
|
{
|
||
|
IList<Series> seriesToScan;
|
||
12 years ago
|
if (options == null || options.SeriesId == 0)
|
||
14 years ago
|
{
|
||
12 years ago
|
if (_configService.IgnoreArticlesWhenSortingSeries)
|
||
12 years ago
|
seriesToScan = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
||
12 years ago
|
|
||
|
else
|
||
12 years ago
|
seriesToScan = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
||
14 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
seriesToScan = new List<Series>() { _seriesRepository.Get((int)options.SeriesId) };
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
foreach (var series in seriesToScan)
|
||
14 years ago
|
{
|
||
14 years ago
|
try
|
||
|
{
|
||
|
notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title);
|
||
14 years ago
|
_diskScanProvider.Scan(series);
|
||
14 years ago
|
notification.CurrentMessage = string.Format("Disk Scan completed for '{0}'", series.Title);
|
||
14 years ago
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
14 years ago
|
Logger.ErrorException("An error has occurred while scanning " + series.Title, e);
|
||
14 years ago
|
}
|
||
14 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|