1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00
Radarr/NzbDrone.Core/Jobs/DeleteSeriesJob.cs

67 lines
2.1 KiB
C#
Raw Normal View History

2011-12-02 02:33:17 +01:00
using System.Linq;
using System;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Model.Notification;
2011-12-02 02:33:17 +01:00
using NzbDrone.Core.Providers;
2011-12-02 02:33:17 +01:00
namespace NzbDrone.Core.Jobs
{
public class DeleteSeriesJob : IJob
{
private readonly SeriesProvider _seriesProvider;
private readonly RecycleBinProvider _recycleBinProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public DeleteSeriesJob(SeriesProvider seriesProvider, RecycleBinProvider recycleBinProvider)
{
_seriesProvider = seriesProvider;
_recycleBinProvider = recycleBinProvider;
}
public string Name
{
get { return "Delete Series"; }
}
public TimeSpan DefaultInterval
{
get { return TimeSpan.FromTicks(0); }
}
2012-09-10 21:04:17 +02:00
public void Start(ProgressNotification notification, dynamic options)
{
2012-10-23 17:18:28 +02:00
if (options == null)
throw new ArgumentNullException("options");
if (options.SeriesId == 0)
throw new ArgumentNullException("options.SeriesId");
DeleteSeries(notification, options.SeriesId, options.DeleteFiles);
}
private void DeleteSeries(ProgressNotification notification, int seriesId, bool deleteFiles)
{
Logger.Trace("Deleting Series [{0}]", seriesId);
var series = _seriesProvider.GetSeries(seriesId);
var title = series.Title;
notification.CurrentMessage = String.Format("Deleting '{0}' from database", title);
_seriesProvider.DeleteSeries(seriesId);
notification.CurrentMessage = String.Format("Successfully deleted '{0}' from database", title);
if (deleteFiles)
{
notification.CurrentMessage = String.Format("Deleting files from disk for series '{0}'", title);
_recycleBinProvider.DeleteDirectory(series.Path);
notification.CurrentMessage = String.Format("Successfully deleted files from disk for series '{0}'", title);
}
}
}
}