sonarr-repo-only/NzbDrone.Core/Datastore/Converters/ProviderSettingConverter.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2013-09-22 23:40:36 +00:00
using System;
using Marr.Data.Converters;
using NzbDrone.Common.Reflection;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Datastore.Converters
{
public class ProviderSettingConverter : EmbeddedDocumentConverter
{
public override object FromDB(ConverterContext context)
{
if (context.DbValue == DBNull.Value)
{
return NullConfig.Instance;
}
var stringValue = (string)context.DbValue;
if (string.IsNullOrWhiteSpace(stringValue))
{
return NullConfig.Instance;
}
var ordinal = context.DataRecord.GetOrdinal("ConfigContract");
var contract = context.DataRecord.GetString(ordinal);
2013-09-22 23:40:36 +00:00
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(contract);
2013-09-22 23:40:36 +00:00
if (impType == null)
{
throw new ConfigContractNotFoundException(contract);
}
2013-09-22 23:40:36 +00:00
return Json.Deserialize(stringValue, impType);
}
}
}