mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
spelling
This commit is contained in:
parent
c35682376e
commit
cf8be4bf8f
16 changed files with 20 additions and 21 deletions
27
NzbDrone.Api/Extensions/NancyJsonSerializer.cs
Normal file
27
NzbDrone.Api/Extensions/NancyJsonSerializer.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Api.Extensions
|
||||
{
|
||||
public class NancyJsonSerializer : ISerializer
|
||||
{
|
||||
public readonly static NancyJsonSerializer Instance = new NancyJsonSerializer();
|
||||
|
||||
public bool CanSerialize(string contentType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Serialize<TModel>(string contentType, TModel model, Stream outputStream)
|
||||
{
|
||||
var jsonTextWriter = new JsonTextWriter(new StreamWriter(outputStream));
|
||||
Serializer.Instance.Serialize(jsonTextWriter, model);
|
||||
jsonTextWriter.Flush();
|
||||
}
|
||||
|
||||
public IEnumerable<string> Extensions { get; private set; }
|
||||
}
|
||||
}
|
25
NzbDrone.Api/Extensions/RequestExtensions.cs
Normal file
25
NzbDrone.Api/Extensions/RequestExtensions.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Api.Extensions
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
public static T FromJson<T>(this Stream body)
|
||||
{
|
||||
var reader = new StreamReader(body, true);
|
||||
body.Position = 0;
|
||||
var value = reader.ReadToEnd();
|
||||
return JsonConvert.DeserializeObject<T>(value, Serializer.Settings);
|
||||
}
|
||||
|
||||
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
{
|
||||
var jsonResponse = new JsonResponse<TModel>(model, new NancyJsonSerializer()) { StatusCode = statusCode };
|
||||
return jsonResponse;
|
||||
}
|
||||
}
|
||||
}
|
14
NzbDrone.Api/Extensions/RootPathProvider.cs
Normal file
14
NzbDrone.Api/Extensions/RootPathProvider.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
|
||||
namespace NzbDrone.Api.Extensions
|
||||
{
|
||||
public class RootPathProvider : IRootPathProvider
|
||||
{
|
||||
public string GetRootPath()
|
||||
{
|
||||
return Directory.GetCurrentDirectory();
|
||||
}
|
||||
}
|
||||
}
|
33
NzbDrone.Api/Extensions/Serializer.cs
Normal file
33
NzbDrone.Api/Extensions/Serializer.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace NzbDrone.Api.Extensions
|
||||
{
|
||||
public static class Serializer
|
||||
{
|
||||
static Serializer()
|
||||
{
|
||||
Settings = new JsonSerializerSettings
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
|
||||
};
|
||||
|
||||
Instance = new JsonSerializer
|
||||
{
|
||||
DateTimeZoneHandling = Settings.DateTimeZoneHandling,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
}
|
||||
|
||||
public static JsonSerializerSettings Settings { get; private set; }
|
||||
|
||||
public static JsonSerializer Instance { get; private set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue