mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-17 11:43:44 +01:00
Made a separate ApiInteraction solution with platform-specific builds
This commit is contained in:
parent
5dd7080084
commit
0fb0d52a4c
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
49
MediaBrowser.ApiInteraction/DataSerializer.cs
Normal file
49
MediaBrowser.ApiInteraction/DataSerializer.cs
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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">
|
||||
|
||||
@@ -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:
|
||||
//
|
||||
|
||||
4
MediaBrowser.ApiInteraction/packages.config
Normal file
4
MediaBrowser.ApiInteraction/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ServiceStack.Text" version="3.9.5" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user