diff options
Diffstat (limited to 'Emby.Server.Core')
| -rw-r--r-- | Emby.Server.Core/ApplicationHost.cs | 124 | ||||
| -rw-r--r-- | Emby.Server.Core/Data/DataExtensions.cs | 4 | ||||
| -rw-r--r-- | Emby.Server.Core/Data/SqliteItemRepository.cs | 19 | ||||
| -rw-r--r-- | Emby.Server.Core/INativeApp.cs | 78 | ||||
| -rw-r--r-- | Emby.Server.Core/Notifications/SqliteNotificationsRepository.cs | 2 | ||||
| -rw-r--r-- | Emby.Server.Core/ServerApplicationPaths.cs | 4 |
6 files changed, 70 insertions, 161 deletions
diff --git a/Emby.Server.Core/ApplicationHost.cs b/Emby.Server.Core/ApplicationHost.cs index 5c8aea7edf..d3d292ca58 100644 --- a/Emby.Server.Core/ApplicationHost.cs +++ b/Emby.Server.Core/ApplicationHost.cs @@ -142,7 +142,7 @@ namespace Emby.Server.Core /// <summary> /// Class CompositionRoot /// </summary> - public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost, IDependencyContainer + public abstract class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost, IDependencyContainer { /// <summary> /// Gets the server configuration manager. @@ -257,11 +257,9 @@ namespace Emby.Server.Core protected IAuthService AuthService { get; private set; } - private readonly StartupOptions _startupOptions; + protected readonly StartupOptions StartupOptions; private readonly string _releaseAssetFilename; - internal INativeApp NativeApp { get; set; } - internal IPowerManagement PowerManagement { get; private set; } internal IImageEncoder ImageEncoder { get; private set; } @@ -275,7 +273,6 @@ namespace Emby.Server.Core ILogManager logManager, StartupOptions options, IFileSystem fileSystem, - INativeApp nativeApp, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, @@ -293,11 +290,10 @@ namespace Emby.Server.Core memoryStreamFactory, networkManager) { - _startupOptions = options; + StartupOptions = options; _certificateGenerator = certificateGenerator; _releaseAssetFilename = releaseAssetFilename; _defaultUserNameFactory = defaultUsernameFactory; - NativeApp = nativeApp; PowerManagement = powerManagement; ImageEncoder = imageEncoder; @@ -314,19 +310,11 @@ namespace Emby.Server.Core { get { - return _version ?? (_version = GetAssembly(NativeApp.GetType()).GetName().Version); + return _version ?? (_version = GetAssembly(GetType()).GetName().Version); } } - public override bool IsRunningAsService - { - get { return NativeApp.IsRunningAsService; } - } - - public bool SupportsRunningAsService - { - get { return NativeApp.SupportsRunningAsService; } - } + public abstract bool SupportsRunningAsService { get; } /// <summary> /// Gets the name. @@ -345,19 +333,7 @@ namespace Emby.Server.Core return type.GetTypeInfo().Assembly; } - /// <summary> - /// Gets a value indicating whether this instance can self restart. - /// </summary> - /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value> - public override bool CanSelfRestart - { - get { return NativeApp.CanSelfRestart; } - } - - public bool SupportsAutoRunAtStartup - { - get { return NativeApp.SupportsAutoRunAtStartup; } - } + public abstract bool SupportsAutoRunAtStartup { get; } private void SetBaseExceptionMessage() { @@ -580,11 +556,11 @@ namespace Emby.Server.Core UserRepository = await GetUserRepository().ConfigureAwait(false); - var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths, NativeApp.GetDbConnector(), MemoryStreamFactory); + var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths, GetDbConnector(), MemoryStreamFactory); DisplayPreferencesRepository = displayPreferencesRepo; RegisterSingleInstance(DisplayPreferencesRepository); - var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, NativeApp.GetDbConnector(), MemoryStreamFactory); + var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory); ItemRepository = itemRepo; RegisterSingleInstance(ItemRepository); @@ -707,7 +683,7 @@ namespace Emby.Server.Core EncodingManager = new EncodingManager(FileSystemManager, Logger, MediaEncoder, ChapterManager, LibraryManager); RegisterSingleInstance(EncodingManager); - var sharingRepo = new SharingRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); + var sharingRepo = new SharingRepository(LogManager, ApplicationPaths, GetDbConnector()); await sharingRepo.Initialize().ConfigureAwait(false); RegisterSingleInstance<ISharingManager>(new SharingManager(sharingRepo, ServerConfigurationManager, LibraryManager, this)); @@ -727,7 +703,7 @@ namespace Emby.Server.Core await displayPreferencesRepo.Initialize().ConfigureAwait(false); - var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); + var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, GetDbConnector()); ((UserDataManager)UserDataManager).Repository = userDataRepo; await itemRepo.Initialize(userDataRepo).ConfigureAwait(false); @@ -749,6 +725,11 @@ namespace Emby.Server.Core try { + if (!FileSystemManager.FileExists(certificateLocation)) + { + return null; + } + X509Certificate2 localCert = new X509Certificate2(certificateLocation); //localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA; if (!localCert.HasPrivateKey) @@ -770,14 +751,16 @@ namespace Emby.Server.Core { var maxConcurrentImageProcesses = Math.Max(Environment.ProcessorCount, 4); - if (_startupOptions.ContainsOption("-imagethreads")) + if (StartupOptions.ContainsOption("-imagethreads")) { - int.TryParse(_startupOptions.GetOption("-imagethreads"), NumberStyles.Any, CultureInfo.InvariantCulture, out maxConcurrentImageProcesses); + int.TryParse(StartupOptions.GetOption("-imagethreads"), NumberStyles.Any, CultureInfo.InvariantCulture, out maxConcurrentImageProcesses); } return new ImageProcessor(LogManager.GetLogger("ImageProcessor"), ServerConfigurationManager.ApplicationPaths, FileSystemManager, JsonSerializer, ImageEncoder, maxConcurrentImageProcesses, () => LibraryManager, TimerFactory); } + protected abstract FFMpegInstallInfo GetFfmpegInstallInfo(); + /// <summary> /// Registers the media encoder. /// </summary> @@ -787,8 +770,8 @@ namespace Emby.Server.Core string encoderPath = null; string probePath = null; - var info = await new FFMpegLoader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.GetFfmpegInstallInfo()) - .GetFFMpegInfo(_startupOptions, progress).ConfigureAwait(false); + var info = await new FFMpegLoader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, GetFfmpegInstallInfo()) + .GetFFMpegInfo(StartupOptions, progress).ConfigureAwait(false); encoderPath = info.EncoderPath; probePath = info.ProbePath; @@ -825,7 +808,7 @@ namespace Emby.Server.Core /// <returns>Task{IUserRepository}.</returns> private async Task<IUserRepository> GetUserRepository() { - var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer, NativeApp.GetDbConnector(), MemoryStreamFactory); + var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer, GetDbConnector(), MemoryStreamFactory); await repo.Initialize().ConfigureAwait(false); @@ -838,7 +821,7 @@ namespace Emby.Server.Core /// <returns>Task{IUserRepository}.</returns> private async Task<IFileOrganizationRepository> GetFileOrganizationRepository() { - var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); + var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, GetDbConnector()); await repo.Initialize().ConfigureAwait(false); @@ -847,7 +830,7 @@ namespace Emby.Server.Core private async Task<IAuthenticationRepository> GetAuthenticationRepository() { - var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); + var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, GetDbConnector()); await repo.Initialize().ConfigureAwait(false); @@ -856,7 +839,7 @@ namespace Emby.Server.Core private async Task<IActivityRepository> GetActivityLogRepository() { - var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); + var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths, GetDbConnector()); await repo.Initialize().ConfigureAwait(false); @@ -865,7 +848,7 @@ namespace Emby.Server.Core private async Task<ISyncRepository> GetSyncRepository() { - var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); + var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths, GetDbConnector()); await repo.Initialize().ConfigureAwait(false); @@ -877,7 +860,7 @@ namespace Emby.Server.Core /// </summary> private async Task ConfigureNotificationsRepository() { - var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); + var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths, GetDbConnector()); await repo.Initialize().ConfigureAwait(false); @@ -1123,24 +1106,12 @@ namespace Emby.Server.Core Logger.ErrorException("Error sending server restart notification", ex); } - Logger.Info("Calling NativeApp.Restart"); + Logger.Info("Calling RestartInternal"); - NativeApp.Restart(_startupOptions); + RestartInternal(); } - /// <summary> - /// Gets or sets a value indicating whether this instance can self update. - /// </summary> - /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value> - public override bool CanSelfUpdate - { - get - { -#pragma warning disable 162 - return NativeApp.CanSelfUpdate; -#pragma warning restore 162 - } - } + protected abstract void RestartInternal(); /// <summary> /// Gets the composable part assemblies. @@ -1196,14 +1167,16 @@ namespace Emby.Server.Core // Xbmc list.Add(GetAssembly(typeof(ArtistNfoProvider))); - list.AddRange(NativeApp.GetAssembliesWithParts()); + list.AddRange(GetAssembliesWithPartsInternal()); // Include composable parts in the running assembly - list.Add(GetAssembly(GetType())); + list.Add(GetAssembly(typeof(ApplicationHost))); return list; } + protected abstract List<Assembly> GetAssembliesWithPartsInternal(); + /// <summary> /// Gets the plugin assemblies. /// </summary> @@ -1280,7 +1253,7 @@ namespace Emby.Server.Core EncoderLocationType = MediaEncoder.EncoderLocationType, SystemArchitecture = EnvironmentInfo.SystemArchitecture, SystemUpdateLevel = ConfigurationManager.CommonConfiguration.SystemUpdateLevel, - PackageName = _startupOptions.GetOption("-package") + PackageName = StartupOptions.GetOption("-package") }; } @@ -1456,9 +1429,11 @@ namespace Emby.Server.Core Logger.ErrorException("Error sending server shutdown notification", ex); } - NativeApp.Shutdown(); + ShutdownInternal(); } + protected abstract void ShutdownInternal(); + /// <summary> /// Registers the server with administrator access. /// </summary> @@ -1468,12 +1443,7 @@ namespace Emby.Server.Core try { - NativeApp.AuthorizeServer( - UdpServerEntryPoint.PortNumber, - ServerConfigurationManager.Configuration.HttpServerPortNumber, - ServerConfigurationManager.Configuration.HttpsPortNumber, - ConfigurationManager.CommonApplicationPaths.ApplicationPath, - ConfigurationManager.CommonApplicationPaths.TempDirectory); + AuthorizeServer(); } catch (Exception ex) { @@ -1481,6 +1451,9 @@ namespace Emby.Server.Core } } + protected abstract void AuthorizeServer(); + protected abstract IDbConnector GetDbConnector(); + public event EventHandler HasUpdateAvailableChanged; private bool _hasUpdateAvailable; @@ -1551,10 +1524,12 @@ namespace Emby.Server.Core { if (SupportsAutoRunAtStartup) { - NativeApp.ConfigureAutoRun(autorun); + ConfigureAutoRunInternal(autorun); } } + protected abstract void ConfigureAutoRunInternal(bool autorun); + /// <summary> /// This returns localhost in the case of no external dns, and the hostname if the /// dns is prefixed with a valid Uri prefix. @@ -1578,16 +1553,15 @@ namespace Emby.Server.Core } } - public void LaunchUrl(string url) - { - NativeApp.LaunchUrl(url); - } + public abstract void LaunchUrl(string url); public void EnableLoopback(string appName) { - NativeApp.EnableLoopback(appName); + EnableLoopbackInternal(appName); } + protected abstract void EnableLoopbackInternal(string appName); + private void RegisterModules() { var moduleTypes = GetExportTypes<IDependencyModule>(); diff --git a/Emby.Server.Core/Data/DataExtensions.cs b/Emby.Server.Core/Data/DataExtensions.cs index b633d92178..631c1c5005 100644 --- a/Emby.Server.Core/Data/DataExtensions.cs +++ b/Emby.Server.Core/Data/DataExtensions.cs @@ -40,7 +40,7 @@ namespace Emby.Server.Core.Data public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name) { var param = cmd.CreateParameter(); - + param.ParameterName = name; paramCollection.Add(param); @@ -173,7 +173,7 @@ namespace Emby.Server.Core.Data var builder = new StringBuilder(); builder.AppendLine("alter table " + table); - builder.AppendLine("add column " + columnName + " " + type); + builder.AppendLine("add column " + columnName + " " + type + " NULL"); connection.RunQueries(new[] { builder.ToString() }, logger); } diff --git a/Emby.Server.Core/Data/SqliteItemRepository.cs b/Emby.Server.Core/Data/SqliteItemRepository.cs index 2ca86c8318..6ed409aa13 100644 --- a/Emby.Server.Core/Data/SqliteItemRepository.cs +++ b/Emby.Server.Core/Data/SqliteItemRepository.cs @@ -157,7 +157,7 @@ namespace Emby.Server.Core.Data string[] queries = { - "create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID, Path TEXT)", + "create table if not exists TypedBaseItems (guid GUID primary key NOT NULL, type TEXT NOT NULL, data BLOB NULL, ParentId GUID NULL, Path TEXT NULL)", "create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))", "create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)", @@ -286,6 +286,7 @@ namespace Emby.Server.Core.Data _connection.AddColumn(Logger, "TypedBaseItems", "ExtraType", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "Artists", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "AlbumArtists", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "ExternalId", "Text"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -440,7 +441,8 @@ namespace Emby.Server.Core.Data "TotalBitrate", "ExtraType", "Artists", - "AlbumArtists" + "AlbumArtists", + "ExternalId" }; private readonly string[] _mediaStreamSaveColumns = @@ -575,7 +577,8 @@ namespace Emby.Server.Core.Data "TotalBitrate", "ExtraType", "Artists", - "AlbumArtists" + "AlbumArtists", + "ExternalId" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -1084,6 +1087,10 @@ namespace Emby.Server.Core.Data } } + _saveItemCommand.GetParameter(index++).Value = item.ExternalId; + + //Logger.Debug(_saveItemCommand.CommandText); + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1967,6 +1974,12 @@ namespace Emby.Server.Core.Data } index++; + if (!reader.IsDBNull(index)) + { + item.ExternalId = reader.GetString(index); + } + index++; + if (string.IsNullOrWhiteSpace(item.Tagline)) { var movie = item as Movie; diff --git a/Emby.Server.Core/INativeApp.cs b/Emby.Server.Core/INativeApp.cs deleted file mode 100644 index a4e4b32217..0000000000 --- a/Emby.Server.Core/INativeApp.cs +++ /dev/null @@ -1,78 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Model.Logging; -using System.Collections.Generic; -using System.Reflection; -using Emby.Server.Core; -using Emby.Server.Core.Data; -using Emby.Server.Core.FFMpeg; - -namespace Emby.Server.Core -{ - public interface INativeApp - { - /// <summary> - /// Gets the assemblies with parts. - /// </summary> - /// <returns>List<Assembly>.</returns> - List<Assembly> GetAssembliesWithParts(); - - /// <summary> - /// Authorizes the server. - /// </summary> - void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string applicationPath, string tempDirectory); - - /// <summary> - /// Gets a value indicating whether [supports running as service]. - /// </summary> - /// <value><c>true</c> if [supports running as service]; otherwise, <c>false</c>.</value> - bool SupportsRunningAsService { get; } - - /// <summary> - /// Gets a value indicating whether this instance is running as service. - /// </summary> - /// <value><c>true</c> if this instance is running as service; otherwise, <c>false</c>.</value> - bool IsRunningAsService { get; } - - /// <summary> - /// Gets a value indicating whether this instance can self restart. - /// </summary> - /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value> - bool CanSelfRestart { get; } - - /// <summary> - /// Gets a value indicating whether [supports autorun at startup]. - /// </summary> - /// <value><c>true</c> if [supports autorun at startup]; otherwise, <c>false</c>.</value> - bool SupportsAutoRunAtStartup { get; } - - /// <summary> - /// Gets a value indicating whether this instance can self update. - /// </summary> - /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value> - bool CanSelfUpdate { get; } - - /// <summary> - /// Shutdowns this instance. - /// </summary> - void Shutdown(); - - /// <summary> - /// Restarts this instance. - /// </summary> - void Restart(StartupOptions startupOptions); - - /// <summary> - /// Configures the automatic run. - /// </summary> - /// <param name="autorun">if set to <c>true</c> [autorun].</param> - void ConfigureAutoRun(bool autorun); - - FFMpegInstallInfo GetFfmpegInstallInfo(); - - void LaunchUrl(string url); - - IDbConnector GetDbConnector(); - - void EnableLoopback(string appName); - } -} diff --git a/Emby.Server.Core/Notifications/SqliteNotificationsRepository.cs b/Emby.Server.Core/Notifications/SqliteNotificationsRepository.cs index 8a7fc92701..dee0d4cfdd 100644 --- a/Emby.Server.Core/Notifications/SqliteNotificationsRepository.cs +++ b/Emby.Server.Core/Notifications/SqliteNotificationsRepository.cs @@ -30,7 +30,7 @@ namespace Emby.Server.Core.Notifications { string[] queries = { - "create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT, Url TEXT, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT, PRIMARY KEY (Id, UserId))", + "create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT NULL, Url TEXT NULL, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT NULL, PRIMARY KEY (Id, UserId))", "create index if not exists idx_Notifications1 on Notifications(Id)", "create index if not exists idx_Notifications2 on Notifications(UserId)" }; diff --git a/Emby.Server.Core/ServerApplicationPaths.cs b/Emby.Server.Core/ServerApplicationPaths.cs index d59dd89d9c..dc80b773c5 100644 --- a/Emby.Server.Core/ServerApplicationPaths.cs +++ b/Emby.Server.Core/ServerApplicationPaths.cs @@ -12,8 +12,8 @@ namespace Emby.Server.Core /// <summary> /// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class. /// </summary> - public ServerApplicationPaths(string programDataPath, string applicationPath, string applicationResourcesPath) - : base(programDataPath, applicationPath) + public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath) + : base(programDataPath, appFolderPath) { ApplicationResourcesPath = applicationResourcesPath; } |
