From baedafbeb92db3ddf434f038984970bf0a6ac0c1 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 15 Jul 2012 16:27:07 -0400 Subject: [PATCH] Switched to service stack json. Added more api enhancements. --- MediaBrowser.Api/HttpHandlers/ItemHandler.cs | 16 +- MediaBrowser.Common/Json/JsonSerializer.cs | 70 +++--- MediaBrowser.Common/Logging/BaseLogger.cs | 1 + MediaBrowser.Common/Logging/LogRow.cs | 1 + .../MediaBrowser.Common.csproj | 11 +- .../Model/DictionaryBaseItem.cs | 227 ++++++++++++++++++ .../Net/Handlers/JsonHandler.cs | 2 +- MediaBrowser.Common/Plugins/BasePlugin.cs | 2 +- MediaBrowser.Common/packages.config | 1 - MediaBrowser.Controller/Kernel.cs | 2 +- .../MediaBrowser.Controller.csproj | 4 - MediaBrowser.Controller/UserController.cs | 4 +- MediaBrowser.Controller/packages.config | 1 - .../Configuration/Configuration.cs | 4 +- MediaBrowser.Model/Entities/BaseItem.cs | 88 ++++--- MediaBrowser.Model/Entities/Folder.cs | 18 +- .../Logging/LogSeverity.cs | 2 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 14 +- MediaBrowser.Model/packages.config | 4 - .../MediaBrowser.Program.csproj | 4 + MediaBrowser.Program/Program.cs | 1 + MediaBrowser.TV/Entities/Episode.cs | 2 +- MediaBrowser.TV/Entities/Season.cs | 9 +- MediaBrowser.TV/MediaBrowser.TV.csproj | 8 +- MediaBrowser.TV/Metadata/EpisodeXmlParser.cs | 11 +- MediaBrowser.TV/Resolvers/SeriesResolver.cs | 1 - MediaBrowser.TV/packages.config | 4 - 27 files changed, 370 insertions(+), 142 deletions(-) create mode 100644 MediaBrowser.Common/Model/DictionaryBaseItem.cs rename {MediaBrowser.Common => MediaBrowser.Model}/Logging/LogSeverity.cs (82%) delete mode 100644 MediaBrowser.Model/packages.config delete mode 100644 MediaBrowser.TV/packages.config diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index 5571588c8..7b4b02b63 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Net; using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Model.Entities; +using MediaBrowser.Common.Json; namespace MediaBrowser.Api.HttpHandlers { @@ -21,24 +22,19 @@ namespace MediaBrowser.Api.HttpHandlers public static object GetSerializationObject(BaseItem item, bool includeChildren) { - Folder folder = item as Folder; - - if (includeChildren && folder != null) + if (includeChildren && item.IsFolder) { + Folder folder = item as Folder; + return new { BaseItem = item, - Children = folder.Children, - Type = item.GetType().Name + Children = folder.Children }; } else { - return new - { - BaseItem = item, - Type = item.GetType().Name - }; + return item; } } diff --git a/MediaBrowser.Common/Json/JsonSerializer.cs b/MediaBrowser.Common/Json/JsonSerializer.cs index 903482fc8..55663357a 100644 --- a/MediaBrowser.Common/Json/JsonSerializer.cs +++ b/MediaBrowser.Common/Json/JsonSerializer.cs @@ -1,55 +1,55 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; +using System.IO; namespace MediaBrowser.Common.Json { public class JsonSerializer { - public static void Serialize(T o, Stream stream) + public static void SerializeToStream(T o, Stream stream) { - using (StreamWriter streamWriter = new StreamWriter(stream)) - { - using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(streamWriter)) - { - var settings = new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore - }; - - Newtonsoft.Json.JsonSerializer.Create(settings).Serialize(writer, o); - } - } + Configure(); + + ServiceStack.Text.JsonSerializer.SerializeToStream(o, stream); } - public static void Serialize(T o, string file) + public static void SerializeToFile(T o, string file) { + Configure(); + using (StreamWriter streamWriter = new StreamWriter(file)) { - using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(streamWriter)) - { - var settings = new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore - }; - - Newtonsoft.Json.JsonSerializer.Create(settings).Serialize(writer, o); - } + ServiceStack.Text.JsonSerializer.SerializeToWriter(o, streamWriter); } } - public static T Deserialize(string file) + public static T DeserializeFromFile(string file) { - using (StreamReader streamReader = new StreamReader(file)) + Configure(); + + using (Stream stream = File.OpenRead(file)) { - using (Newtonsoft.Json.JsonTextReader reader = new Newtonsoft.Json.JsonTextReader(streamReader)) - { - return Newtonsoft.Json.JsonSerializer.Create(new Newtonsoft.Json.JsonSerializerSettings() { }).Deserialize(reader); - } + return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); } } + + public static T DeserializeFromStream(Stream stream) + { + Configure(); + + return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); + } + + public static T DeserializeFromString(string data) + { + Configure(); + + return ServiceStack.Text.JsonSerializer.DeserializeFromString(data); + } + + private static void Configure() + { + ServiceStack.Text.JsConfig.ExcludeTypeInfo = true; + ServiceStack.Text.JsConfig.IncludeNullValues = false; + ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601; + } } } diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs index 51c6632d5..407c8baa7 100644 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Text; using System.Threading; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Logging { diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs index 39c69eb45..d1e234250 100644 --- a/MediaBrowser.Common/Logging/LogRow.cs +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Logging { diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 3c7f0ff04..8ee14d3a9 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -30,9 +30,6 @@ 4 - - ..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll - ..\packages\ServiceStack.Text.3.8.5\lib\net35\ServiceStack.Text.dll @@ -50,6 +47,7 @@ + @@ -63,7 +61,6 @@ - @@ -71,6 +68,12 @@ + + + {9b1ddd79-5134-4df3-ace3-d1957a7350d8} + MediaBrowser.Model + +