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