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

pull/2/head
kayone 11 years ago
parent eaed756655
commit e8b2d1fda0

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

@ -62,7 +62,7 @@ namespace NzbDrone.Common.Reflection
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)

@ -71,6 +71,7 @@ namespace NzbDrone.Core.Test.IndexerTests
var existingIndexers = Builder<IndexerDefinition>.CreateNew().BuildNew();
existingIndexers.ConfigContract = typeof (NewznabSettings).Name;
repo.Insert(existingIndexers);

@ -23,11 +23,15 @@ namespace NzbDrone.Core.Datastore.Converters
}
var ordinal = context.DataRecord.GetOrdinal("ConfigContract");
var contract = context.DataRecord.GetString(ordinal);
var implementation = context.DataRecord.GetString(ordinal);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(contract);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(implementation);
if (impType == null)
{
throw new ConfigContractNotFoundException(contract);
}
return Json.Deserialize(stringValue, impType);
}

@ -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" />

@ -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)
{
}
}
}

@ -48,7 +48,7 @@ namespace NzbDrone.Core.ThingiProvider
{
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();
}

Loading…
Cancel
Save