|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Ninject;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers.ExternalNotification;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using PetaPoco;
|
|
|
|
@ -13,10 +15,13 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public ExternalNotificationProvider(IDatabase database)
|
|
|
|
|
private IEnumerable<ExternalNotificationBase> _notifiers;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public ExternalNotificationProvider(IDatabase database, IEnumerable<ExternalNotificationBase> notifiers)
|
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
_notifiers = notifiers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ExternalNotificationProvider()
|
|
|
|
@ -24,51 +29,54 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual List<ExternalNotificationSetting> All()
|
|
|
|
|
public virtual List<ExternalNotificationDefinition> All()
|
|
|
|
|
{
|
|
|
|
|
return _database.Fetch<ExternalNotificationSetting>();
|
|
|
|
|
return _database.Fetch<ExternalNotificationDefinition>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void SaveSettings(ExternalNotificationSetting settings)
|
|
|
|
|
public virtual void SaveSettings(ExternalNotificationDefinition settings)
|
|
|
|
|
{
|
|
|
|
|
if (settings.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Adding External Notification settings for {0}", settings.Name);
|
|
|
|
|
Logger.Debug("Adding External Notification definition for {0}", settings.Name);
|
|
|
|
|
_database.Insert(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Updating External Notification settings for {0}", settings.Name);
|
|
|
|
|
Logger.Debug("Updating External Notification definition for {0}", settings.Name);
|
|
|
|
|
_database.Update(settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual ExternalNotificationSetting GetSettings(Type type)
|
|
|
|
|
public virtual ExternalNotificationDefinition GetSettings(Type type)
|
|
|
|
|
{
|
|
|
|
|
return _database.SingleOrDefault<ExternalNotificationSetting>("WHERE NotifierName = @0", type.ToString());
|
|
|
|
|
return _database.SingleOrDefault<ExternalNotificationDefinition>("WHERE ExternalNotificationProviderType = @0", type.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual ExternalNotificationSetting GetSettings(int id)
|
|
|
|
|
public virtual IList<ExternalNotificationBase> GetEnabledExternalNotifiers()
|
|
|
|
|
{
|
|
|
|
|
return _database.SingleOrDefault<ExternalNotificationSetting>(id);
|
|
|
|
|
var all = All();
|
|
|
|
|
return _notifiers.Where(i => all.Exists(c => c.ExternalNotificationProviderType == i.GetType().ToString() && c.Enable)).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void InitializeNotifiers(IList<ExternalNotificationProviderBase> notifiers)
|
|
|
|
|
public virtual void InitializeNotifiers(IList<ExternalNotificationBase> notifiers)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Initializing notifiers. Count {0}", notifiers.Count);
|
|
|
|
|
|
|
|
|
|
_notifiers = notifiers;
|
|
|
|
|
|
|
|
|
|
var currentNotifiers = All();
|
|
|
|
|
|
|
|
|
|
foreach (var feedProvider in notifiers)
|
|
|
|
|
foreach (var notificationProvider in notifiers)
|
|
|
|
|
{
|
|
|
|
|
ExternalNotificationProviderBase externalNotificationProviderLocal = feedProvider;
|
|
|
|
|
if (!currentNotifiers.Exists(c => c.NotifierName == externalNotificationProviderLocal.GetType().ToString()))
|
|
|
|
|
ExternalNotificationBase externalNotificationProviderLocal = notificationProvider;
|
|
|
|
|
if (!currentNotifiers.Exists(c => c.ExternalNotificationProviderType == externalNotificationProviderLocal.GetType().ToString()))
|
|
|
|
|
{
|
|
|
|
|
var settings = new ExternalNotificationSetting()
|
|
|
|
|
var settings = new ExternalNotificationDefinition
|
|
|
|
|
{
|
|
|
|
|
Enabled = false,
|
|
|
|
|
NotifierName = externalNotificationProviderLocal.GetType().ToString(),
|
|
|
|
|
Enable = false,
|
|
|
|
|
ExternalNotificationProviderType = externalNotificationProviderLocal.GetType().ToString(),
|
|
|
|
|
Name = externalNotificationProviderLocal.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -76,5 +84,29 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnGrab(string message)
|
|
|
|
|
{
|
|
|
|
|
foreach (var notifier in _notifiers.Where(i => GetSettings(i.GetType()).Enable))
|
|
|
|
|
{
|
|
|
|
|
notifier.OnGrab(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnDownload(string message, Series series)
|
|
|
|
|
{
|
|
|
|
|
foreach (var notifier in _notifiers.Where(i => GetSettings(i.GetType()).Enable))
|
|
|
|
|
{
|
|
|
|
|
notifier.OnDownload(message, series);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnRename(string message, Series series)
|
|
|
|
|
{
|
|
|
|
|
foreach (var notifier in _notifiers.Where(i => GetSettings(i.GetType()).Enable))
|
|
|
|
|
{
|
|
|
|
|
notifier.OnRename(message, series);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|