1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

fixed indexer setting load/reload.

This commit is contained in:
Keivan Beigi 2013-04-10 16:44:48 -07:00
parent 1465fbf499
commit 2eb3ead230
21 changed files with 160 additions and 149 deletions

View File

@ -108,7 +108,6 @@
<Compile Include="Eventing\IHandle.cs" />
<Compile Include="HostController.cs" />
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
<Compile Include="ReflectionExtentions.cs" />
<Compile Include="StringExtention.cs" />
<Compile Include="HttpProvider.cs" />
<Compile Include="ConfigFileProvider.cs" />

View File

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NzbDrone.Common
{
public static class ReflectionExtensions
{
public static IEnumerable<Type> GetInterfaces(this Assembly assembly)
{
return assembly.GetTypes().Where(c => c.IsInterface);
}
public static IEnumerable<Type> GetImplementations(this Assembly assembly, Type contractType)
{
return assembly.GetTypes()
.Where(implementation =>
contractType.IsAssignableFrom(implementation) &&
!implementation.IsInterface &&
!implementation.IsAbstract
);
}
}
}

View File

@ -101,14 +101,13 @@ protected override void MainDbUpgrade()
Create.TableForModel("IndexerDefinitions")
.WithColumn("Enable").AsBoolean()
.WithColumn("Name").AsString().Unique()
.WithColumn("Settings").AsString();
.WithColumn("Settings").AsString().Nullable();
Create.TableForModel("NewznabDefinitions")
.WithColumn("Enable").AsBoolean()
.WithColumn("Name").AsString().Unique()
.WithColumn("Url").AsString()
.WithColumn("ApiKey").AsString().Nullable()
.WithColumn("BuiltIn").AsBoolean();
.WithColumn("ApiKey").AsString().Nullable();
Create.TableForModel("QualityProfiles")
.WithColumn("Name").AsString().Unique()

View File

@ -3,27 +3,23 @@
namespace NzbDrone.Core.Indexers.FileSharingTalk
{
public class FileSharingTalk : BaseIndexer
public class FileSharingTalk : IndexerWithSetting<FileSharingTalkSetting>
{
private readonly FileSharingTalkSetting _settings;
public FileSharingTalk(IProviderIndexerSetting settingProvider)
: base(settingProvider)
{
_settings = settingProvider.Get<FileSharingTalkSetting>(this);
}
public override IEnumerable<string> RecentFeed
{
get
{
yield return
string.Format(
yield return string.Format(
"http://filesharingtalk.com/ng_rss.php?uid={0}&ps={1}&category=tv&subcategory=x264sd,x264720,xvid,webdl720,x2641080",
_settings.Uid, _settings.Secret);
Settings.Uid, Settings.Secret);
}
}
public override IParseFeed Parser
{
get
@ -32,11 +28,6 @@ public override IParseFeed Parser
}
}
public override IIndexerSetting Settings
{
get { return _settings; }
}
public override string Name
{
get { return "FileSharingTalk"; }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace NzbDrone.Core.Indexers
{
public interface IIndexerBase
{
string Name { get; }
bool EnabledByDefault { get; }
IEnumerable<string> RecentFeed { get; }
IParseFeed Parser { get; }
bool IsConfigured { get; }
IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber);
IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date);
IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber);
IEnumerable<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard);
}
}

View File

