2011-05-11 19:53:19 -07:00
|
|
|
using System;
|
2011-06-13 18:23:04 -07:00
|
|
|
using Ninject;
|
2011-05-11 19:53:19 -07:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.Jobs
|
|
|
|
{
|
|
|
|
public class DeleteSeriesJob : IJob
|
|
|
|
{
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
2011-06-13 18:23:04 -07:00
|
|
|
[Inject]
|
2011-05-15 16:35:45 -07:00
|
|
|
public DeleteSeriesJob(SeriesProvider seriesProvider)
|
2011-05-11 19:53:19 -07:00
|
|
|
{
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "Delete Series"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
{
|
|
|
|
get { return 0; }
|
|
|
|
}
|
|
|
|
|
2011-08-21 17:48:37 -07:00
|
|
|
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
2011-05-11 19:53:19 -07:00
|
|
|
{
|
|
|
|
DeleteSeries(notification, targetId);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeleteSeries(ProgressNotification notification, int seriesId)
|
|
|
|
{
|
|
|
|
Logger.Warn("Deleting Series [{0}]", seriesId);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-05-17 00:04:49 -07:00
|
|
|
var title = _seriesProvider.GetSeries(seriesId).Title;
|
|
|
|
|
|
|
|
notification.CurrentMessage = String.Format("Deleting '{0}' from database", title);
|
2011-05-11 19:53:19 -07:00
|
|
|
|
2011-05-12 17:55:26 -07:00
|
|
|
_seriesProvider.DeleteSeries(seriesId);
|
2011-05-11 19:53:19 -07:00
|
|
|
|
2011-07-05 23:17:21 -07:00
|
|
|
notification.CurrentMessage = String.Format("Successfully deleted '{0}' from database", title);
|
2011-05-11 19:53:19 -07:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.ErrorException("An error has occurred while deleting series: " + seriesId, e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|