2013-05-06 00:33:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.AspNet.SignalR.Json;
|
2013-05-10 23:53:50 +00:00
|
|
|
|
using NzbDrone.Common.Composition;
|
2013-05-13 02:52:55 +00:00
|
|
|
|
using NzbDrone.Common.Serializer;
|
2013-05-06 00:33:43 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.SignalR
|
|
|
|
|
{
|
2013-05-10 23:53:50 +00:00
|
|
|
|
[Singleton]
|
2013-05-06 00:33:43 +00:00
|
|
|
|
public class Serializer : IJsonSerializer
|
|
|
|
|
{
|
2013-05-13 02:52:55 +00:00
|
|
|
|
private readonly JsonNetSerializer _signalRSerializer = new JsonNetSerializer();
|
2013-05-06 00:33:43 +00:00
|
|
|
|
|
|
|
|
|
public void Serialize(object value, TextWriter writer)
|
|
|
|
|
{
|
|
|
|
|
if (value.GetType().FullName.StartsWith("NzbDrone"))
|
|
|
|
|
{
|
2013-05-13 02:52:55 +00:00
|
|
|
|
Json.Serialize(value, writer);
|
2013-05-06 00:33:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_signalRSerializer.Serialize(value, writer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Parse(string json, Type targetType)
|
|
|
|
|
{
|
|
|
|
|
if (targetType.FullName.StartsWith("NzbDrone"))
|
|
|
|
|
{
|
2013-05-13 02:52:55 +00:00
|
|
|
|
return Json.Deserialize(json, targetType);
|
2013-05-06 00:33:43 +00:00
|
|
|
|
}
|
2013-05-10 23:53:50 +00:00
|
|
|
|
|
2013-05-06 00:33:43 +00:00
|
|
|
|
return _signalRSerializer.Parse(json, targetType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|