@ -3,27 +3,13 @@
namespace NzbDrone.Core.Indexers
{
public interface IIndexerBase
public abstract class Indexer : IIndexerBase
{
string Name { get; }
bool EnabledByDefault { get; }
IEnumerable<string> RecentFeed { get; }
IParseFeed Parser { get; }
IIndexerSetting Settings { get; }
IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber);
IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date);
IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber);
IEnumerable<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard);
}
public abstract class BaseIndexer : IIndexerBase
{
public abstract string Name { get; }
public virtual bool EnabledByDefault
{
get
@ -40,14 +26,13 @@ public virtual IParseFeed Parser
}
}
public virtual IIndexerSetting Settings
public virtual bool IsConfigured
{
get
{
return new NullSetting();
}
get { return true; }
}
public abstract IEnumerable<string> RecentFeed { get; }
public abstract IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber);

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Indexers
@ -6,6 +7,7 @@ namespace NzbDrone.Core.Indexers
public interface IIndexerRepository : IBasicRepository<IndexerDefinition>
{
IndexerDefinition Get(string name);
IndexerDefinition Find(string name);
}
public class IndexerRepository : BasicRepository<IndexerDefinition>, IIndexerRepository
@ -17,7 +19,13 @@ public IndexerRepository(IDatabase database)
public IndexerDefinition Get(string name)
{
return Query.Single(i => i.Name.ToLower() == name.ToLower());
}
return Query.Single(i => i.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
public IndexerDefinition Find(string name)
{
return Query.SingleOrDefault(i => i.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
}
}

View File

@ -38,7 +38,7 @@ public List<IndexerDefinition> All()
public List<IIndexerBase> GetAvailableIndexers()
{
var enabled = All().Where(c => c.Enable).Select(c => c.Name);
var configureIndexers = _indexers.Where(c => c.Settings.IsValid);
var configureIndexers = _indexers.Where(c => c.IsConfigured);
return configureIndexers.Where(c => enabled.Contains(c.Name)).ToList();
}

View File

@ -18,8 +18,14 @@ public IndexerSettingProvider(IIndexerRepository indexerRepository)
public TSetting Get<TSetting>(IIndexerBase indexer) where TSetting : IIndexerSetting, new()
{
var json = _indexerRepository.Get(indexer.Name).Settings;
return JsonConvert.DeserializeObject<TSetting>(json);
var indexerDef = _indexerRepository.Find(indexer.Name);
if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings))
{
return new TSetting();
}
return JsonConvert.DeserializeObject<TSetting>(indexerDef.Settings);
}
}
}

View File

@ -0,0 +1,16 @@
using NzbDrone.Common.Eventing;
namespace NzbDrone.Core.Indexers
{
public class IndexerSettingUpdatedEvent : IEvent
{
public string IndexerName { get; private set; }
public IIndexerSetting IndexerSetting { get; private set; }
public IndexerSettingUpdatedEvent(string indexerName, IIndexerSetting indexerSetting)
{
IndexerName = indexerName;
IndexerSetting = indexerSetting;
}
}
}

View File

@ -0,0 +1,30 @@
using System;
using NzbDrone.Common.Eventing;
namespace NzbDrone.Core.Indexers
{
public abstract class IndexerWithSetting<TSetting> :
Indexer,
IHandle<IndexerSettingUpdatedEvent> where TSetting : IIndexerSetting, new()
{
protected IndexerWithSetting(IProviderIndexerSetting settingProvider)
{
Settings = settingProvider.Get<TSetting>(this);
}
public override bool IsConfigured
{
get { return Settings.IsValid; }
}
protected TSetting Settings { get; private set; }
public void Handle(IndexerSettingUpdatedEvent message)
{
if (message.IndexerName.Equals(Name, StringComparison.InvariantCultureIgnoreCase))
{
Settings = (TSetting)message.IndexerSetting;
}
}
}
}

View File

