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.
Readarr/NzbDrone.Core/Jobs/DeleteSeriesJob.cs

63 lines
1.9 KiB

using System.Linq;
using System;
using Ninject;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
namespace NzbDrone.Core.Jobs
{
public class DeleteSeriesJob : IJob
{
private readonly SeriesProvider _seriesProvider;
private readonly RecycleBinProvider _recycleBinProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
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); }
}
public void Start(ProgressNotification notification, dynamic options)
{
DeleteSeries(notification, options.SeriesId, options.DeleteFiless);
}
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);
}
}
}
}