update portable components

pull/702/head
Luke Pulverenti 8 years ago
parent 2c64cc7d7d
commit 01fc207b62

@ -4,7 +4,7 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Server.Implementations.Serialization
namespace Emby.Common.Implementations.Serialization
{
/// <summary>
/// Provides a wrapper around third party json serialization.

@ -19,10 +19,11 @@
"System.Text.Encoding": "4.0.0.0",
"System.Threading": "4.0.0.0",
"System.Threading.Tasks": "4.0.0.0",
"System.Xml.ReaderWriter": "4.0.0"
"System.Xml.ReaderWriter": "4.0.0"
},
"dependencies": {
"SimpleInjector": "3.2.4",
"ServiceStack.Text": "4.5.4",
"NLog": "4.4.0-betaV15",
"MediaBrowser.Model": {
"target": "project"
@ -30,35 +31,37 @@
"MediaBrowser.Common": {
"target": "project"
}
}
}
},
"netstandard1.6": {
"imports": "dnxcore50",
"dependencies": {
"NETStandard.Library": "1.6.0",
"System.IO.FileSystem.DriveInfo": "4.0.0",
"System.Diagnostics.Process": "4.1.0",
"System.Threading.Timer": "4.0.1",
"System.Net.Requests": "4.0.11",
"System.Xml.ReaderWriter": "4.0.11",
"System.Xml.XmlSerializer": "4.0.11",
"System.Net.Http": "4.1.0",
"System.Net.Primitives": "4.0.11",
"System.Net.Sockets": "4.1.0",
"System.Net.NetworkInformation": "4.1.0",
"System.Net.NameResolution": "4.0.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.Reflection": "4.1.0",
"System.Reflection.Primitives": "4.0.1",
"System.Runtime.Loader": "4.0.0",
"SimpleInjector": "3.2.4",
"System.IO.FileSystem.DriveInfo": "4.0.0",
"System.Diagnostics.Process": "4.1.0",
"System.Threading.Timer": "4.0.1",
"System.Net.Requests": "4.0.11",
"System.Xml.ReaderWriter": "4.0.11",
"System.Xml.XmlSerializer": "4.0.11",
"System.Net.Http": "4.1.0",
"System.Net.Primitives": "4.0.11",
"System.Net.Sockets": "4.1.0",
"System.Net.NetworkInformation": "4.1.0",
"System.Net.NameResolution": "4.0.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.Reflection": "4.1.0",
"System.Reflection.Primitives": "4.0.1",
"System.Runtime.Loader": "4.0.0",
"SimpleInjector": "3.2.4",
"ServiceStack.Text.Core": "1.0.27",
"NLog": "4.4.0-betaV15",
"MediaBrowser.Model": {
"target": "project"
},
"MediaBrowser.Common": {
"target": "project"
} }
}
}
}
}
}

@ -69,6 +69,7 @@
<Compile Include="FileOrganization\OrganizerScheduledTask.cs" />
<Compile Include="FileOrganization\TvFolderOrganizer.cs" />
<Compile Include="HttpServer\GetSwaggerResource.cs" />
<Compile Include="HttpServer\HttpResultFactory.cs" />
<Compile Include="HttpServer\LoggerUtils.cs" />
<Compile Include="HttpServer\RangeRequestWriter.cs" />
<Compile Include="HttpServer\ResponseFilter.cs" />
@ -263,6 +264,9 @@
<Project>{442b5058-dcaf-4263-bb6a-f21e31120a1b}</Project>
<Name>MediaBrowser.Providers</Name>
</ProjectReference>
<Reference Include="ServiceStack">
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.dll</HintPath>
</Reference>
<Reference Include="SocketHttpListener.Portable">
<HintPath>..\ThirdParty\emby\SocketHttpListener.Portable.dll</HintPath>
</Reference>

