1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

fixed broken test, cleaned up some code around config contracts.

This commit is contained in:
kayone 2013-09-24 17:01:03 -07:00
parent eaed756655
commit e8b2d1fda0
7 changed files with 26 additions and 5 deletions

View File

@ -57,6 +57,8 @@ public static List<Field> ToSchema(object model)
public static object ReadFormSchema(List<Field> fields, Type targetType)
{
Ensure.That(() => targetType).IsNotNull();
var properties = targetType.GetSimpleProperties();
var target = Activator.CreateInstance(targetType);

View File

@ -62,7 +62,7 @@ public static T GetAttribute<T>(this MemberInfo member, bool isRequired = true)
public static Type FindTypeByName(this Assembly assembly, string name)
{
return assembly.GetTypes().Single(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
return assembly.GetTypes().SingleOrDefault(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
public static bool HasAttribute<TAttribute>(this Type type)

View File

@ -71,6 +71,7 @@ public void should_remove_missing_indexers_on_startup()
var existingIndexers = Builder<IndexerDefinition>.CreateNew().BuildNew();
existingIndexers.ConfigContract = typeof (NewznabSettings).Name;
repo.Insert(existingIndexers);

View File

@ -23,11 +23,15 @@ public override object FromDB(ConverterContext context)
}
var ordinal = context.DataRecord.GetOrdinal("ConfigContract");
var implementation = context.DataRecord.GetString(ordinal);
var contract = context.DataRecord.GetString(ordinal);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(implementation);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(contract);
if (impType == null)
{
throw new ConfigContractNotFoundException(contract);
}
return Json.Deserialize(stringValue, impType);
}

View File

@ -414,6 +414,7 @@
<Compile Include="Parser\Parser.cs" />
<Compile Include="Parser\ParsingService.cs" />
<Compile Include="Parser\QualityParser.cs" />
<Compile Include="ThingiProvider\ConfigContractNotFoundException.cs" />
<Compile Include="ThingiProvider\IProvider.cs" />
<Compile Include="Qualities\QualityProfileInUseException.cs" />
<Compile Include="Qualities\QualitySizeRepository.cs" />

View File

@ -0,0 +1,13 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.ThingiProvider
{
public class ConfigContractNotFoundException : NzbDroneException
{
public ConfigContractNotFoundException(string contract)
: base("Couldn't find config contract " + contract)
{
}
}
}

View File

@ -48,7 +48,7 @@ public List<TProviderDefinition> Templates()
{
ConfigContract = p.ConfigContract.Name,
Implementation = p.GetType().Name,
Settings = (IProviderConfig)Activator.CreateInstance(ReflectionExtensions.CoreAssembly.FindTypeByName(p.ConfigContract.Name))
Settings = (IProviderConfig)Activator.CreateInstance(p.ConfigContract)
}).ToList();
}