From 8492225deef59b4548976e162f6fa147abf923be Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 10 Nov 2016 22:29:51 -0500 Subject: [PATCH] update portable projects --- .../Emby.Server.Implementations.csproj | 2 + .../HttpServer/HttpListenerHost.cs | 138 ++++++------------ .../Playlists/ManualPlaylistsFolder.cs | 16 +- .../ServerManager/ServerManager.cs | 8 +- MediaBrowser.Controller/Net/IHttpServer.cs | 10 +- MediaBrowser.Controller/Net/IServerManager.cs | 4 +- .../Devices/CameraUploadsFolder.cs | 1 + .../HttpServer/ServerFactory.cs | 39 ----- ...MediaBrowser.Server.Implementations.csproj | 44 +----- .../Persistence/SqliteItemRepository.cs | 2 +- .../packages.config | 5 - .../ApplicationHost.cs | 43 +++++- .../ServerConfigurationManager.cs | 16 +- .../HttpServerFactory.cs | 107 ++++++++++++++ .../MediaBrowser.Server.Startup.Common.csproj | 15 +- .../ServerApplicationPaths.cs | 6 +- .../packages.config | 1 + 17 files changed, 227 insertions(+), 230 deletions(-) rename {MediaBrowser.Server.Implementations => Emby.Server.Implementations}/HttpServer/HttpListenerHost.cs (85%) rename {MediaBrowser.Server.Implementations => Emby.Server.Implementations}/Playlists/ManualPlaylistsFolder.cs (86%) delete mode 100644 MediaBrowser.Server.Implementations/HttpServer/ServerFactory.cs rename {MediaBrowser.Server.Implementations => MediaBrowser.Server.Startup.Common}/Configuration/ServerConfigurationManager.cs (98%) create mode 100644 MediaBrowser.Server.Startup.Common/HttpServerFactory.cs rename {MediaBrowser.Server.Implementations => MediaBrowser.Server.Startup.Common}/ServerApplicationPaths.cs (98%) diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 07f3bd020f..ccdecbf7b6 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -69,6 +69,7 @@ + @@ -172,6 +173,7 @@ + diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs similarity index 85% rename from MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs rename to Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index f0a9c5ca3c..d7897f1659 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -8,12 +8,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Security; -using System.Net.Sockets; using System.Reflection; -using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; -using Emby.Common.Implementations.Net; using Emby.Server.Implementations.HttpServer; using Emby.Server.Implementations.HttpServer.SocketSharp; using MediaBrowser.Common.Net; @@ -25,12 +21,12 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Services; +using MediaBrowser.Model.System; using MediaBrowser.Model.Text; -using ServiceStack.Text.Jsv; using SocketHttpListener.Net; using SocketHttpListener.Primitives; -namespace MediaBrowser.Server.Implementations.HttpServer +namespace Emby.Server.Implementations.HttpServer { public class HttpListenerHost : ServiceStackHost, IHttpServer { @@ -46,8 +42,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer public event EventHandler WebSocketConnected; public event EventHandler WebSocketConnecting; - public string CertificatePath { get; private set; } - private readonly IServerConfigurationManager _config; private readonly INetworkManager _networkManager; private readonly IMemoryStreamFactory _memoryStreamProvider; @@ -60,12 +54,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer private readonly IJsonSerializer _jsonSerializer; private readonly IXmlSerializer _xmlSerializer; + private readonly ICertificate _certificate; + private readonly IEnvironmentInfo _environment; + private readonly IStreamFactory _streamFactory; + private readonly Func> _funcParseFn; public HttpListenerHost(IServerApplicationHost applicationHost, - ILogManager logManager, + ILogger logger, IServerConfigurationManager config, string serviceName, - string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer) + string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer, IEnvironmentInfo environment, ICertificate certificate, IStreamFactory streamFactory, Func> funcParseFn) : base(serviceName, new Assembly[] { }) { _appHost = applicationHost; @@ -77,9 +75,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer _cryptoProvider = cryptoProvider; _jsonSerializer = jsonSerializer; _xmlSerializer = xmlSerializer; + _environment = environment; + _certificate = certificate; + _streamFactory = streamFactory; + _funcParseFn = funcParseFn; _config = config; - _logger = logManager.GetLogger("HttpServer"); + _logger = logger; } public string GlobalResponse { get; set; } @@ -92,11 +94,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer {typeof (NotImplementedException), 500}, {typeof (ResourceNotFoundException), 404}, {typeof (FileNotFoundException), 404}, - {typeof (DirectoryNotFoundException), 404}, + //{typeof (DirectoryNotFoundException), 404}, {typeof (SecurityException), 401}, {typeof (PaymentRequiredException), 402}, {typeof (UnauthorizedAccessException), 500}, - {typeof (ApplicationException), 500}, {typeof (PlatformNotSupportedException), 500}, {typeof (NotSupportedException), 500} }; @@ -123,16 +124,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer return _appHost.Resolve(); } - public override Type[] GetGenericArguments(Type type) - { - return type.GetGenericArguments(); - } - - public override bool IsAssignableFrom(Type type1, Type type2) - { - return type1.IsAssignableFrom(type2); - } - public override T TryResolve() { return _appHost.TryResolve(); @@ -187,34 +178,18 @@ namespace MediaBrowser.Server.Implementations.HttpServer private IHttpListener GetListener() { - var cert = !string.IsNullOrWhiteSpace(CertificatePath) && File.Exists(CertificatePath) - ? GetCert(CertificatePath) : - null; + var enableDualMode = _environment.OperatingSystem == OperatingSystem.Windows; - var enableDualMode = Environment.OSVersion.Platform == PlatformID.Win32NT; - - return new WebSocketSharpListener(_logger, cert, _memoryStreamProvider, _textEncoding, _networkManager, _socketFactory, _cryptoProvider, new StreamFactory(), enableDualMode, GetRequest); - } - - public ICertificate GetCert(string certificateLocation) - { - try - { - X509Certificate2 localCert = new X509Certificate2(certificateLocation); - //localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA; - if (localCert.PrivateKey == null) - { - //throw new FileNotFoundException("Secure requested, no private key included", certificateLocation); - return null; - } - - return new Certificate(localCert); - } - catch (Exception ex) - { - Logger.ErrorException("Error loading cert from {0}", ex, certificateLocation); - return null; - } + return new WebSocketSharpListener(_logger, + _certificate, + _memoryStreamProvider, + _textEncoding, + _networkManager, + _socketFactory, + _cryptoProvider, + _streamFactory, + enableDualMode, + GetRequest); } private IHttpRequest GetRequest(HttpListenerContext httpContext) @@ -328,7 +303,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer // this gets all the query string key value pairs as a collection var newQueryString = MyHttpUtility.ParseQueryString(uri.Query); - if (newQueryString.Count == 0) + var originalCount = newQueryString.Count; + + if (originalCount == 0) { return url; } @@ -336,8 +313,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer // this removes the key if exists newQueryString.Remove(key); + if (originalCount == newQueryString.Count) + { + return url; + } + // this gets the page path from root without QueryString - string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); + string pagePathWithoutQueryString = url.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0]; return newQueryString.Count > 0 ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) @@ -578,28 +560,28 @@ namespace MediaBrowser.Server.Implementations.HttpServer base.Init(); } - public override Model.Services.RouteAttribute[] GetRouteAttributes(Type requestType) + public override RouteAttribute[] GetRouteAttributes(Type requestType) { var routes = base.GetRouteAttributes(requestType).ToList(); var clone = routes.ToList(); foreach (var route in clone) { - routes.Add(new Model.Services.RouteAttribute(NormalizeEmbyRoutePath(route.Path), route.Verbs) + routes.Add(new RouteAttribute(NormalizeEmbyRoutePath(route.Path), route.Verbs) { Notes = route.Notes, Priority = route.Priority, Summary = route.Summary }); - routes.Add(new Model.Services.RouteAttribute(NormalizeRoutePath(route.Path), route.Verbs) + routes.Add(new RouteAttribute(NormalizeRoutePath(route.Path), route.Verbs) { Notes = route.Notes, Priority = route.Priority, Summary = route.Summary }); - routes.Add(new Model.Services.RouteAttribute(DoubleNormalizeEmbyRoutePath(route.Path), route.Verbs) + routes.Add(new RouteAttribute(DoubleNormalizeEmbyRoutePath(route.Path), route.Verbs) { Notes = route.Notes, Priority = route.Priority, @@ -622,14 +604,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer task.Wait(); - var type = task.GetType(); + var type = task.GetType().GetTypeInfo(); if (!type.IsGenericType) { return null; } Logger.Warn("Getting task result from " + requestName + " using reflection. For better performance have your api return Task"); - return type.GetProperty("Result").GetValue(task); + return type.GetDeclaredProperty("Result").GetValue(task); } catch (TypeAccessException) { @@ -639,9 +621,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer public override Func GetParseFn(Type propertyType) { - var fn = JsvReader.GetParseFn(propertyType); - - return s => fn(s); + return _funcParseFn(propertyType); } public override void SerializeToJson(object o, Stream stream) @@ -721,44 +701,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer GC.SuppressFinalize(this); } - public void StartServer(IEnumerable urlPrefixes, string certificatePath) + public void StartServer(IEnumerable urlPrefixes) { - CertificatePath = certificatePath; UrlPrefixes = urlPrefixes.ToList(); Start(UrlPrefixes.First()); } } - - public class StreamFactory : IStreamFactory - { - public Stream CreateNetworkStream(ISocket socket, bool ownsSocket) - { - var netSocket = (NetSocket)socket; - - return new NetworkStream(netSocket.Socket, ownsSocket); - } - - public Task AuthenticateSslStreamAsServer(Stream stream, ICertificate certificate) - { - var sslStream = (SslStream)stream; - var cert = (Certificate)certificate; - - return sslStream.AuthenticateAsServerAsync(cert.X509Certificate); - } - - public Stream CreateSslStream(Stream innerStream, bool leaveInnerStreamOpen) - { - return new SslStream(innerStream, leaveInnerStreamOpen); - } - } - - public class Certificate : ICertificate - { - public Certificate(X509Certificate x509Certificate) - { - X509Certificate = x509Certificate; - } - - public X509Certificate X509Certificate { get; private set; } - } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs b/Emby.Server.Implementations/Playlists/ManualPlaylistsFolder.cs similarity index 86% rename from MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs rename to Emby.Server.Implementations/Playlists/ManualPlaylistsFolder.cs index eff77574d3..8e65ccaf75 100644 --- a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs +++ b/Emby.Server.Implementations/Playlists/ManualPlaylistsFolder.cs @@ -1,16 +1,14 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Playlists; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Playlists; using MediaBrowser.Model.IO; using MediaBrowser.Model.Querying; -using System.Threading.Tasks; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.IO; -namespace MediaBrowser.Server.Implementations.Playlists +namespace Emby.Server.Implementations.Playlists { public class PlaylistsFolder : BasePluginFolder { @@ -39,7 +37,7 @@ namespace MediaBrowser.Server.Implementations.Playlists public override string CollectionType { - get { return Model.Entities.CollectionType.Playlists; } + get { return MediaBrowser.Model.Entities.CollectionType.Playlists; } } protected override Task> GetItemsInternal(InternalItemsQuery query) diff --git a/Emby.Server.Implementations/ServerManager/ServerManager.cs b/Emby.Server.Implementations/ServerManager/ServerManager.cs index f660d01ec5..f7e4c0ce2b 100644 --- a/Emby.Server.Implementations/ServerManager/ServerManager.cs +++ b/Emby.Server.Implementations/ServerManager/ServerManager.cs @@ -112,22 +112,22 @@ namespace Emby.Server.Implementations.ServerManager /// /// Starts this instance. /// - public void Start(IEnumerable urlPrefixes, string certificatePath) + public void Start(IEnumerable urlPrefixes) { - ReloadHttpServer(urlPrefixes, certificatePath); + ReloadHttpServer(urlPrefixes); } /// /// Restarts the Http Server, or starts it if not currently running /// - private void ReloadHttpServer(IEnumerable urlPrefixes, string certificatePath) + private void ReloadHttpServer(IEnumerable urlPrefixes) { _logger.Info("Loading Http Server"); try { HttpServer = _applicationHost.Resolve(); - HttpServer.StartServer(urlPrefixes, certificatePath); + HttpServer.StartServer(urlPrefixes); } catch (Exception ex) { diff --git a/MediaBrowser.Controller/Net/IHttpServer.cs b/MediaBrowser.Controller/Net/IHttpServer.cs index 8c503c199b..f319244dae 100644 --- a/MediaBrowser.Controller/Net/IHttpServer.cs +++ b/MediaBrowser.Controller/Net/IHttpServer.cs @@ -15,19 +15,11 @@ namespace MediaBrowser.Controller.Net /// The URL prefix. IEnumerable UrlPrefixes { get; } - /// - /// Gets the certificate path. - /// - /// The certificate path. - string CertificatePath { get; } - /// /// Starts the specified server name. /// /// The URL prefixes. - /// If an https prefix is specified, - /// the ssl certificate localtion on the file system. - void StartServer(IEnumerable urlPrefixes, string certificatePath); + void StartServer(IEnumerable urlPrefixes); /// /// Stops this instance. diff --git a/MediaBrowser.Controller/Net/IServerManager.cs b/MediaBrowser.Controller/Net/IServerManager.cs index 5191a62e31..202df29824 100644 --- a/MediaBrowser.Controller/Net/IServerManager.cs +++ b/MediaBrowser.Controller/Net/IServerManager.cs @@ -15,9 +15,7 @@ namespace MediaBrowser.Controller.Net /// Starts this instance. /// /// The URL prefixes. - /// If an https prefix is specified, - /// the ssl certificate localtion on the file system. - void Start(IEnumerable urlPrefixes, string certificatePath); + void Start(IEnumerable urlPrefixes); /// /// Sends a message to all clients currently connected via a web socket diff --git a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs index 19a0593e3b..882701885e 100644 --- a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs +++ b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs @@ -10,6 +10,7 @@ using MediaBrowser.Common.IO; using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Serialization; namespace MediaBrowser.Server.Implementations.Devices { diff --git a/MediaBrowser.Server.Implementations/HttpServer/ServerFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/ServerFactory.cs deleted file mode 100644 index abcf84abda..0000000000 --- a/MediaBrowser.Server.Implementations/HttpServer/ServerFactory.cs +++ /dev/null @@ -1,39 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Cryptography; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; -using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Text; - -namespace MediaBrowser.Server.Implementations.HttpServer -{ - /// - /// Class ServerFactory - /// - public static class ServerFactory - { - /// - /// Creates the server. - /// - /// IHttpServer. - public static IHttpServer CreateServer(IServerApplicationHost applicationHost, - ILogManager logManager, - IServerConfigurationManager config, - INetworkManager networkmanager, - IMemoryStreamFactory streamProvider, - string serverName, - string defaultRedirectpath, - ITextEncoding textEncoding, - ISocketFactory socketFactory, - ICryptoProvider cryptoProvider, - IJsonSerializer json, - IXmlSerializer xml) - { - return new HttpListenerHost(applicationHost, logManager, config, serverName, defaultRedirectpath, networkmanager, streamProvider, textEncoding, socketFactory, cryptoProvider, json, xml); - } - } -} diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 6fb4f9e36d..8d5697c49c 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -42,21 +42,10 @@ 4 - - ..\ThirdParty\emby\Emby.Common.Implementations.dll - - - ..\packages\Emby.XmlTv.1.0.0.63\lib\portable-net45+win8\Emby.XmlTv.dll - True - ..\packages\ini-parser.2.3.0\lib\net20\INIFileParser.dll True - - ..\packages\MediaBrowser.Naming.1.0.0.59\lib\portable-net45+win8\MediaBrowser.Naming.dll - True - ..\packages\Microsoft.IO.RecyclableMemoryStream.1.1.0.0\lib\net45\Microsoft.IO.RecyclableMemoryStream.dll True @@ -65,38 +54,18 @@ False ..\ThirdParty\emby\Mono.Nat.dll - - ..\packages\Patterns.Logging.1.0.0.6\lib\portable-net45+win8\Patterns.Logging.dll - True - - - ..\packages\ServiceStack.Text.4.5.4\lib\net45\ServiceStack.Text.dll - True - False ..\ThirdParty\SharpCompress\SharpCompress.dll - - ..\ThirdParty\emby\SocketHttpListener.Portable.dll - - - - - ..\ThirdParty\ServiceStack\ServiceStack.dll - - - ..\packages\UniversalDetector.1.0.1\lib\portable-net45+sl4+wp71+win8+wpa81\UniversalDetector.dll - True - @@ -105,12 +74,9 @@ - - - @@ -143,10 +109,8 @@ - - @@ -170,10 +134,6 @@ {7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B} MediaBrowser.Model - - {442b5058-dcaf-4263-bb6a-f21e31120a1b} - MediaBrowser.Providers - @@ -348,9 +308,7 @@ - - - +