mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
fixed disk scan scheduler.
This commit is contained in:
parent
42849d3276
commit
687f8d9384
23 changed files with 140 additions and 142 deletions
58
NzbDrone.Common/Serializer/Json.cs
Normal file
58
NzbDrone.Common/Serializer/Json.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace NzbDrone.Common.Serializer
|
||||
{
|
||||
public static class Json
|
||||
{
|
||||
private static readonly JsonSerializer JsonNetSerializer;
|
||||
|
||||
|
||||
static Json()
|
||||
{
|
||||
JsonNetSerializer = new JsonSerializer()
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
DefaultValueHandling = DefaultValueHandling.Include,
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
JsonNetSerializer.Converters.Add(new StringEnumConverter { CamelCaseText = true });
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(string json) where T : class, new()
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public static object Deserialize(string json, Type type)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(json, type);
|
||||
}
|
||||
|
||||
public static string Serialize(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
|
||||
public static void Serialize<TModel>(TModel model, TextWriter outputStream)
|
||||
{
|
||||
var jsonTextWriter = new JsonTextWriter(outputStream);
|
||||
JsonNetSerializer.Serialize(jsonTextWriter, model);
|
||||
jsonTextWriter.Flush();
|
||||
}
|
||||
|
||||
public static void Serialize<TModel>(TModel model, Stream outputStream)
|
||||
{
|
||||
Serialize(model, new StreamWriter(outputStream));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace NzbDrone.Common.Serializer
|
||||
{
|
||||
public interface IJsonSerializer
|
||||
{
|
||||
T Deserialize<T>(string json) where T : class, new();
|
||||
string Serialize(object obj);
|
||||
void Serialize<TModel>(TModel model, TextWriter textWriter);
|
||||
void Serialize<TModel>(TModel model, Stream outputStream);
|
||||
object Deserialize(string json, Type type);
|
||||
}
|
||||
|
||||
public class JsonSerializer : IJsonSerializer
|
||||
{
|
||||
private readonly Newtonsoft.Json.JsonSerializer _jsonNetSerializer;
|
||||
|
||||
public JsonSerializer()
|
||||
{
|
||||
_jsonNetSerializer = new Newtonsoft.Json.JsonSerializer()
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
DefaultValueHandling = DefaultValueHandling.Include,
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
_jsonNetSerializer.Converters.Add(new StringEnumConverter { CamelCaseText = true });
|
||||
}
|
||||
|
||||
public T Deserialize<T>(string json) where T : class, new()
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public object Deserialize(string json, Type type)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(json, type);
|
||||
}
|
||||
|
||||
public string Serialize(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
|
||||
public void Serialize<TModel>(TModel model, TextWriter outputStream)
|
||||
{
|
||||
var jsonTextWriter = new JsonTextWriter(outputStream);
|
||||
_jsonNetSerializer.Serialize(jsonTextWriter, model);
|
||||
jsonTextWriter.Flush();
|
||||
}
|
||||
|
||||
public void Serialize<TModel>(TModel model, Stream outputStream)
|
||||
{
|
||||
Serialize(model, new StreamWriter(outputStream));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue