|
|
|
@ -5,24 +5,57 @@ using NzbDrone.Common.Serializer;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore.Converters
|
|
|
|
|
{
|
|
|
|
|
public class EmbeddedDocumentConverter : IConverter
|
|
|
|
|
|
|
|
|
|
public class ProviderSettingConverter : EmbeddedDocumentConverter
|
|
|
|
|
{
|
|
|
|
|
public override object FromDB(ConverterContext context)
|
|
|
|
|
{
|
|
|
|
|
if (context.DbValue == DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
return DBNull.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object FromDB(ColumnMap map, object dbValue)
|
|
|
|
|
var stringValue = (string)context.DbValue;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(stringValue))
|
|
|
|
|
{
|
|
|
|
|
if (dbValue == DBNull.Value)
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ordinal = context.DataRecord.GetOrdinal("ConfigContract");
|
|
|
|
|
|
|
|
|
|
var implementation = context.DataRecord.GetString(ordinal);
|
|
|
|
|
|
|
|
|
|
var impType = Type.GetType(implementation, true, true);
|
|
|
|
|
|
|
|
|
|
return Json.Deserialize(stringValue, impType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class EmbeddedDocumentConverter : IConverter
|
|
|
|
|
{
|
|
|
|
|
public virtual object FromDB(ConverterContext context)
|
|
|
|
|
{
|
|
|
|
|
if (context.DbValue == DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
return DBNull.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stringValue = (string)dbValue;
|
|
|
|
|
var stringValue = (string)context.DbValue;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(stringValue))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json.Deserialize(stringValue, map.FieldType);
|
|
|
|
|
return Json.Deserialize(stringValue, context.ColumnMap.FieldType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object FromDB(ColumnMap map, object dbValue)
|
|
|
|
|
{
|
|
|
|
|
return FromDB(new ConverterContext { ColumnMap = map, DbValue = dbValue });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ToDB(object clrValue)
|
|
|
|
|