@ -4,7 +4,7 @@
namespace NzbDrone.Core.Indexers.Newznab
{
public class Newznab : BaseIndexer
public class Newznab : Indexer
{
private readonly INewznabService _newznabProvider;

View File

@ -1,16 +1,10 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Core.Indexers.NzbClub
{
public class NzbClub : BaseIndexer
public class NzbClub : Indexer
{
public NzbClub(HttpProvider httpProvider, IConfigService configService)
{
}
public override IEnumerable<string> RecentFeed
{
get

View File

@ -3,7 +3,7 @@
namespace NzbDrone.Core.Indexers.NzbIndex
{
public class NzbIndex : BaseIndexer
public class NzbIndex : Indexer
{
public override IEnumerable<string> RecentFeed
{

View File

@ -3,13 +3,13 @@
namespace NzbDrone.Core.Indexers.NzbsRUs
{
public class Nzbsrus : BaseIndexer
public class Nzbsrus : IndexerWithSetting<NzbsrusSetting>
{
private readonly NzbsrusSetting _setting;
public Nzbsrus(IProviderIndexerSetting settingProvider)
public Nzbsrus(IProviderIndexerSetting settingProvider):base(settingProvider)
{
_setting = settingProvider.Get<NzbsrusSetting>(this);
}
public override IEnumerable<string> RecentFeed
@ -23,12 +23,6 @@ public override IEnumerable<string> RecentFeed
}
}
public override IIndexerSetting Settings
{
get { return _setting; }
}
public override string Name
{
get { return "NzbsRUs"; }

View File

@ -3,7 +3,7 @@
namespace NzbDrone.Core.Indexers.Nzbx
{
public class Nzbx : BaseIndexer
public class Nzbx : Indexer
{
public override string Name
{

View File

@ -3,13 +3,11 @@
namespace NzbDrone.Core.Indexers.Omgwtfnzbs
{
public class Omgwtfnzbs : BaseIndexer
public class Omgwtfnzbs : IndexerWithSetting<OmgwtfnzbsSetting>
{
private readonly OmgwtfnzbsSetting _settings;
public Omgwtfnzbs(IProviderIndexerSetting settingProvider)
: base(settingProvider)
{
_settings = settingProvider.Get<OmgwtfnzbsSetting>(this);
}
public override string Name
@ -24,14 +22,10 @@ public override IEnumerable<string> RecentFeed
yield return
String.Format("http://rss.omgwtfnzbs.org/rss-search.php?catid=19,20&user={0}&api={1}&eng=1",
_settings.Username, _settings.ApiKey);
Settings.Username, Settings.ApiKey);
}
}
public override IIndexerSetting Settings
{
get { return _settings; }
}
public override IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{

View File

@ -3,17 +3,11 @@
namespace NzbDrone.Core.Indexers.Wombles
{
public class Wombles : BaseIndexer
public class Wombles : Indexer
{
public override IEnumerable<string> RecentFeed
{
get
{
return new[]
{
string.Format("http://nzb.isasecret.com/rss")
};
}
get { yield return string.Format("http://nzb.isasecret.com/rss"); }
}
public override string Name
@ -21,8 +15,6 @@ public override string Name
get { return "WomblesIndex"; }
}
public override IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
return new List<string>();

View File

@ -236,6 +236,9 @@
<Compile Include="Download\Clients\Sabnzbd\SabAutoConfigureService.cs" />
<Compile Include="Download\DownloadClientProvider.cs" />
<Compile Include="Download\DownloadClientType.cs" />
<Compile Include="Indexers\IIndexerBase.cs" />
<Compile Include="Indexers\IndexerSettingUpdatedEvent.cs" />
<Compile Include="Indexers\IndexerWithSetting.cs" />
<Compile Include="MediaFiles\Events\EpisodeDownloadedEvent.cs" />
<Compile Include="Download\EpisodeGrabbedEvent.cs" />
<Compile Include="Download\SeriesRenamedEvent.cs" />
@ -254,7 +257,7 @@
<Compile Include="Indexers\RssSyncService.cs" />
<Compile Include="Indexers\FileSharingTalk\FileSharingTalk.cs" />
<Compile Include="Indexers\FileSharingTalk\FileSharingTalkParser.cs" />
<Compile Include="Indexers\BaseIndexer.cs" />
<Compile Include="Indexers\Indexer.cs" />
<Compile Include="Indexers\IndexerDefinition.cs" />
<Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Indexers\IndexerSettingProvider.cs" />

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
@ -11,9 +12,7 @@
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Core.ExternalNotification;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders;
using TinyIoC;
@ -21,27 +20,31 @@ namespace NzbDrone
{
public static class ContainerBuilder
{
private static readonly Logger logger = LogManager.GetLogger("ContainerBuilder");
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilder");
public static TinyIoCContainer Instance { get; private set; }
private static readonly List<Type> NzbDroneTypes;
static ContainerBuilder()
{
var container = new TinyIoCContainer();
container.AutoRegisterInterfaces("NzbDrone");
container.AutoRegisterInterfaces("NzbDrone.Common");
container.AutoRegisterInterfaces("NzbDrone.Core");
container.AutoRegisterInterfaces("NzbDrone.Api");
NzbDroneTypes = new List<Type>();
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone").GetTypes());
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Common").GetTypes());
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Core").GetTypes());
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Api").GetTypes());
container.AutoRegisterInterfaces();
container.AutoRegisterImplementations<IIndexerBase>();
container.AutoRegisterImplementations<ExternalNotificationBase>();
container.Register<IEventAggregator, EventAggregator>().AsSingleton();
container.Register<INancyBootstrapper, TinyNancyBootstrapper>().AsSingleton();
container.Register<IAnnouncer, MigrationLogger>().AsSingleton();
container.Register<Router>().AsSingleton();
container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)).AsMultiInstance();
container.Register(typeof(IBasicRepository<NameSpecification>), typeof(BasicRepository<NameSpecification>)).AsMultiInstance();
container.InitDatabase();
@ -50,30 +53,23 @@ static ContainerBuilder()
private static void InitDatabase(this TinyIoCContainer container)
{
logger.Info("Registering Database...");
Logger.Info("Registering Database...");
//TODO: move this to factory
var environmentProvider = new EnvironmentProvider();
var appDataPath = environmentProvider.GetAppDataPath();
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
container.Register(
delegate(TinyIoCContainer c, NamedParameterOverloads p)
if (!Directory.Exists(appDataPath))
{
return c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase());
});
Directory.CreateDirectory(appDataPath);
}
private static void AutoRegisterInterfaces(this TinyIoCContainer container, string assemblyName)
{
var assembly = Assembly.Load(assemblyName);
if (assembly == null)
{
throw new ApplicationException("Couldn't load assembly " + assemblyName);
container.Register((c, p) => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
}
var interfaces = assembly.GetInterfaces().Where(c => !c.FullName.StartsWith("Nancy."));
private static void AutoRegisterInterfaces(this TinyIoCContainer container)
{
var interfaces = NzbDroneTypes.Where(t => t.IsInterface);
foreach (var contract in interfaces)
{
@ -81,6 +77,7 @@ private static void AutoRegisterInterfaces(this TinyIoCContainer container, stri
}
}
private static void AutoRegisterImplementations<TContract>(this TinyIoCContainer container)
{
container.AutoRegisterImplementations(typeof(TContract));
@ -88,24 +85,30 @@ private static void AutoRegisterImplementations<TContract>(this TinyIoCContainer
private static void AutoRegisterImplementations(this TinyIoCContainer container, Type contractType)
{
var implementations = contractType.Assembly.GetImplementations(contractType).ToList();
var implementations = GetImplementations(contractType).ToList();
foreach(var implementation in implementations)
if (implementations.Count == 0)
{
logger.Trace("Registering {0} as {1}", implementation.Name, contractType.Name);
container.Register(contractType, implementation).AsMultiInstance();
return;
}
}
private static void AutoRegisterMultipleImplementations<TContract>(this TinyIoCContainer container)
if (implementations.Count == 1)
{
container.AutoRegisterMultipleImplementations(typeof(TContract));
container.Register(contractType, implementations.Single()).AsMultiInstance();
}
private static void AutoRegisterMultipleImplementations(this TinyIoCContainer container, Type contractType)
else
{
var implementations = contractType.Assembly.GetImplementations(contractType);
container.RegisterMultiple(contractType, implementations).AsMultiInstance();
}
}
private static IEnumerable<Type> GetImplementations(Type contractType)
{
return NzbDroneTypes
.Where(implementation =>
contractType.IsAssignableFrom(implementation) &&
!implementation.IsInterface &&
!implementation.IsAbstract
);
}
}
}

View File

@ -117,7 +117,7 @@
<Compile Include="ApplicationServer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CommonContainerExtentions.cs" />
<Compile Include="ContainerBuilder.cs" />
<Compile Include="NzbDroneBootstrapper.cs" />
<Compile Include="ApplicationMode.cs" />
<Compile Include="AppMain.cs" />