2011-12-02 01:33:17 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
using NLog;
|
2012-09-04 00:51:07 +00:00
|
|
|
|
using NzbDrone.Common;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
2011-12-02 01:33:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-05-12 02:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
public class DeleteSeriesJob : IJob
|
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
private readonly ISeriesService _seriesService;
|
2012-09-04 06:49:04 +00:00
|
|
|
|
private readonly RecycleBinProvider _recycleBinProvider;
|
2013-02-20 02:05:15 +00:00
|
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public DeleteSeriesJob(ISeriesService seriesService, RecycleBinProvider recycleBinProvider, ISeriesRepository seriesRepository)
|
2011-05-12 02:53:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
_seriesService = seriesService;
|
2012-09-04 06:49:04 +00:00
|
|
|
|
_recycleBinProvider = recycleBinProvider;
|
2013-02-20 02:05:15 +00:00
|
|
|
|
_seriesRepository = seriesRepository;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Delete Series"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 02:47:23 +00:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-05-12 02:53:19 +00:00
|
|
|
|
{
|
2012-01-15 02:47:23 +00:00
|
|
|
|
get { return TimeSpan.FromTicks(0); }
|
2011-05-12 02:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
public void Start(ProgressNotification notification, dynamic options)
|
2011-05-12 02:53:19 +00:00
|
|
|
|
{
|
2012-10-23 15:18:28 +00:00
|
|
|
|
if (options == null)
|
|
|
|
|
throw new ArgumentNullException("options");
|
|
|
|
|
|
|
|
|
|
if (options.SeriesId == 0)
|
|
|
|
|
throw new ArgumentNullException("options.SeriesId");
|
|
|
|
|
|
|
|
|
|
DeleteSeries(notification, options.SeriesId, options.DeleteFiles);
|
2011-05-12 02:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 00:51:07 +00:00
|
|
|
|
private void DeleteSeries(ProgressNotification notification, int seriesId, bool deleteFiles)
|
2011-05-12 02:53:19 +00:00
|
|
|
|
{
|
2012-02-25 02:01:53 +00:00
|
|
|
|
Logger.Trace("Deleting Series [{0}]", seriesId);
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
var series = _seriesRepository.Get(seriesId);
|
2012-09-04 00:51:07 +00:00
|
|
|
|
var title = series.Title;
|
2011-05-17 07:04:49 +00:00
|
|
|
|
|
2012-02-25 02:01:53 +00:00
|
|
|
|
notification.CurrentMessage = String.Format("Deleting '{0}' from database", title);
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
_seriesRepository.Delete(seriesId);
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
2012-02-25 02:01:53 +00:00
|
|
|
|
notification.CurrentMessage = String.Format("Successfully deleted '{0}' from database", title);
|
2012-09-04 00:51:07 +00:00
|
|
|
|
|
|
|
|
|
if (deleteFiles)
|
|
|
|
|
{
|
|
|
|
|
notification.CurrentMessage = String.Format("Deleting files from disk for series '{0}'", title);
|
|
|
|
|
|
2012-09-04 06:49:04 +00:00
|
|
|
|
_recycleBinProvider.DeleteDirectory(series.Path);
|
2012-09-04 00:51:07 +00:00
|
|
|
|
|
|
|
|
|
notification.CurrentMessage = String.Format("Successfully deleted files from disk for series '{0}'", title);
|
|
|
|
|
}
|
2011-05-12 02:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|