2013-03-26 06:51:56 +01:00
|
|
|
|
using System;
|
|
|
|
|
using Marr.Data.Converters;
|
|
|
|
|
using Marr.Data.Mapping;
|
2013-04-18 01:32:06 +02:00
|
|
|
|
using NzbDrone.Common;
|
2013-05-12 17:18:17 +02:00
|
|
|
|
using NzbDrone.Common.Serializer;
|
2013-03-26 06:51:56 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore.Converters
|
|
|
|
|
{
|
|
|
|
|
public class EmbeddedDocumentConverter : IConverter
|
|
|
|
|
{
|
2013-04-18 01:32:06 +02:00
|
|
|
|
|
2013-03-26 06:51:56 +01:00
|
|
|
|
public object FromDB(ColumnMap map, object dbValue)
|
|
|
|
|
{
|
|
|
|
|
if (dbValue == DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
return DBNull.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stringValue = (string)dbValue;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(stringValue))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-13 04:52:55 +02:00
|
|
|
|
return Json.Deserialize(stringValue, map.FieldType);
|
2013-03-26 06:51:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ToDB(object clrValue)
|
|
|
|
|
{
|
|
|
|
|
if (clrValue == null) return null;
|
|
|
|
|
|
2013-05-13 04:52:55 +02:00
|
|
|
|
var json = Json.Serialize(clrValue);
|
2013-03-26 06:51:56 +01:00
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type DbType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return typeof(string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|