diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-02-20 15:50:58 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-02-20 15:50:58 -0500 |
| commit | 5d55b36487b25b2efaf6923a3c069f4b0b59a449 (patch) | |
| tree | dacf7607a28bf65a67004f65fdb1f1e33f3c075f /Emby.Server.Core | |
| parent | de3ca87a763506badcf1518ae288a5736605445c (diff) | |
make more classes portable
Diffstat (limited to 'Emby.Server.Core')
| -rw-r--r-- | Emby.Server.Core/ApplicationHost.cs | 7 | ||||
| -rw-r--r-- | Emby.Server.Core/Configuration/ServerConfigurationManager.cs | 245 | ||||
| -rw-r--r-- | Emby.Server.Core/Logging/ConsoleLogger.cs | 16 | ||||
| -rw-r--r-- | Emby.Server.Core/ServerApplicationPaths.cs | 233 | ||||
| -rw-r--r-- | Emby.Server.Core/UnhandledExceptionWriter.cs | 38 |
5 files changed, 20 insertions, 519 deletions
diff --git a/Emby.Server.Core/ApplicationHost.cs b/Emby.Server.Core/ApplicationHost.cs index c3d88eeab1..a8866fc970 100644 --- a/Emby.Server.Core/ApplicationHost.cs +++ b/Emby.Server.Core/ApplicationHost.cs @@ -83,7 +83,6 @@ using Emby.Dlna.MediaReceiverRegistrar; using Emby.Dlna.Ssdp; using Emby.Server.Core; using Emby.Server.Implementations.Activity; -using Emby.Server.Core.Configuration; using Emby.Server.Implementations.Devices; using Emby.Server.Implementations.FFMpeg; using Emby.Server.Core.IO; @@ -94,7 +93,6 @@ using Emby.Server.Implementations.Social; using Emby.Server.Implementations.Sync; using Emby.Server.Implementations.Channels; using Emby.Server.Implementations.Collections; -using Emby.Server.Implementations.Connect; using Emby.Server.Implementations.Dto; using Emby.Server.Implementations.EntryPoints; using Emby.Server.Implementations.FileOrganization; @@ -134,6 +132,7 @@ using Emby.Drawing; using Emby.Server.Implementations.Migrations; using MediaBrowser.Model.Diagnostics; using Emby.Common.Implementations.Diagnostics; +using Emby.Server.Implementations.Configuration; namespace Emby.Server.Core { @@ -526,6 +525,8 @@ namespace Emby.Server.Core } } + protected abstract IConnectManager CreateConnectManager(); + /// <summary> /// Registers resources that classes will depend on /// </summary> @@ -635,7 +636,7 @@ namespace Emby.Server.Core var encryptionManager = new EncryptionManager(); RegisterSingleInstance<IEncryptionManager>(encryptionManager); - ConnectManager = new ConnectManager(LogManager.GetLogger("ConnectManager"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager, FileSystemManager); + ConnectManager = CreateConnectManager(); RegisterSingleInstance(ConnectManager); DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, LogManager.GetLogger("DeviceManager"), FileSystemManager), UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager, LogManager.GetLogger("DeviceManager"), NetworkManager); diff --git a/Emby.Server.Core/Configuration/ServerConfigurationManager.cs b/Emby.Server.Core/Configuration/ServerConfigurationManager.cs deleted file mode 100644 index eb3d8b9f9c..0000000000 --- a/Emby.Server.Core/Configuration/ServerConfigurationManager.cs +++ /dev/null @@ -1,245 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Emby.Common.Implementations.Configuration; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Events; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Controller.Entities.TV; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Events; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Serialization; - -namespace Emby.Server.Core.Configuration -{ - /// <summary> - /// Class ServerConfigurationManager - /// </summary> - public class ServerConfigurationManager : BaseConfigurationManager, IServerConfigurationManager - { - - /// <summary> - /// Initializes a new instance of the <see cref="ServerConfigurationManager" /> class. - /// </summary> - /// <param name="applicationPaths">The application paths.</param> - /// <param name="logManager">The log manager.</param> - /// <param name="xmlSerializer">The XML serializer.</param> - /// <param name="fileSystem">The file system.</param> - public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem) - : base(applicationPaths, logManager, xmlSerializer, fileSystem) - { - UpdateMetadataPath(); - } - - public event EventHandler<GenericEventArgs<ServerConfiguration>> ConfigurationUpdating; - - /// <summary> - /// Gets the type of the configuration. - /// </summary> - /// <value>The type of the configuration.</value> - protected override Type ConfigurationType - { - get { return typeof(ServerConfiguration); } - } - - /// <summary> - /// Gets the application paths. - /// </summary> - /// <value>The application paths.</value> - public IServerApplicationPaths ApplicationPaths - { - get { return (IServerApplicationPaths)CommonApplicationPaths; } - } - - /// <summary> - /// Gets the configuration. - /// </summary> - /// <value>The configuration.</value> - public ServerConfiguration Configuration - { - get { return (ServerConfiguration)CommonConfiguration; } - } - - /// <summary> - /// Called when [configuration updated]. - /// </summary> - protected override void OnConfigurationUpdated() - { - UpdateMetadataPath(); - - base.OnConfigurationUpdated(); - } - - public override void AddParts(IEnumerable<IConfigurationFactory> factories) - { - base.AddParts(factories); - - UpdateTranscodingTempPath(); - } - - /// <summary> - /// Updates the metadata path. - /// </summary> - private void UpdateMetadataPath() - { - string metadataPath; - - if (string.IsNullOrWhiteSpace(Configuration.MetadataPath)) - { - metadataPath = GetInternalMetadataPath(); - } - else - { - metadataPath = Path.Combine(Configuration.MetadataPath, "metadata"); - } - - ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath = metadataPath; - - ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath; - } - - private string GetInternalMetadataPath() - { - return Path.Combine(ApplicationPaths.ProgramDataPath, "metadata"); - } - - /// <summary> - /// Updates the transcoding temporary path. - /// </summary> - private void UpdateTranscodingTempPath() - { - var encodingConfig = this.GetConfiguration<EncodingOptions>("encoding"); - - ((ServerApplicationPaths)ApplicationPaths).TranscodingTempPath = string.IsNullOrEmpty(encodingConfig.TranscodingTempPath) ? - null : - Path.Combine(encodingConfig.TranscodingTempPath, "transcoding-temp"); - } - - protected override void OnNamedConfigurationUpdated(string key, object configuration) - { - base.OnNamedConfigurationUpdated(key, configuration); - - if (string.Equals(key, "encoding", StringComparison.OrdinalIgnoreCase)) - { - UpdateTranscodingTempPath(); - } - } - - /// <summary> - /// Replaces the configuration. - /// </summary> - /// <param name="newConfiguration">The new configuration.</param> - /// <exception cref="System.IO.DirectoryNotFoundException"></exception> - public override void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration) - { - var newConfig = (ServerConfiguration)newConfiguration; - - ValidateMetadataPath(newConfig); - ValidateSslCertificate(newConfig); - - EventHelper.FireEventIfNotNull(ConfigurationUpdating, this, new GenericEventArgs<ServerConfiguration> { Argument = newConfig }, Logger); - - base.ReplaceConfiguration(newConfiguration); - } - - - /// <summary> - /// Validates the SSL certificate. - /// </summary> - /// <param name="newConfig">The new configuration.</param> - /// <exception cref="System.IO.DirectoryNotFoundException"></exception> - private void ValidateSslCertificate(BaseApplicationConfiguration newConfig) - { - var serverConfig = (ServerConfiguration)newConfig; - - var newPath = serverConfig.CertificatePath; - - if (!string.IsNullOrWhiteSpace(newPath) - && !string.Equals(Configuration.CertificatePath ?? string.Empty, newPath)) - { - // Validate - if (!FileSystem.FileExists(newPath)) - { - throw new FileNotFoundException(string.Format("Certificate file '{0}' does not exist.", newPath)); - } - } - } - - /// <summary> - /// Validates the metadata path. - /// </summary> - /// <param name="newConfig">The new configuration.</param> - /// <exception cref="System.IO.DirectoryNotFoundException"></exception> - private void ValidateMetadataPath(ServerConfiguration newConfig) - { - var newPath = newConfig.MetadataPath; - - if (!string.IsNullOrWhiteSpace(newPath) - && !string.Equals(Configuration.MetadataPath ?? string.Empty, newPath)) - { - // Validate - if (!FileSystem.DirectoryExists(newPath)) - { - throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath)); - } - - EnsureWriteAccess(newPath); - } - } - - public void DisableMetadataService(string service) - { - DisableMetadataService(typeof(Movie), Configuration, service); - DisableMetadataService(typeof(Episode), Configuration, service); - DisableMetadataService(typeof(Series), Configuration, service); - DisableMetadataService(typeof(Season), Configuration, service); - DisableMetadataService(typeof(MusicArtist), Configuration, service); - DisableMetadataService(typeof(MusicAlbum), Configuration, service); - DisableMetadataService(typeof(MusicVideo), Configuration, service); - DisableMetadataService(typeof(Video), Configuration, service); - } - - private void DisableMetadataService(Type type, ServerConfiguration config, string service) - { - var options = GetMetadataOptions(type, config); - - if (!options.DisabledMetadataSavers.Contains(service, StringComparer.OrdinalIgnoreCase)) - { - var list = options.DisabledMetadataSavers.ToList(); - - list.Add(service); - - options.DisabledMetadataSavers = list.ToArray(); - } - } - - private MetadataOptions GetMetadataOptions(Type type, ServerConfiguration config) - { - var options = config.MetadataOptions - .FirstOrDefault(i => string.Equals(i.ItemType, type.Name, StringComparison.OrdinalIgnoreCase)); - - if (options == null) - { - var list = config.MetadataOptions.ToList(); - - options = new MetadataOptions - { - ItemType = type.Name - }; - - list.Add(options); - - config.MetadataOptions = list.ToArray(); - } - - return options; - } - } -} diff --git a/Emby.Server.Core/Logging/ConsoleLogger.cs b/Emby.Server.Core/Logging/ConsoleLogger.cs new file mode 100644 index 0000000000..01eca7b7e4 --- /dev/null +++ b/Emby.Server.Core/Logging/ConsoleLogger.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MediaBrowser.Model.Logging; + +namespace Emby.Server.Core.Logging +{ + public class ConsoleLogger : IConsoleLogger + { + public void WriteLine(string message) + { + Console.WriteLine(message); + } + } +} diff --git a/Emby.Server.Core/ServerApplicationPaths.cs b/Emby.Server.Core/ServerApplicationPaths.cs deleted file mode 100644 index dc80b773c5..0000000000 --- a/Emby.Server.Core/ServerApplicationPaths.cs +++ /dev/null @@ -1,233 +0,0 @@ -using System.IO; -using Emby.Common.Implementations; -using MediaBrowser.Controller; - -namespace Emby.Server.Core -{ - /// <summary> - /// Extends BaseApplicationPaths to add paths that are only applicable on the server - /// </summary> - public class ServerApplicationPaths : BaseApplicationPaths, IServerApplicationPaths - { - /// <summary> - /// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class. - /// </summary> - public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath) - : base(programDataPath, appFolderPath) - { - ApplicationResourcesPath = applicationResourcesPath; - } - - public string ApplicationResourcesPath { get; private set; } - - /// <summary> - /// Gets the path to the base root media directory - /// </summary> - /// <value>The root folder path.</value> - public string RootFolderPath - { - get - { - return Path.Combine(ProgramDataPath, "root"); - } - } - - /// <summary> - /// Gets the path to the default user view directory. Used if no specific user view is defined. - /// </summary> - /// <value>The default user views path.</value> - public string DefaultUserViewsPath - { - get - { - return Path.Combine(RootFolderPath, "default"); - } - } - - /// <summary> - /// Gets the path to localization data. - /// </summary> - /// <value>The localization path.</value> - public string LocalizationPath - { - get - { - return Path.Combine(ProgramDataPath, "localization"); - } - } - - /// <summary> - /// The _ibn path - /// </summary> - private string _ibnPath; - /// <summary> - /// Gets the path to the Images By Name directory - /// </summary> - /// <value>The images by name path.</value> - public string ItemsByNamePath - { - get - { - return _ibnPath ?? (_ibnPath = Path.Combine(ProgramDataPath, "ImagesByName")); - } - set - { - _ibnPath = value; - } - } - - /// <summary> - /// Gets the path to the People directory - /// </summary> - /// <value>The people path.</value> - public string PeoplePath - { - get - { - return Path.Combine(ItemsByNamePath, "People"); - } - } - - public string ArtistsPath - { - get - { - return Path.Combine(ItemsByNamePath, "artists"); - } - } - - /// <summary> - /// Gets the path to the Genre directory - /// </summary> - /// <value>The genre path.</value> - public string GenrePath - { - get - { - return Path.Combine(ItemsByNamePath, "Genre"); - } - } - - /// <summary> - /// Gets the path to the Genre directory - /// </summary> - /// <value>The genre path.</value> - public string MusicGenrePath - { - get - { - return Path.Combine(ItemsByNamePath, "MusicGenre"); - } - } - - /// <summary> - /// Gets the path to the Studio directory - /// </summary> - /// <value>The studio path.</value> - public string StudioPath - { - get - { - return Path.Combine(ItemsByNamePath, "Studio"); - } - } - - /// <summary> - /// Gets the path to the Year directory - /// </summary> - /// <value>The year path.</value> - public string YearPath - { - get - { - return Path.Combine(ItemsByNamePath, "Year"); - } - } - - /// <summary> - /// Gets the path to the General IBN directory - /// </summary> - /// <value>The general path.</value> - public string GeneralPath - { - get - { - return Path.Combine(ItemsByNamePath, "general"); - } - } - - /// <summary> - /// Gets the path to the Ratings IBN directory - /// </summary> - /// <value>The ratings path.</value> - public string RatingsPath - { - get - { - return Path.Combine(ItemsByNamePath, "ratings"); - } - } - - /// <summary> - /// Gets the media info images path. - /// </summary> - /// <value>The media info images path.</value> - public string MediaInfoImagesPath - { - get - { - return Path.Combine(ItemsByNamePath, "mediainfo"); - } - } - - /// <summary> - /// Gets the path to the user configuration directory - /// </summary> - /// <value>The user configuration directory path.</value> - public string UserConfigurationDirectoryPath - { - get - { - return Path.Combine(ConfigurationDirectoryPath, "users"); - } - } - - private string _transcodingTempPath; - public string TranscodingTempPath - { - get - { - return _transcodingTempPath ?? (_transcodingTempPath = Path.Combine(ProgramDataPath, "transcoding-temp")); - } - set - { - _transcodingTempPath = value; - } - } - - /// <summary> - /// Gets the game genre path. - /// </summary> - /// <value>The game genre path.</value> - public string GameGenrePath - { - get - { - return Path.Combine(ItemsByNamePath, "GameGenre"); - } - } - - private string _internalMetadataPath; - public string InternalMetadataPath - { - get - { - return _internalMetadataPath ?? (_internalMetadataPath = Path.Combine(DataPath, "metadata")); - } - set - { - _internalMetadataPath = value; - } - } - } -} diff --git a/Emby.Server.Core/UnhandledExceptionWriter.cs b/Emby.Server.Core/UnhandledExceptionWriter.cs deleted file mode 100644 index 5147be9e7c..0000000000 --- a/Emby.Server.Core/UnhandledExceptionWriter.cs +++ /dev/null @@ -1,38 +0,0 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Logging; -using System; -using System.IO; - -namespace Emby.Server.Core -{ - public class UnhandledExceptionWriter - { - private readonly IApplicationPaths _appPaths; - private readonly ILogger _logger; - private readonly ILogManager _logManager; - - public UnhandledExceptionWriter(IApplicationPaths appPaths, ILogger logger, ILogManager logManager) - { - _appPaths = appPaths; - _logger = logger; - _logManager = logManager; - } - - public void Log(Exception ex) - { - _logger.ErrorException("UnhandledException", ex); - _logManager.Flush(); - - var path = Path.Combine(_appPaths.LogDirectoryPath, "unhandled_" + Guid.NewGuid() + ".txt"); - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - var builder = LogHelper.GetLogMessage(ex); - - // Write to console just in case file logging fails - Console.WriteLine("UnhandledException"); - Console.WriteLine(builder.ToString()); - - File.WriteAllText(path, builder.ToString()); - } - } -} |
