2013-05-06 00:33:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.AspNet.SignalR.Json;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.SignalR
|
|
|
|
|
{
|
|
|
|
|
public class Serializer : IJsonSerializer
|
|
|
|
|
{
|
|
|
|
|
private readonly Common.IJsonSerializer _nzbDroneSerializer;
|
2013-05-07 05:38:40 +00:00
|
|
|
|
private readonly JsonNetSerializer _signalRSerializer;
|
2013-05-06 00:33:43 +00:00
|
|
|
|
|
|
|
|
|
public Serializer(Common.IJsonSerializer nzbDroneSerializer)
|
|
|
|
|
{
|
|
|
|
|
_signalRSerializer = new JsonNetSerializer();
|
|
|
|
|
_nzbDroneSerializer = nzbDroneSerializer;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Serialize(object value, TextWriter writer)
|
|
|
|
|
{
|
|
|
|
|
if (value.GetType().FullName.StartsWith("NzbDrone"))
|
|
|
|
|
{
|
|
|
|
|
_nzbDroneSerializer.Serialize(value, writer);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_signalRSerializer.Serialize(value, writer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Parse(string json, Type targetType)
|
|
|
|
|
{
|
|
|
|
|
if (targetType.FullName.StartsWith("NzbDrone"))
|
|
|
|
|
{
|
|
|
|
|
return _nzbDroneSerializer.Deserialize(json, targetType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _signalRSerializer.Parse(json, targetType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|