diff options
Diffstat (limited to 'MediaBrowser.Common')
| -rw-r--r-- | MediaBrowser.Common/Json/JsonSerializer.cs | 70 | ||||
| -rw-r--r-- | MediaBrowser.Common/Logging/BaseLogger.cs | 1 | ||||
| -rw-r--r-- | MediaBrowser.Common/Logging/LogRow.cs | 1 | ||||
| -rw-r--r-- | MediaBrowser.Common/Logging/LogSeverity.cs | 18 | ||||
| -rw-r--r-- | MediaBrowser.Common/MediaBrowser.Common.csproj | 11 | ||||
| -rw-r--r-- | MediaBrowser.Common/Model/DictionaryBaseItem.cs | 227 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/Handlers/JsonHandler.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Common/Plugins/BasePlugin.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Common/packages.config | 1 |
9 files changed, 273 insertions, 60 deletions
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>(T o, Stream stream)
+ public static void SerializeToStream<T>(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<T>(o, stream);
}
- public static void Serialize<T>(T o, string file)
+ public static void SerializeToFile<T>(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<T>(o, streamWriter);
}
}
- public static T Deserialize<T>(string file)
+ public static T DeserializeFromFile<T>(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<T>(reader);
- }
+ return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
}
}
+
+ public static T DeserializeFromStream<T>(Stream stream)
+ {
+ Configure();
+
+ return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
+ }
+
+ public static T DeserializeFromString<T>(string data)
+ {
+ Configure();
+
+ return ServiceStack.Text.JsonSerializer.DeserializeFromString<T>(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/Logging/LogSeverity.cs b/MediaBrowser.Common/Logging/LogSeverity.cs deleted file mode 100644 index b9578522e..000000000 --- a/MediaBrowser.Common/Logging/LogSeverity.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace MediaBrowser.Common.Logging
-{
- [Flags]
- public enum LogSeverity
- {
- None = 0,
- Debug = 1,
- Info = 2,
- Warning = 4,
- Error = 8
- }
-}
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 @@ <WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Newtonsoft.Json">
- <HintPath>..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
- </Reference>
<Reference Include="ServiceStack.Text">
<HintPath>..\packages\ServiceStack.Text.3.8.5\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
@@ -50,6 +47,7 @@ <ItemGroup>
<Compile Include="Events\GenericItemEventArgs.cs" />
<Compile Include="Json\JsonSerializer.cs" />
+ <Compile Include="Model\DictionaryBaseItem.cs" />
<Compile Include="Net\CollectionExtensions.cs" />
<Compile Include="Net\Handlers\BaseEmbeddedResourceHandler.cs" />
<Compile Include="Net\Handlers\JsonHandler.cs" />
@@ -63,7 +61,6 @@ <Compile Include="Logging\FileLogger.cs" />
<Compile Include="Logging\Logger.cs" />
<Compile Include="Logging\LogRow.cs" />
- <Compile Include="Logging\LogSeverity.cs" />
<Compile Include="Plugins\BasePlugin.cs" />
<Compile Include="Plugins\PluginController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -71,6 +68,12 @@ <ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">
+ <Project>{9b1ddd79-5134-4df3-ace3-d1957a7350d8}</Project>
+ <Name>MediaBrowser.Model</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/MediaBrowser.Common/Model/DictionaryBaseItem.cs b/MediaBrowser.Common/Model/DictionaryBaseItem.cs new file mode 100644 index 000000000..8bdcf1460 --- /dev/null +++ b/MediaBrowser.Common/Model/DictionaryBaseItem.cs @@ -0,0 +1,227 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MediaBrowser.Model.Entities;
+using System.IO;
+using MediaBrowser.Common.Json;
+
+namespace MediaBrowser.Common.Model
+{
+ public class DictionaryBaseItem : BaseItem
+ {
+ private Dictionary<string, object> Dictionary { get; set; }
+
+ public DictionaryBaseItem(Dictionary<string, object> dictionary)
+ {
+ Dictionary = dictionary;
+ }
+
+ public override string Name
+ {
+ get
+ {
+ return GetString("Name");
+ }
+ set
+ {
+ SetValue("Name", value);
+ }
+ }
+
+ public override string ArtImagePath
+ {
+ get
+ {
+ return GetString("ArtImagePath");
+ }
+ set
+ {
+ SetValue("ArtImagePath", value);
+ }
+ }
+
+ public override string AspectRatio
+ {
+ get
+ {
+ return GetString("AspectRatio");
+ }
+ set
+ {
+ SetValue("AspectRatio", value);
+ }
+ }
+
+ public override string BannerImagePath
+ {
+ get
+ {
+ return GetString("BannerImagePath");
+ }
+ set
+ {
+ SetValue("BannerImagePath", value);
+ }
+ }
+
+ public override string CustomPin
+ {
+ get
+ {
+ return GetString("CustomPin");
+ }
+ set
+ {
+ SetValue("CustomPin", value);
+ }
+ }
+
+ public override string CustomRating
+ {
+ get
+ {
+ return GetString("CustomRating");
+ }
+ set
+ {
+ SetValue("CustomRating", value);
+ }
+ }
+
+ public override string DisplayMediaType
+ {
+ get
+ {
+ return GetString("DisplayMediaType");
+ }
+ set
+ {
+ SetValue("DisplayMediaType", value);
+ }
+ }
+
+ public override string LogoImagePath
+ {
+ get
+ {
+ return GetString("LogoImagePath");
+ }
+ set
+ {
+ SetValue("LogoImagePath", value);
+ }
+ }
+
+ public override string OfficialRating
+ {
+ get
+ {
+ return GetString("OfficialRating");
+ }
+ set
+ {
+ SetValue("OfficialRating", value);
+ }
+ }
+
+ public override string Overview
+ {
+ get
+ {
+ return GetString("Overview");
+ }
+ set
+ {
+ SetValue("Overview", value);
+ }
+ }
+
+ public override string Path
+ {
+ get
+ {
+ return GetString("Path");
+ }
+ set
+ {
+ SetValue("Path", value);
+ }
+ }
+
+ public override string PrimaryImagePath
+ {
+ get
+ {
+ return GetString("PrimaryImagePath");
+ }
+ set
+ {
+ SetValue("PrimaryImagePath", value);
+ }
+ }
+
+ public override string SortName
+ {
+ get
+ {
+ return GetString("SortName");
+ }
+ set
+ {
+ SetValue("SortName", value);
+ }
+ }
+
+ public override string Tagline
+ {
+ get
+ {
+ return GetString("Tagline");
+ }
+ set
+ {
+ SetValue("Tagline", value);
+ }
+ }
+
+ public override string TrailerUrl
+ {
+ get
+ {
+ return GetString("TrailerUrl");
+ }
+ set
+ {
+ SetValue("TrailerUrl", value);
+ }
+ }
+
+ private string GetString(string name)
+ {
+ return Dictionary[name] as string;
+ }
+
+ private void SetValue<T>(string name, T value)
+ {
+ Dictionary[name] = value;
+ }
+
+ public static DictionaryBaseItem FromApiOutput(Stream stream)
+ {
+ Dictionary<string,object> data = JsonSerializer.DeserializeFromStream<Dictionary<string, object>>(stream);
+
+ if (data.ContainsKey("BaseItem"))
+ {
+ string baseItem = data["BaseItem"] as string;
+
+ data = JsonSerializer.DeserializeFromString<Dictionary<string, object>>(baseItem);
+
+ return new DictionaryBaseItem(data);
+ }
+
+ return new DictionaryBaseItem(data);
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Net/Handlers/JsonHandler.cs b/MediaBrowser.Common/Net/Handlers/JsonHandler.cs index da1234b4e..ecfdd311a 100644 --- a/MediaBrowser.Common/Net/Handlers/JsonHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/JsonHandler.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Common.Net.Handlers {
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Compress, false))
{
- JsonSerializer.Serialize(ObjectToSerialize, gzipStream);
+ JsonSerializer.SerializeToStream(ObjectToSerialize, gzipStream);
}
}
}
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index fc05cbc9a..3438b09c2 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -40,7 +40,7 @@ namespace MediaBrowser.Common.Plugins return new TConfigurationType();
}
- return JsonSerializer.Deserialize<TConfigurationType>(ConfigurationPath);
+ return JsonSerializer.DeserializeFromFile<TConfigurationType>(ConfigurationPath);
}
}
diff --git a/MediaBrowser.Common/packages.config b/MediaBrowser.Common/packages.config index 411c42bfb..15a978d36 100644 --- a/MediaBrowser.Common/packages.config +++ b/MediaBrowser.Common/packages.config @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Newtonsoft.Json" version="4.5.7" targetFramework="net45" />
<package id="Rx-Main" version="1.0.11226" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.8.5" targetFramework="net45" />
</packages>
\ No newline at end of file |
