1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-23 22:25:14 -04:00

Swap to dapper and system.text.json for database backend

This commit is contained in:
ta264
2019-12-15 15:04:42 +00:00
parent 7b17c3e36c
commit d2065bfa1b
155 changed files with 2333 additions and 2340 deletions
@@ -1,40 +1,23 @@
using System;
using Marr.Data.Converters;
using NzbDrone.Common.Reflection;
using NzbDrone.Common.Serializer;
using System.Data;
using System.Text.Json;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Datastore.Converters
{
public class ProviderSettingConverter : EmbeddedDocumentConverter
public class ProviderSettingConverter : EmbeddedDocumentConverter<IProviderConfig>
{
public override object FromDB(ConverterContext context)
public override IProviderConfig Parse(object value)
{
if (context.DbValue == DBNull.Value)
{
return NullConfig.Instance;
}
// We can't deserialize based on another column, happens in ProviderRepository instead
return null;
}
var stringValue = (string)context.DbValue;
if (string.IsNullOrWhiteSpace(stringValue))
{
return NullConfig.Instance;
}
var ordinal = context.DataRecord.GetOrdinal("ConfigContract");
var contract = context.DataRecord.GetString(ordinal);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(contract);
if (impType == null)
{
throw new ConfigContractNotFoundException(contract);
}
return Json.Deserialize(stringValue, impType);
public override void SetValue(IDbDataParameter parameter, IProviderConfig value)
{
// Cast to object to get all properties written out
// https://github.com/dotnet/corefx/issues/38650
parameter.Value = JsonSerializer.Serialize((object)value, SerializerSettings);
}
}
}
}