The Free Software Media System - Server Backend & API
move classes
Luke Pulverenti8ef442c2e8f3
diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.csindex c5798a5d1b..c348e658cc 100644--- a/Emby.Dlna/DlnaManager.cs+++ b/Emby.Dlna/DlnaManager.cs@@ -560,17 +560,19 @@ namespace Emby.Dlna? ImageFormat.Png: ImageFormat.Jpg;+ var resource = GetType().Namespace + ".Images." + filename.ToLower();+#if NET46return new ImageStream{Format = format,- Stream = GetType().Assembly.GetManifestResourceStream("MediaBrowser.Dlna.Images." + filename.ToLower())+ Stream = GetType().Assembly.GetManifestResourceStream(resource)};#elif NETSTANDARD1_6return new ImageStream{Format = format,- Stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream("MediaBrowser.Dlna.Images." + filename.ToLower())+ Stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream(resource)};#endifthrow new NotImplementedException();diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csprojindex 152a165e21..7829193c53 100644--- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj+++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj@@ -131,6 +131,8 @@<Compile Include="ScheduledTasks\RefreshIntrosTask.cs" /><Compile Include="ScheduledTasks\RefreshMediaLibraryTask.cs" /><Compile Include="ScheduledTasks\SystemUpdateTask.cs" />+ <Compile Include="ServerManager\ServerManager.cs" />+ <Compile Include="ServerManager\WebSocketConnection.cs" /><Compile Include="Sorting\AiredEpisodeOrderComparer.cs" /><Compile Include="Sorting\AirTimeComparer.cs" /><Compile Include="Sorting\AlbumArtistComparer.cs" />@@ -178,6 +180,7 @@<Compile Include="Sync\SyncNotificationEntryPoint.cs" /><Compile Include="Sync\SyncRegistrationInfo.cs" /><Compile Include="Sync\TargetDataProvider.cs" />+ <Compile Include="TV\SeriesPostScanTask.cs" /><Compile Include="TV\TVSeriesManager.cs" /><Compile Include="Updates\InstallationManager.cs" /><Compile Include="UserViews\CollectionFolderImageProvider.cs" />@@ -197,6 +200,10 @@<Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project><Name>MediaBrowser.Model</Name></ProjectReference>+ <ProjectReference Include="..\MediaBrowser.Providers\MediaBrowser.Providers.csproj">+ <Project>{442b5058-dcaf-4263-bb6a-f21e31120a1b}</Project>+ <Name>MediaBrowser.Providers</Name>+ </ProjectReference></ItemGroup><Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /><!-- To modify your build process, add your task inside one of the targets below and uncomment it.diff --git a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs b/Emby.Server.Implementations/ServerManager/ServerManager.cssimilarity index 93%rename from MediaBrowser.Server.Implementations/ServerManager/ServerManager.csrename to Emby.Server.Implementations/ServerManager/ServerManager.csindex 4e706324f9..83ce0b6a35 100644--- a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs+++ b/Emby.Server.Implementations/ServerManager/ServerManager.cs@@ -10,14 +10,14 @@ using System;using System.Collections.Generic;using System.Collections.Specialized;using System.Linq;-using System.Net.Sockets;using System.Threading;using System.Threading.Tasks;using MediaBrowser.Common.IO;using MediaBrowser.Model.IO;using MediaBrowser.Model.Services;+using MediaBrowser.Model.TextEncoding;-namespace MediaBrowser.Server.Implementations.ServerManager+namespace Emby.Server.Implementations.ServerManager{/// <summary>/// Manages the Http Server, Udp Server and WebSocket connections@@ -76,6 +76,7 @@ namespace MediaBrowser.Server.Implementations.ServerManagerprivate bool _disposed;private readonly IMemoryStreamProvider _memoryStreamProvider;+ private readonly IEncoding _textEncoding;/// <summary>/// Initializes a new instance of the <see cref="ServerManager" /> class.@@ -85,7 +86,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager/// <param name="logger">The logger.</param>/// <param name="configurationManager">The configuration manager.</param>/// <exception cref="System.ArgumentNullException">applicationHost</exception>- public ServerManager(IServerApplicationHost applicationHost, IJsonSerializer jsonSerializer, ILogger logger, IServerConfigurationManager configurationManager, IMemoryStreamProvider memoryStreamProvider)+ public ServerManager(IServerApplicationHost applicationHost, IJsonSerializer jsonSerializer, ILogger logger, IServerConfigurationManager configurationManager, IMemoryStreamProvider memoryStreamProvider, IEncoding textEncoding){if (applicationHost == null){@@ -105,6 +106,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager_applicationHost = applicationHost;ConfigurationManager = configurationManager;_memoryStreamProvider = memoryStreamProvider;+ _textEncoding = textEncoding;}/// <summary>@@ -127,15 +129,13 @@ namespace MediaBrowser.Server.Implementations.ServerManagerHttpServer = _applicationHost.Resolve<IHttpServer>();HttpServer.StartServer(urlPrefixes, certificatePath);}- catch (SocketException ex)- {- _logger.ErrorException("The http server is unable to start due to a Socket error. This can occasionally happen when the operating system takes longer than usual to release the IP bindings from the previous session. This can take up to five minutes. Please try waiting or rebooting the system.", ex);-- throw;- }catch (Exception ex){- _logger.ErrorException("Error starting Http Server", ex);+ var msg = string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase)+ ? "The http server is unable to start due to a Socket error. This can occasionally happen when the operating system takes longer than usual to release the IP bindings from the previous session. This can take up to five minutes. Please try waiting or rebooting the system."+ : "Error starting Http Server";++ _logger.ErrorException(msg, ex);throw;}@@ -155,7 +155,7 @@ namespace MediaBrowser.Server.Implementations.ServerManagerreturn;}- var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger, _memoryStreamProvider)+ var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger, _memoryStreamProvider, _textEncoding){OnReceive = ProcessWebSocketMessageReceived,Url = e.Url,diff --git a/MediaBrowser.Server.Implementations/ServerManager/WebSocketConnection.cs b/Emby.Server.Implementations/ServerManager/WebSocketConnection.cssimilarity index 95%rename from MediaBrowser.Server.Implementations/ServerManager/WebSocketConnection.csrename to Emby.Server.Implementations/ServerManager/WebSocketConnection.csindex c1bd8ed6b0..dd17edea52 100644--- a/MediaBrowser.Server.Implementations/ServerManager/WebSocketConnection.cs+++ b/Emby.Server.Implementations/ServerManager/WebSocketConnection.cs@@ -12,9 +12,10 @@ using System.Threading.Tasks;using MediaBrowser.Common.IO;using MediaBrowser.Model.IO;using MediaBrowser.Model.Services;+using MediaBrowser.Model.TextEncoding;using UniversalDetector;-namespace MediaBrowser.Server.Implementations.ServerManager+namespace Emby.Server.Implementations.ServerManager{/// <summary>/// Class WebSocketConnection@@ -77,6 +78,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager/// <value>The query string.</value>public QueryParamCollection QueryString { get; set; }private readonly IMemoryStreamProvider _memoryStreamProvider;+ private readonly IEncoding _textEncoding;/// <summary>/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.@@ -86,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager/// <param name="jsonSerializer">The json serializer.</param>/// <param name="logger">The logger.</param>/// <exception cref="System.ArgumentNullException">socket</exception>- public WebSocketConnection(IWebSocket socket, string remoteEndPoint, IJsonSerializer jsonSerializer, ILogger logger, IMemoryStreamProvider memoryStreamProvider)+ public WebSocketConnection(IWebSocket socket, string remoteEndPoint, IJsonSerializer jsonSerializer, ILogger logger, IMemoryStreamProvider memoryStreamProvider, IEncoding textEncoding){if (socket == null){@@ -113,6 +115,7 @@ namespace MediaBrowser.Server.Implementations.ServerManagerRemoteEndPoint = remoteEndPoint;_logger = logger;_memoryStreamProvider = memoryStreamProvider;+ _textEncoding = textEncoding;socket.Closed += socket_Closed;}@@ -138,11 +141,11 @@ namespace MediaBrowser.Server.Implementations.ServerManagerif (string.Equals(charset, "utf-8", StringComparison.OrdinalIgnoreCase)){- OnReceiveInternal(Encoding.UTF8.GetString(bytes));+ OnReceiveInternal(Encoding.UTF8.GetString(bytes, 0, bytes.Length));}else{- OnReceiveInternal(Encoding.ASCII.GetString(bytes));+ OnReceiveInternal(_textEncoding.GetASCIIString(bytes, 0, bytes.Length));}}private string DetectCharset(byte[] bytes)diff --git a/MediaBrowser.Server.Implementations/TV/SeriesPostScanTask.cs b/Emby.Server.Implementations/TV/SeriesPostScanTask.cssimilarity index 94%rename from MediaBrowser.Server.Implementations/TV/SeriesPostScanTask.csrename to Emby.Server.Implementations/TV/SeriesPostScanTask.csindex a498dfec3c..2e04c883fa 100644--- a/MediaBrowser.Server.Implementations/TV/SeriesPostScanTask.cs+++ b/Emby.Server.Implementations/TV/SeriesPostScanTask.cs@@ -14,10 +14,11 @@ using MediaBrowser.Model.Globalization;using MediaBrowser.Model.IO;using MediaBrowser.Model.Logging;using MediaBrowser.Model.Tasks;+using MediaBrowser.Model.Threading;using MediaBrowser.Model.Xml;using MediaBrowser.Providers.TV;-namespace MediaBrowser.Server.Implementations.TV+namespace Emby.Server.Implementations.TV{class SeriesGroup : List<Series>, IGrouping<string, Series>{@@ -132,8 +133,9 @@ namespace MediaBrowser.Server.Implementations.TVprivate const int LibraryUpdateDuration = 180000;private readonly ITaskManager _taskManager;private readonly IXmlReaderSettingsFactory _xmlSettings;+ private readonly ITimerFactory _timerFactory;- public CleanMissingEpisodesEntryPoint(ILibraryManager libraryManager, IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, IFileSystem fileSystem, ITaskManager taskManager, IXmlReaderSettingsFactory xmlSettings)+ public CleanMissingEpisodesEntryPoint(ILibraryManager libraryManager, IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, IFileSystem fileSystem, ITaskManager taskManager, IXmlReaderSettingsFactory xmlSettings, ITimerFactory timerFactory){_libraryManager = libraryManager;_config = config;@@ -142,9 +144,10 @@ namespace MediaBrowser.Server.Implementations.TV_fileSystem = fileSystem;_taskManager = taskManager;_xmlSettings = xmlSettings;+ _timerFactory = timerFactory;}- private Timer LibraryUpdateTimer { get; set; }+ private ITimer LibraryUpdateTimer { get; set; }public void Run(){@@ -162,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.TV{if (LibraryUpdateTimer == null){- LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite);+ LibraryUpdateTimer = _timerFactory.Create(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite);}else{diff --git a/Emby.Server.Implementations/project.json b/Emby.Server.Implementations/project.jsonindex 81f816753c..9d80f8ce42 100644--- a/Emby.Server.Implementations/project.json+++ b/Emby.Server.Implementations/project.json@@ -1,7 +1,8 @@{"supports": {},"dependencies": {- "MediaBrowser.Naming": "1.0.0.59"+ "MediaBrowser.Naming": "1.0.0.59",+ "UniversalDetector": "1.0.1"},"frameworks": {".NETPortable,Version=v4.5,Profile=Profile7": {}diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.csindex 769b7821ab..565eeb259b 100644--- a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs+++ b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs@@ -14,13 +14,13 @@ using System.Threading.Tasks;using MediaBrowser.Common.IO;using MediaBrowser.Controller.IO;using MediaBrowser.Model.IO;-using MediaBrowser.Server.Implementations.Threading;+using MediaBrowser.Model.Threading;namespace MediaBrowser.Server.Implementations.Connect{public class ConnectEntryPoint : IServerEntryPoint{- private PeriodicTimer _timer;+ private ITimer _timer;private readonly IHttpClient _httpClient;private readonly IApplicationPaths _appPaths;private readonly ILogger _logger;@@ -29,8 +29,9 @@ namespace MediaBrowser.Server.Implementations.Connectprivate readonly INetworkManager _networkManager;private readonly IApplicationHost _appHost;private readonly IFileSystem _fileSystem;+ private readonly ITimerFactory _timerFactory;- public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost, IFileSystem fileSystem)+ public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost, IFileSystem fileSystem, ITimerFactory timerFactory){_httpClient = httpClient;_appPaths = appPaths;@@ -39,13 +40,14 @@ namespace MediaBrowser.Server.Implementations.Connect_connectManager = connectManager;_appHost = appHost;_fileSystem = fileSystem;+ _timerFactory = timerFactory;}public void Run(){LoadCachedAddress();- _timer = new PeriodicTimer(TimerCallback, null, TimeSpan.FromSeconds(5), TimeSpan.FromHours(1));+ _timer = _timerFactory.Create(TimerCallback, null, TimeSpan.FromSeconds(5), TimeSpan.FromHours(1));((ConnectManager)_connectManager).Start();}diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.csindex d86990a408..dcfa27cc04 100644--- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs+++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs@@ -11,7 +11,7 @@ using System.Net;using MediaBrowser.Common.Net;using MediaBrowser.Model.Dlna;using MediaBrowser.Model.Events;-using MediaBrowser.Server.Implementations.Threading;+using MediaBrowser.Model.Threading;namespace MediaBrowser.Server.Implementations.EntryPoints{@@ -23,16 +23,18 @@ namespace MediaBrowser.Server.Implementations.EntryPointsprivate readonly IServerConfigurationManager _config;private readonly IDeviceDiscovery _deviceDiscovery;- private PeriodicTimer _timer;+ private ITimer _timer;private bool _isStarted;+ private readonly ITimerFactory _timerFactory;- public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient)+ public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, ITimerFactory timerFactory){_logger = logmanager.GetLogger("PortMapper");_appHost = appHost;_config = config;_deviceDiscovery = deviceDiscovery;_httpClient = httpClient;+ _timerFactory = timerFactory;}private string _lastConfigIdentifier;@@ -94,7 +96,7 @@ namespace MediaBrowser.Server.Implementations.EntryPointsNatUtility.StartDiscovery();- _timer = new PeriodicTimer(ClearCreatedRules, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));+ _timer = _timerFactory.Create(ClearCreatedRules, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));_deviceDiscovery.DeviceDiscovered += _deviceDiscovery_DeviceDiscovered;diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csprojindex 5d1d2fc38c..adc5d68792 100644--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj@@ -207,8 +207,6 @@<Compile Include="Serialization\JsonSerializer.cs" /><Compile Include="Social\SharingManager.cs" /><Compile Include="Social\SharingRepository.cs" />- <Compile Include="Threading\PeriodicTimer.cs" />- <Compile Include="TV\SeriesPostScanTask.cs" /><Compile Include="Persistence\SqliteFileOrganizationRepository.cs" /><Compile Include="Notifications\SqliteNotificationsRepository.cs" /><Compile Include="Persistence\TypeMapper.cs" />@@ -217,8 +215,6 @@<Compile Include="Security\AuthenticationRepository.cs" /><Compile Include="Security\EncryptionManager.cs" /><Compile Include="ServerApplicationPaths.cs" />- <Compile Include="ServerManager\ServerManager.cs" />- <Compile Include="ServerManager\WebSocketConnection.cs" /><Compile Include="Session\HttpSessionController.cs" /><Compile Include="Session\SessionManager.cs"><SubType>Code</SubType>diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.csindex 11d401670f..19b8ad2f97 100644--- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs+++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs@@ -62,7 +62,6 @@ using MediaBrowser.Server.Implementations.Localization;using MediaBrowser.Server.Implementations.Notifications;using MediaBrowser.Server.Implementations.Persistence;using MediaBrowser.Server.Implementations.Security;-using MediaBrowser.Server.Implementations.ServerManager;using MediaBrowser.Server.Implementations.Session;using MediaBrowser.Server.Implementations.Social;using MediaBrowser.Server.Implementations.Sync;@@ -113,6 +112,7 @@ using Emby.Server.Implementations.MediaEncoder;using Emby.Server.Implementations.Notifications;using Emby.Server.Implementations.Persistence;using Emby.Server.Implementations.Playlists;+using Emby.Server.Implementations.ServerManager;using Emby.Server.Implementations.Sync;using Emby.Server.Implementations.TV;using Emby.Server.Implementations.Updates;@@ -603,7 +603,7 @@ namespace MediaBrowser.Server.Startup.CommonRegisterSingleInstance(HttpServer, false);progress.Report(10);- ServerManager = new ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager, MemoryStreamProvider);+ ServerManager = new ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager, MemoryStreamProvider, textEncoding);RegisterSingleInstance(ServerManager);var innerProgress = new ActionableProgress<double>();diff --git a/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs b/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.csindex 79debce8da..95b42afbf9 100644--- a/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs+++ b/MediaBrowser.Server.Startup.Common/EntryPoints/KeepServerAwake.cs@@ -4,7 +4,7 @@ using MediaBrowser.Controller.Session;using MediaBrowser.Model.Logging;using System;using System.Linq;-using MediaBrowser.Server.Implementations.Threading;+using MediaBrowser.Server.Startup.Common.Threading;namespace MediaBrowser.Server.Startup.Common.EntryPoints{diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csprojindex 6a84ee0c5a..4aecb11dc9 100644--- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj+++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj@@ -95,6 +95,7 @@<Compile Include="Properties\AssemblyInfo.cs" /><Compile Include="StartupOptions.cs" /><Compile Include="SystemEvents.cs" />+ <Compile Include="Threading\PeriodicTimer.cs" /><Compile Include="UnhandledExceptionWriter.cs" /></ItemGroup><ItemGroup>diff --git a/MediaBrowser.Server.Implementations/Threading/PeriodicTimer.cs b/MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cssimilarity index 87%rename from MediaBrowser.Server.Implementations/Threading/PeriodicTimer.csrename to MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.csindex 057a84483b..3e898adfdf 100644--- a/MediaBrowser.Server.Implementations/Threading/PeriodicTimer.cs+++ b/MediaBrowser.Server.Startup.Common/Threading/PeriodicTimer.cs@@ -2,7 +2,7 @@using System.Threading;using Microsoft.Win32;-namespace MediaBrowser.Server.Implementations.Threading+namespace MediaBrowser.Server.Startup.Common.Threading{public class PeriodicTimer : IDisposable{@@ -46,13 +46,13 @@ namespace MediaBrowser.Server.Implementations.Threading{_timer = new Timer(TimerCallback, _state, dueTime, _period);- SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;+ Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;}}private void DisposeTimer(){- SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;+ Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;lock (_timerLock){