aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ApiInteraction
diff options
context:
space:
mode:
authorLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-09-05 19:40:44 -0400
committerLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-09-05 19:40:44 -0400
commit0fb0d52a4c5732eb254e1f778835a28efddccf5f (patch)
treef28ef7a89a44c82c1142f9e5622075e4d45caeee /MediaBrowser.ApiInteraction
parent5dd70800840eef8d26d3a2223ac9bdee444a32cb (diff)
Made a separate ApiInteraction solution with platform-specific builds
Diffstat (limited to 'MediaBrowser.ApiInteraction')
-rw-r--r--MediaBrowser.ApiInteraction/ApiClient.cs30
-rw-r--r--MediaBrowser.ApiInteraction/DataSerializer.cs49
-rw-r--r--MediaBrowser.ApiInteraction/IDataSerializer.cs22
-rw-r--r--MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj32
-rw-r--r--MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs12
-rw-r--r--MediaBrowser.ApiInteraction/packages.config4
6 files changed, 92 insertions, 57 deletions
diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs
index 18d6ddc210..8e3327f01a 100644
--- a/MediaBrowser.ApiInteraction/ApiClient.cs
+++ b/MediaBrowser.ApiInteraction/ApiClient.cs
@@ -18,6 +18,8 @@ namespace MediaBrowser.ApiInteraction
handler.AutomaticDecompression = DecompressionMethods.Deflate;
HttpClient = new HttpClient(handler);
+
+ DataSerializer.Configure();
}
/// <summary>
@@ -48,24 +50,11 @@ namespace MediaBrowser.ApiInteraction
{
get
{
- // First try Protobuf since it has the best performance
- if (DataSerializer.CanDeserializeProtobuf)
- {
- return ApiInteraction.SerializationFormat.Protobuf;
- }
-
- // Next best is jsv
- if (DataSerializer.CanDeserializeJsv)
- {
- return ApiInteraction.SerializationFormat.Jsv;
- }
-
- return ApiInteraction.SerializationFormat.Json;
+ return ApiInteraction.SerializationFormat.Jsv;
}
}
public HttpClient HttpClient { get; private set; }
- public IDataSerializer DataSerializer { get; set; }
/// <summary>
/// Gets an image url that can be used to download an image from the api
@@ -597,7 +586,7 @@ namespace MediaBrowser.ApiInteraction
string url = ApiUrl + "/ServerConfiguration";
// At the moment this can't be retrieved in protobuf format
- SerializationFormat format = DataSerializer.CanDeserializeJsv ? SerializationFormat.Jsv : ApiInteraction.SerializationFormat.Json;
+ SerializationFormat format = SerializationFormat.Jsv;
using (Stream stream = await GetSerializedStreamAsync(url, format).ConfigureAwait(false))
{
@@ -613,7 +602,7 @@ namespace MediaBrowser.ApiInteraction
string url = ApiUrl + "/PluginConfiguration?assemblyfilename=" + plugin.AssemblyFileName;
// At the moment this can't be retrieved in protobuf format
- SerializationFormat format = DataSerializer.CanDeserializeJsv ? SerializationFormat.Jsv : ApiInteraction.SerializationFormat.Json;
+ SerializationFormat format = SerializationFormat.Jsv;
using (Stream stream = await GetSerializedStreamAsync(url, format).ConfigureAwait(false))
{
@@ -708,7 +697,7 @@ namespace MediaBrowser.ApiInteraction
{
if (format == ApiInteraction.SerializationFormat.Protobuf)
{
- return DataSerializer.DeserializeProtobufFromStream(stream, type);
+ throw new NotImplementedException();
}
if (format == ApiInteraction.SerializationFormat.Jsv)
{
@@ -731,11 +720,4 @@ namespace MediaBrowser.ApiInteraction
HttpClient.Dispose();
}
}
-
- public enum SerializationFormat
- {
- Json,
- Jsv,
- Protobuf
- }
}
diff --git a/MediaBrowser.ApiInteraction/DataSerializer.cs b/MediaBrowser.ApiInteraction/DataSerializer.cs
new file mode 100644
index 0000000000..15039cd45a
--- /dev/null
+++ b/MediaBrowser.ApiInteraction/DataSerializer.cs
@@ -0,0 +1,49 @@
+using System;
+using System.IO;
+using ProtoBuf;
+using ServiceStack.Text;
+
+namespace MediaBrowser.ApiInteraction
+{
+ public static class DataSerializer
+ {
+ public static T DeserializeJsonFromStream<T>(Stream stream)
+ {
+ return JsonSerializer.DeserializeFromStream<T>(stream);
+ }
+
+ public static T DeserializeJsvFromStream<T>(Stream stream)
+ {
+ return TypeSerializer.DeserializeFromStream<T>(stream);
+ }
+
+ public static object DeserializeJsvFromStream(Stream stream, Type type)
+ {
+ return TypeSerializer.DeserializeFromStream(type, stream);
+ }
+
+ public static object DeserializeJsonFromStream(Stream stream, Type type)
+ {
+ return JsonSerializer.DeserializeFromStream(type, stream);
+ }
+
+ public static T DeserializeProtobufFromStream<T>(Stream stream)
+ {
+ return Serializer.Deserialize<T>(stream);
+ }
+
+ public static void Configure()
+ {
+ JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601;
+ JsConfig.ExcludeTypeInfo = true;
+ JsConfig.IncludeNullValues = false;
+ }
+ }
+
+ public enum SerializationFormat
+ {
+ Json,
+ Jsv,
+ Protobuf
+ }
+}
diff --git a/MediaBrowser.ApiInteraction/IDataSerializer.cs b/MediaBrowser.ApiInteraction/IDataSerializer.cs
deleted file mode 100644
index 33bac96df8..0000000000
--- a/MediaBrowser.ApiInteraction/IDataSerializer.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using System.IO;
-
-namespace MediaBrowser.ApiInteraction
-{
- /// <summary>
- /// Since ServiceStack Json is not portable, we need to abstract required json functions into an interface
- /// </summary>
- public interface IDataSerializer
- {
- T DeserializeJsonFromStream<T>(Stream stream);
- T DeserializeJsvFromStream<T>(Stream stream);
- T DeserializeProtobufFromStream<T>(Stream stream);
-
- object DeserializeJsonFromStream(Stream stream, Type type);
- object DeserializeJsvFromStream(Stream stream, Type type);
- object DeserializeProtobufFromStream(Stream stream, Type type);
-
- bool CanDeserializeJsv { get; }
- bool CanDeserializeProtobuf { get; }
- }
-}
diff --git a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj
index 93c6acec9e..62a60f86cc 100644
--- a/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj
+++ b/MediaBrowser.ApiInteraction/MediaBrowser.ApiInteraction.csproj
@@ -4,15 +4,13 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProjectGuid>{B1C27231-7017-4C9B-A678-DE891954FA38}</ProjectGuid>
+ <ProjectGuid>{921C0F64-FDA7-4E9F-9E73-0CB0EEDB2422}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaBrowser.ApiInteraction</RootNamespace>
<AssemblyName>MediaBrowser.ApiInteraction</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
- <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -32,18 +30,36 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <!-- A reference to the entire .NET Framework is automatically included -->
+ <Reference Include="protobuf-net">
+ <HintPath>..\protobuf-net\Full\net30\protobuf-net.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Text">
+ <HintPath>..\packages\ServiceStack.Text.3.9.5\lib\net35\ServiceStack.Text.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ApiClient.cs" />
+ <Compile Include="DataSerializer.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">
<Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
<Name>MediaBrowser.Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <Compile Include="ApiClient.cs" />
- <Compile Include="IDataSerializer.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
+ <None Include="packages.config" />
</ItemGroup>
- <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
+ <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.
<Target Name="BeforeBuild">
diff --git a/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs b/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs
index a788c5f71e..5dd263f0a0 100644
--- a/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
-using System.Resources;
-using System.Reflection;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -14,7 +13,14 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-[assembly: NeutralResourcesLanguage("en")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("677618f2-de4b-44f4-8dfd-a90176297ee2")]
// Version information for an assembly consists of the following four values:
//
diff --git a/MediaBrowser.ApiInteraction/packages.config b/MediaBrowser.ApiInteraction/packages.config
new file mode 100644
index 0000000000..c9218be3cd
--- /dev/null
+++ b/MediaBrowser.ApiInteraction/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="ServiceStack.Text" version="3.9.5" targetFramework="net45" />
+</packages> \ No newline at end of file