@ -21,7 +21,7 @@ using IRequest = MediaBrowser.Model.Services.IRequest;
using MimeTypes = MediaBrowser.Model.Net.MimeTypes;
using StreamWriter = Emby.Server.Implementations.HttpServer.StreamWriter;
namespace MediaBrowser.Server.Implementations.HttpServer
namespace Emby.Server.Implementations.HttpServer
{
/// <summary>
/// Class HttpResultFactory
@ -161,13 +161,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public static string GetCompressionType(IRequest request)
{
var prefs = new RequestPreferences(request);
var acceptEncoding = request.Headers["Accept-Encoding"];
if (prefs.AcceptsDeflate)
return "deflate";
if (!string.IsNullOrWhiteSpace(acceptEncoding))
{
if (acceptEncoding.Contains("deflate"))
return "deflate";
if (prefs.AcceptsGzip)
return "gzip";
if (acceptEncoding.Contains("gzip"))
return "gzip";
}
return null;
}
@ -187,14 +190,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer
if (compressionType == null)
{
var contentType = request.ResponseContentType;
var contentTypeAttr = ContentFormat.GetEndpointAttributes(contentType);
switch (contentTypeAttr)
switch (GetRealContentType(contentType))
{
case RequestAttributes.Xml:
case "application/xml":
case "text/xml":
case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml
return SerializeToXmlString(dto);
case RequestAttributes.Json:
case "application/json":
case "text/json":
return _jsonSerializer.SerializeToString(dto);
}
}
@ -204,7 +209,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
using (var compressionStream = GetCompressionStream(ms, compressionType))
{
ContentTypes.Instance.SerializeToStream(request, dto, compressionStream);
compressionStream.Close();
compressionStream.Dispose();
var compressedBytes = ms.ToArray();
@ -221,6 +226,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
}
}
public static string GetRealContentType(string contentType)
{
return contentType == null
? null
: contentType.Split(';')[0].ToLower().Trim();
}
public static string SerializeToXmlString(object from)
{
using (var ms = new MemoryStream())
@ -520,7 +532,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private bool ShouldCompressResponse(IRequest requestContext, string contentType)
{
// It will take some work to support compression with byte range requests
if (!string.IsNullOrEmpty(requestContext.GetHeader("Range")))
if (!string.IsNullOrEmpty(requestContext.Headers.Get("Range")))
{
return false;
}
@ -573,7 +585,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
if (!compress || string.IsNullOrEmpty(requestedCompressionType))
{
var rangeHeader = requestContext.GetHeader("Range");
var rangeHeader = requestContext.Headers.Get("Range");
var stream = await factoryFn().ConfigureAwait(false);
@ -648,7 +660,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
using (var zipStream = new DeflateStream(ms, CompressionMode.Compress))
{
zipStream.Write(bytes, 0, bytes.Length);
zipStream.Close();
zipStream.Dispose();
return ms.ToArray();
}
@ -665,7 +677,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
using (var zipStream = new GZipStream(ms, CompressionMode.Compress))
{
zipStream.Write(buffer, 0, buffer.Length);
zipStream.Close();
zipStream.Dispose();
return ms.ToArray();
}
@ -747,7 +759,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
var isNotModified = true;
var ifModifiedSinceHeader = requestContext.GetHeader("If-Modified-Since");
var ifModifiedSinceHeader = requestContext.Headers.Get("If-Modified-Since");
if (!string.IsNullOrEmpty(ifModifiedSinceHeader))
{
@ -759,7 +771,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
}
}
var ifNoneMatchHeader = requestContext.GetHeader("If-None-Match");
var ifNoneMatchHeader = requestContext.Headers.Get("If-None-Match");
// Validate If-None-Match
if (isNotModified && (cacheKey.HasValue || !string.IsNullOrEmpty(ifNoneMatchHeader)))

@ -127,23 +127,7 @@ namespace Emby.Server.Implementations.Library.Validators
{
var item = _libraryManager.GetPerson(person.Key);
var hasMetdata = !string.IsNullOrWhiteSpace(item.Overview);
var performFullRefresh = !hasMetdata && (DateTime.UtcNow - item.DateLastRefreshed).TotalDays >= 30;
var defaultMetadataRefreshMode = performFullRefresh
? MetadataRefreshMode.FullRefresh
: MetadataRefreshMode.Default;
var imageRefreshMode = performFullRefresh
? ImageRefreshMode.FullRefresh
: ImageRefreshMode.Default;
var options = new MetadataRefreshOptions(_fileSystem)
{
MetadataRefreshMode = person.Value ? defaultMetadataRefreshMode : MetadataRefreshMode.ValidationOnly,
ImageRefreshMode = person.Value ? imageRefreshMode : ImageRefreshMode.ValidationOnly,
ForceSave = performFullRefresh
};
var options = new MetadataRefreshOptions(_fileSystem);
await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
}

@ -28,6 +28,7 @@ using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.Text;
using ServiceStack.Text.Jsv;
using SocketHttpListener.Net;
using SocketHttpListener.Primitives;
@ -87,9 +88,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public override void Configure()
{
HostConfig.Instance.DefaultRedirectPath = DefaultRedirectPath;
HostConfig.Instance.MapExceptionToStatusCode = new Dictionary<Type, int>
var mapExceptionToStatusCode = new Dictionary<Type, int>
{
{typeof (InvalidOperationException), 500},
{typeof (NotImplementedException), 500},
@ -126,21 +125,24 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return _appHost.Resolve<T>();
}
public override T TryResolve<T>()
public override Type[] GetGenericArguments(Type type)
{
return _appHost.TryResolve<T>();
return type.GetGenericArguments();
}
public override object CreateInstance(Type type)
public override bool IsAssignableFrom(Type type1, Type type2)
{
return _appHost.CreateInstance(type);
return type1.IsAssignableFrom(type2);
}
public override void OnConfigLoad()
public override T TryResolve<T>()
{
base.OnConfigLoad();
return _appHost.TryResolve<T>();
}
Config.HandlerFactoryPath = null;
public override object CreateInstance(Type type)
{
return _appHost.CreateInstance(type);
}
protected override ServiceController CreateServiceController(params Assembly[] assembliesWithServices)
@ -156,12 +158,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return this;
}
public static string HandlerFactoryPath;
/// <summary>
/// Starts the Web Service
/// </summary>
private void StartListener()
{
HostContext.Config.HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes.First());
HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes.First());
_listener = GetListener();
@ -610,6 +614,40 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return routes.ToArray();
}
public override object GetTaskResult(Task task, string requestName)
{
try
{
var taskObject = task as Task<object>;
if (taskObject != null)
{
return taskObject.Result;
}
task.Wait();
var type = task.GetType();
if (!type.IsGenericType)
{
return null;
}
Logger.Warn("Getting task result from " + requestName + " using reflection. For better performance have your api return Task<object>");
return type.GetProperty("Result").GetValue(task);
}
catch (TypeAccessException)
{
return null; //return null for void Task's
}
}
public override Func<string, object> GetParseFn(Type propertyType)
{
var fn = JsvReader.GetParseFn(propertyType);
return s => fn(s);
}
public override void SerializeToJson(object o, Stream stream)
{
_jsonSerializer.SerializeToStream(o, stream);

@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Emby.Server.Implementations.HttpServer;
using Emby.Server.Implementations.HttpServer.SocketSharp;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Services;
using ServiceStack;
using ServiceStack.Host;
using SocketHttpListener.Net;
using IHttpFile = MediaBrowser.Model.Services.IHttpFile;
using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;
@ -244,14 +244,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
var specifiedContentType = GetQueryStringContentType(httpReq);
if (!string.IsNullOrEmpty(specifiedContentType)) return specifiedContentType;
var serverDefaultContentType = "application/json";
var acceptContentTypes = httpReq.AcceptTypes;
var defaultContentType = httpReq.ContentType;
if (HasAnyOfContentTypes(httpReq, FormUrlEncoded, MultiPartFormData))
{
defaultContentType = HostContext.Config.DefaultContentType;
defaultContentType = serverDefaultContentType;
}
var customContentTypes = ContentTypes.Instance.ContentTypeFormats.Values;
var preferredContentTypes = new string[] {};
var acceptsAnything = false;
@ -261,7 +262,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
var hasPreferredContentTypes = new bool[preferredContentTypes.Length];
foreach (var acceptsType in acceptContentTypes)
{
var contentType = ContentFormat.GetRealContentType(acceptsType);
var contentType = HttpResultFactory.GetRealContentType(acceptsType);
acceptsAnything = acceptsAnything || contentType == "*/*";
for (var i = 0; i < preferredContentTypes.Length; i++)
@ -285,17 +286,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
{
if (hasDefaultContentType)
return defaultContentType;
if (HostContext.Config.DefaultContentType != null)
return HostContext.Config.DefaultContentType;
}
foreach (var contentType in acceptContentTypes)
{
foreach (var customContentType in customContentTypes)
{
if (contentType.StartsWith(customContentType, StringComparison.OrdinalIgnoreCase))
return customContentType;
}
if (serverDefaultContentType != null)
return serverDefaultContentType;
}
}
@ -305,8 +297,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
}
//We could also send a '406 Not Acceptable', but this is allowed also
return HostContext.Config.DefaultContentType;
return serverDefaultContentType;
}
public const string Soap11 = "text/xml; charset=utf-8";
public static bool HasAnyOfContentTypes(IRequest request, params string[] contentTypes)
@ -342,10 +335,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
if (format.Contains("json")) return "application/json";
if (format.Contains("xml")) return Xml;
string contentType;
ContentTypes.Instance.ContentTypeFormats.TryGetValue(format, out contentType);
return contentType;
return null;
}
public bool HasExplicitResponseContentType { get; private set; }
@ -357,7 +347,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
{
if (this.pathInfo == null)
{
var mode = HostContext.Config.HandlerFactoryPath;
var mode = HttpListenerHost.HandlerFactoryPath;
var pos = request.RawUrl.IndexOf("?");
if (pos != -1)

@ -69,6 +69,10 @@
<HintPath>..\packages\Patterns.Logging.1.0.0.6\lib\portable-net45+win8\Patterns.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ServiceStack.Text, Version=4.5.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Text.4.5.4\lib\net45\ServiceStack.Text.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SharpCompress, Version=0.10.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\SharpCompress\SharpCompress.dll</HintPath>
@ -88,9 +92,6 @@
<Reference Include="ServiceStack">
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text">
<HintPath>..\ThirdParty\ServiceStack.Text\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="UniversalDetector, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UniversalDetector.1.0.1\lib\portable-net45+sl4+wp71+win8+wpa81\UniversalDetector.dll</HintPath>
@ -109,7 +110,6 @@
<Compile Include="Devices\CameraUploadsFolder.cs" />
<Compile Include="EntryPoints\ExternalPortForwarding.cs" />
<Compile Include="HttpServer\HttpListenerHost.cs" />
<Compile Include="HttpServer\HttpResultFactory.cs" />
<Compile Include="HttpServer\ServerFactory.cs" />
<Compile Include="HttpServer\SocketSharp\RequestMono.cs" />
<Compile Include="HttpServer\SocketSharp\WebSocketSharpRequest.cs" />
@ -141,7 +141,6 @@
<Compile Include="Persistence\DataExtensions.cs" />
<Compile Include="Persistence\IDbConnector.cs" />
<Compile Include="Persistence\MediaStreamColumns.cs" />
<Compile Include="Serialization\JsonSerializer.cs" />
<Compile Include="Social\SharingRepository.cs" />
<Compile Include="Persistence\SqliteFileOrganizationRepository.cs" />
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
@ -351,7 +350,9 @@
<None Include="LiveTv\TunerHosts\SatIp\ini\satellite\3594.ini" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Serialization\" />
</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.

@ -5,5 +5,6 @@
<package id="MediaBrowser.Naming" version="1.0.0.59" targetFramework="net46" />
<package id="Microsoft.IO.RecyclableMemoryStream" version="1.1.0.0" targetFramework="net46" />
<package id="Patterns.Logging" version="1.0.0.6" targetFramework="net46" />
<package id="ServiceStack.Text" version="4.5.4" targetFramework="net46" />
<package id="UniversalDetector" version="1.0.1" targetFramework="net46" />
</packages>

@ -77,6 +77,7 @@ using System.Threading.Tasks;
using Emby.Common.Implementations;
using Emby.Common.Implementations.Networking;
using Emby.Common.Implementations.Reflection;
using Emby.Common.Implementations.Serialization;
using Emby.Common.Implementations.TextEncoding;
using Emby.Common.Implementations.Updates;
using Emby.Common.Implementations.Xml;
@ -103,6 +104,7 @@ using Emby.Server.Implementations.Devices;
using Emby.Server.Implementations.Dto;
using Emby.Server.Implementations.EntryPoints;
using Emby.Server.Implementations.FileOrganization;
using Emby.Server.Implementations.HttpServer;
using Emby.Server.Implementations.HttpServer.Security;
using Emby.Server.Implementations.Library;
using Emby.Server.Implementations.LiveTv;
@ -131,7 +133,6 @@ using MediaBrowser.Model.Social;
using MediaBrowser.Model.Text;
using MediaBrowser.Model.Xml;
using MediaBrowser.Server.Implementations.Archiving;
using MediaBrowser.Server.Implementations.Serialization;
using OpenSubtitlesHandler;
using ServiceStack;
using StringExtensions = MediaBrowser.Controller.Extensions.StringExtensions;

Loading…
Cancel
Save