More Connects cleanup/fixing

pull/4/head
Mark McDowall 11 years ago
parent 27da44ba45
commit 25c5401a9d

@ -39,7 +39,6 @@ namespace NzbDrone.Core.Indexers
_logger.Debug("Available indexers {0}", indexers.Count);
var taskList = new List<Task>();
var taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Indexers
}
}
public ProviderDefinition Definition { get; set; }
public virtual ProviderDefinition Definition { get; set; }
public abstract DownloadProtocol Protocol { get; }
@ -49,7 +49,6 @@ namespace NzbDrone.Core.Indexers
public abstract IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date);
public abstract IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset);
public override string ToString()
{
return GetType().Name;

@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
@ -15,8 +17,8 @@ namespace NzbDrone.Core.Indexers
private readonly IIndexerRepository _providerRepository;
private readonly IEnumerable<IIndexer> _providers;
public IndexerFactory(IIndexerRepository providerRepository, IEnumerable<IIndexer> providers, Logger logger)
: base(providerRepository, providers, logger)
public IndexerFactory(IIndexerRepository providerRepository, IEnumerable<IIndexer> providers, IContainer container, Logger logger)
: base(providerRepository, providers, container, logger)
{
_providerRepository = providerRepository;
_providers = providers;
@ -36,5 +38,10 @@ namespace NzbDrone.Core.Indexers
_providerRepository.InsertMany(newProviders.Cast<IndexerDefinition>().ToList());
}
}
protected override List<IndexerDefinition> Active()
{
return base.Active().Where(c => c.Enable).ToList();
}
}
}

@ -52,6 +52,8 @@ namespace NzbDrone.Core.Indexers.Newznab
}
}
public override ProviderDefinition Definition { get; set; }
private NewznabSettings GetSettings(string url, List<int> categories)
{
var settings = new NewznabSettings { Url = url };

@ -1,20 +1,35 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Notifications
{
public interface INotificationFactory : IProviderFactory<INotification, NotificationDefinition>
{
List<INotification> OnGrabEnabled();
List<INotification> OnDownloadEnabled();
}
public class NotificationFactory : ProviderFactory<INotification, NotificationDefinition>, INotificationFactory
{
public NotificationFactory(INotificationRepository providerRepository, IEnumerable<INotification> providers, Logger logger)
: base(providerRepository, providers, logger)
private IEnumerable<INotification> _providers;
public NotificationFactory(INotificationRepository providerRepository, IEnumerable<INotification> providers, IContainer container, Logger logger)
: base(providerRepository, providers, container, logger)
{
_providers = providers;
}
public List<INotification> OnGrabEnabled()
{
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnGrab).ToList();
}
public List<INotification> OnDownloadEnabled()
{
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnDownload).ToList();
}
}
}

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
using Omu.ValueInjecter;
namespace NzbDrone.Core.Notifications
{
public class NotificationService
: IHandle<EpisodeGrabbedEvent>,
IHandle<EpisodeDownloadedEvent>,
IHandle<SeriesRenamedEvent>
{
private readonly INotificationFactory _notificationFactory;
private readonly Logger _logger;
public NotificationService(INotificationFactory notificationFactory, Logger logger)
{
_notificationFactory = notificationFactory;
_logger = logger;
}
private string GetMessage(Series series, List<Episode> episodes, QualityModel quality)
{
if (series.SeriesType == SeriesTypes.Daily)
{
var episode = episodes.First();
return String.Format("{0} - {1} - {2} [{3}]",
series.Title,
episode.AirDate,
episode.Title,
quality);
}
var episodeNumbers = String.Concat(episodes.Select(e => e.EpisodeNumber)
.Select(i => String.Format("x{0:00}", i)));
var episodeTitles = String.Join(" + ", episodes.Select(e => e.Title));
return String.Format("{0} - {1}{2} - {3} {4}",
series.Title,
episodes.First().SeasonNumber,
episodeNumbers,
episodeTitles,
quality);
}
public void Handle(EpisodeGrabbedEvent message)
{
var messageBody = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality);
foreach (var notification in _notificationFactory.OnGrabEnabled())
{
try
{
notification.OnGrab(messageBody);
}
catch (Exception ex)
{
_logger.ErrorException("Unable to send OnGrab notification to: " + notification.Definition.Name, ex);
}
}
}
public void Handle(EpisodeDownloadedEvent message)
{
var messageBody = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality);
foreach (var notification in _notificationFactory.OnDownloadEnabled())
{
try
{
notification.OnDownload(messageBody, message.Episode.Series);
}
catch (Exception ex)
{
_logger.WarnException("Unable to send OnDownload notification to: " + notification.Definition.Name, ex);
}
}
}
public void Handle(SeriesRenamedEvent message)
{
foreach (var notification in _notificationFactory.OnDownloadEnabled())
{
try
{
notification.AfterRename(message.Series);
}
catch (Exception ex)
{
_logger.WarnException("Unable to send AfterRename notification to: " + notification.Definition.Name, ex);
}
}
}
}
}

@ -272,6 +272,7 @@
<Compile Include="Messaging\Events\IHandle.cs" />
<Compile Include="MetadataSource\Trakt\TraktException.cs" />
<Compile Include="Notifications\NotificationFactory.cs" />
<Compile Include="Notifications\NotificationService.cs" />
<Compile Include="Notifications\PushBullet\PushBullet.cs" />
<Compile Include="Notifications\PushBullet\PushBulletProxy.cs" />
<Compile Include="Notifications\PushBullet\PushBulletSettings.cs" />

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
@ -12,13 +13,18 @@ namespace NzbDrone.Core.ThingiProvider
where TProvider : IProvider
{
private readonly IProviderRepository<TProviderDefinition> _providerRepository;
private readonly IContainer _container;
private readonly Logger _logger;
private readonly List<TProvider> _providers;
protected ProviderFactory(IProviderRepository<TProviderDefinition> providerRepository, IEnumerable<TProvider> providers, Logger logger)
protected ProviderFactory(IProviderRepository<TProviderDefinition> providerRepository,
IEnumerable<TProvider> providers,
IContainer container,
Logger logger)
{
_providerRepository = providerRepository;
_container = container;
_providers = providers.ToList();
_logger = logger;
}
@ -40,8 +46,7 @@ namespace NzbDrone.Core.ThingiProvider
public List<TProvider> GetAvailableProviders()
{
return All().Where(c => c.Settings.Validate().IsValid)
.Select(GetInstance).ToList();
return Active().Select(GetInstance).ToList();
}
public TProviderDefinition Get(int id)
@ -67,7 +72,9 @@ namespace NzbDrone.Core.ThingiProvider
private TProvider GetInstance(TProviderDefinition definition)
{
var type = GetImplementation(definition);
var instance = (TProvider)Activator.CreateInstance(type);
//TODO: This doesn't work for things that have non-parameterless constructors
var instance = (TProvider)_container.Resolve(type);
instance.Definition = definition;
return instance;
}
@ -90,6 +97,11 @@ namespace NzbDrone.Core.ThingiProvider
{
}
protected virtual List<TProviderDefinition> Active()
{
return All().Where(c => c.Settings.Validate().IsValid).ToList();
}
private void RemoveMissingImplementations()
{
var storedProvider = _providerRepository.All();

@ -3,7 +3,7 @@
define([
'AppLayout',
'marionette',
'Settings/Notifications/EditView',
'Settings/Notifications/NotificationEditView',
'Settings/Notifications/DeleteView'
], function (AppLayout, Marionette, EditView, DeleteView) {

Loading…
Cancel
Save