From a6d535a3f1cb64cb2a72dd9c39a880a9fe21a080 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Nov 2016 15:46:18 -0500 Subject: [PATCH 1/5] update mac project --- .../Emby.Server.Mac.csproj | 1 - MediaBrowser.Server.Mac/MacAppHost.cs | 14 ++++++----- MediaBrowser.Server.Mac/Native/DbConnector.cs | 24 ------------------- 3 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 MediaBrowser.Server.Mac/Native/DbConnector.cs diff --git a/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj b/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj index 9df2df2ff4..494b89149b 100644 --- a/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj +++ b/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj @@ -147,7 +147,6 @@ - diff --git a/MediaBrowser.Server.Mac/MacAppHost.cs b/MediaBrowser.Server.Mac/MacAppHost.cs index 342829c107..78bca03c86 100644 --- a/MediaBrowser.Server.Mac/MacAppHost.cs +++ b/MediaBrowser.Server.Mac/MacAppHost.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Reflection; using Emby.Server.Core; -using Emby.Server.Core.Data; using Emby.Server.Implementations; using Emby.Server.Implementations.FFMpeg; using MediaBrowser.Model.IO; @@ -35,6 +34,14 @@ namespace MediaBrowser.Server.Mac } } + protected override bool SupportsDualModeSockets + { + get + { + return true; + } + } + protected override FFMpegInstallInfo GetFfmpegInstallInfo() { var info = new FFMpegInstallInfo(); @@ -95,11 +102,6 @@ namespace MediaBrowser.Server.Mac throw new NotImplementedException(); } - protected override IDbConnector GetDbConnector() - { - return new DbConnector(Logger); - } - protected override void ConfigureAutoRunInternal(bool autorun) { throw new NotImplementedException(); diff --git a/MediaBrowser.Server.Mac/Native/DbConnector.cs b/MediaBrowser.Server.Mac/Native/DbConnector.cs deleted file mode 100644 index 1ef9d2388e..0000000000 --- a/MediaBrowser.Server.Mac/Native/DbConnector.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Data; -using System.Data.SQLite; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; -using Emby.Server.Core.Data; - -namespace MediaBrowser.Server.Mac -{ - public class DbConnector : IDbConnector - { - private readonly ILogger _logger; - - public DbConnector(ILogger logger) - { - _logger = logger; - } - - public Task Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null) - { - return SqliteExtensions.ConnectToDb(dbPath, isReadOnly, enablePooling, cacheSize, _logger); - } - } -} \ No newline at end of file From 6da99d9d04042a461ec04e57b6e40708a37bb44f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 15:55:48 -0500 Subject: [PATCH 2/5] update .net core startup --- src/Emby.Server/project.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Emby.Server/project.json b/src/Emby.Server/project.json index 170523db1b..0e1cf8bee5 100644 --- a/src/Emby.Server/project.json +++ b/src/Emby.Server/project.json @@ -9,18 +9,17 @@ "Emby.Server.Core": "1.0.0-*", "Microsoft.NETCore.App": { "type": "platform", - "version": "1.0.1" + "version": "1.1.0" }, "Mono.Nat": "1.0.0-*", "Microsoft.Win32.Registry": "4.0.0", "System.Runtime.Extensions": "4.1.0", "System.Diagnostics.Process": "4.1.0", - "Microsoft.Data.SQLite": "1.1.0-preview1-final", - "SQLitePCLRaw.provider.sqlite3.netstandard11": "1.1.0" + "SQLitePCLRaw.provider.sqlite3.netstandard11": "1.1.0" }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "imports": "dnxcore50", "dependencies": { "BDInfo": { From 94e622e3a0cfcd14ad47ede3342dfab7a862c4d9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 16:02:32 -0500 Subject: [PATCH 3/5] add sqlite logging --- .../Data/BaseSqliteRepository.cs | 9 ++++ src/Emby.Server/CoreAppHost.cs | 7 +-- src/Emby.Server/Data/DbConnector.cs | 52 ------------------- src/Emby.Server/Program.cs | 3 +- 4 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 src/Emby.Server/Data/DbConnector.cs diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index 6c1a968137..7836c8b41b 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -33,8 +33,17 @@ namespace Emby.Server.Implementations.Data //CheckOk(rc); } + private static bool _versionLogged; + protected virtual SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false) { + if (!_versionLogged) + { + _versionLogged = true; + Logger.Info("Sqlite version: " + SQLite3.Version); + Logger.Info("Sqlite compiler options: " + string.Join(",", SQLite3.CompilerOptions.ToArray())); + } + ConnectionFlags connectionFlags; //isReadOnly = false; diff --git a/src/Emby.Server/CoreAppHost.cs b/src/Emby.Server/CoreAppHost.cs index 21f6ae4456..5291f20ef3 100644 --- a/src/Emby.Server/CoreAppHost.cs +++ b/src/Emby.Server/CoreAppHost.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; using Emby.Server.Core; -using Emby.Server.Core.Data; using Emby.Server.Core.FFMpeg; using Emby.Server.Data; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.System; +using Emby.Server.Implementations; namespace Emby.Server { @@ -55,11 +55,6 @@ namespace Emby.Server { } - protected override IDbConnector GetDbConnector() - { - return new DbConnector(Logger); - } - protected override void ConfigureAutoRunInternal(bool autorun) { } diff --git a/src/Emby.Server/Data/DbConnector.cs b/src/Emby.Server/Data/DbConnector.cs deleted file mode 100644 index bd70cff6cf..0000000000 --- a/src/Emby.Server/Data/DbConnector.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Data; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; -using Emby.Server.Core.Data; -using Microsoft.Data.Sqlite; - -namespace Emby.Server.Data -{ - public class DbConnector : IDbConnector - { - private readonly ILogger _logger; - - public DbConnector(ILogger logger) - { - _logger = logger; - } - - public async Task Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null) - { - if (string.IsNullOrEmpty(dbPath)) - { - throw new ArgumentNullException("dbPath"); - } - - //SQLiteConnection.SetMemoryStatus(false); - - var connectionstr = new SqliteConnectionStringBuilder - { - //PageSize = 4096, - //CacheSize = cacheSize ?? 2000, - //SyncMode = SynchronizationModes.Normal, - DataSource = dbPath, - //JournalMode = SQLiteJournalModeEnum.Wal, - - // This is causing crashing under linux - //Pooling = enablePooling && Environment.OSVersion.Platform == PlatformID.Win32NT, - //ReadOnly = isReadOnly, - Cache = enablePooling ? SqliteCacheMode.Default : SqliteCacheMode.Private, - Mode = isReadOnly ? SqliteOpenMode.ReadOnly : SqliteOpenMode.ReadWriteCreate - }; - - var connectionString = connectionstr.ConnectionString; - - var connection = new SqliteConnection(connectionString); - - await connection.OpenAsync().ConfigureAwait(false); - - return connection; - } - } -} \ No newline at end of file diff --git a/src/Emby.Server/Program.cs b/src/Emby.Server/Program.cs index 80e56c8ab7..e5d8351fe5 100644 --- a/src/Emby.Server/Program.cs +++ b/src/Emby.Server/Program.cs @@ -15,10 +15,11 @@ using Emby.Common.Implementations.Logging; using Emby.Common.Implementations.Networking; using Emby.Drawing; using Emby.Server.Core; -using Emby.Server.Core.Browser; +using Emby.Server.Implementations.Browser; using Emby.Server.Implementations.IO; using MediaBrowser.Common.Net; using Emby.Server.IO; +using Emby.Server.Implementations; namespace Emby.Server { From e297e90bceeb3310e32142af406403d54875720d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 18:48:52 -0500 Subject: [PATCH 4/5] update .net core startup --- Emby.Server.Core/ApplicationHost.cs | 36 +++++++++++++++- .../Data/BaseSqliteRepository.cs | 20 ++++++--- .../Data/SqliteItemRepository.cs | 8 ++++ .../HdHomerun/HdHomerunLiveStream.cs | 5 ++- MediaBrowser.Server.Mono/MonoAppHost.cs | 5 --- .../WindowsAppHost.cs | 32 -------------- src/Emby.Server/CoreAppHost.cs | 43 ++++++++++++++++--- src/Emby.Server/Program.cs | 38 ++++++++++++---- src/Emby.Server/project.json | 2 +- 9 files changed, 127 insertions(+), 62 deletions(-) diff --git a/Emby.Server.Core/ApplicationHost.cs b/Emby.Server.Core/ApplicationHost.cs index ba0d830d32..55a8510337 100644 --- a/Emby.Server.Core/ApplicationHost.cs +++ b/Emby.Server.Core/ApplicationHost.cs @@ -132,6 +132,8 @@ using SocketHttpListener.Primitives; using StringExtensions = MediaBrowser.Controller.Extensions.StringExtensions; using Emby.Drawing; using Emby.Server.Implementations.Migrations; +using MediaBrowser.Model.Diagnostics; +using Emby.Common.Implementations.Diagnostics; namespace Emby.Server.Core { @@ -1543,7 +1545,39 @@ namespace Emby.Server.Core } } - public abstract void LaunchUrl(string url); + public void LaunchUrl(string url) + { + if (EnvironmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows) + { + throw new NotImplementedException(); + } + + var process = ProcessFactory.Create(new ProcessOptions { + FileName = url, + EnableRaisingEvents = true, + UseShellExecute = true, + ErrorDialog = false + }); + + process.Exited += ProcessExited; + + try + { + process.Start(); + } + catch (Exception ex) + { + Console.WriteLine("Error launching url: {0}", url); + Logger.ErrorException("Error launching url: {0}", ex, url); + + throw; + } + } + + private static void ProcessExited(object sender, EventArgs e) + { + ((IProcess)sender).Dispose(); + } public void EnableLoopback(string appName) { diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index 7836c8b41b..c506411d47 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -12,12 +12,22 @@ namespace Emby.Server.Implementations.Data public abstract class BaseSqliteRepository : IDisposable { protected string DbFilePath { get; set; } - protected ReaderWriterLockSlim WriteLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); + protected ReaderWriterLockSlim WriteLock; + protected ILogger Logger { get; private set; } protected BaseSqliteRepository(ILogger logger) { Logger = logger; + + WriteLock = AllowLockRecursion ? + new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion) : + new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); + } + + protected virtual bool AllowLockRecursion + { + get { return false; } } protected virtual bool EnableConnectionPooling @@ -86,7 +96,7 @@ namespace Emby.Server.Implementations.Data var cacheSize = CacheSize; if (cacheSize.HasValue) { - + } if (EnableExclusiveMode) @@ -206,11 +216,7 @@ namespace Emby.Server.Implementations.Data return; } - connection.ExecuteAll(string.Join(";", new string[] - { - "alter table " + table, - "add column " + columnName + " " + type + " NULL" - })); + connection.Execute("alter table " + table + " add column " + columnName + " " + type + " NULL"); } } diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 255235cc7b..150e4072ac 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -95,6 +95,14 @@ namespace Emby.Server.Implementations.Data DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db"); } + protected override bool AllowLockRecursion + { + get + { + return true; + } + } + private const string ChaptersTableName = "Chapters2"; protected override int? CacheSize diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunLiveStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunLiveStream.cs index 1e8057f875..4852270d5e 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunLiveStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunLiveStream.cs @@ -89,7 +89,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { Url = url, CancellationToken = cancellationToken, - BufferContent = false + BufferContent = false, + + // Increase a little bit + TimeoutMs = 30000 }, "GET").ConfigureAwait(false)) { diff --git a/MediaBrowser.Server.Mono/MonoAppHost.cs b/MediaBrowser.Server.Mono/MonoAppHost.cs index f317997f82..8def1ca2bf 100644 --- a/MediaBrowser.Server.Mono/MonoAppHost.cs +++ b/MediaBrowser.Server.Mono/MonoAppHost.cs @@ -126,11 +126,6 @@ namespace MediaBrowser.Server.Mono throw new NotImplementedException(); } - public override void LaunchUrl(string url) - { - throw new NotImplementedException(); - } - protected override void EnableLoopbackInternal(string appName) { } diff --git a/MediaBrowser.ServerApplication/WindowsAppHost.cs b/MediaBrowser.ServerApplication/WindowsAppHost.cs index e36287584e..c2cdb9ab01 100644 --- a/MediaBrowser.ServerApplication/WindowsAppHost.cs +++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs @@ -119,38 +119,6 @@ namespace MediaBrowser.ServerApplication } } - public override void LaunchUrl(string url) - { - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = url - }, - - EnableRaisingEvents = true, - }; - - process.Exited += ProcessExited; - - try - { - process.Start(); - } - catch (Exception ex) - { - Console.WriteLine("Error launching url: {0}", url); - Logger.ErrorException("Error launching url: {0}", ex, url); - - throw; - } - } - - private static void ProcessExited(object sender, EventArgs e) - { - ((Process)sender).Dispose(); - } - protected override void EnableLoopbackInternal(string appName) { LoopUtil.Run(appName); diff --git a/src/Emby.Server/CoreAppHost.cs b/src/Emby.Server/CoreAppHost.cs index 5291f20ef3..09df664faa 100644 --- a/src/Emby.Server/CoreAppHost.cs +++ b/src/Emby.Server/CoreAppHost.cs @@ -4,8 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; using Emby.Server.Core; -using Emby.Server.Core.FFMpeg; -using Emby.Server.Data; +using Emby.Server.Implementations.FFMpeg; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.System; @@ -39,9 +38,37 @@ namespace Emby.Server { var info = new FFMpegInstallInfo(); + if (EnvironmentInfo.OperatingSystem == OperatingSystem.Windows) + { + info.FFMpegFilename = "ffmpeg.exe"; + info.FFProbeFilename = "ffprobe.exe"; + info.Version = "20160410"; + info.ArchiveType = "7z"; + info.DownloadUrls = GetDownloadUrls(); + } + return info; } + private string[] GetDownloadUrls() + { + switch (EnvironmentInfo.SystemArchitecture) + { + case Architecture.X64: + return new[] + { + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160410-win64.7z" + }; + case Architecture.X86: + return new[] + { + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160410-win32.7z" + }; + } + + return new string[] { }; + } + protected override List GetAssembliesWithPartsInternal() { var list = new List(); @@ -59,10 +86,6 @@ namespace Emby.Server { } - public override void LaunchUrl(string url) - { - } - protected override void EnableLoopbackInternal(string appName) { } @@ -98,5 +121,13 @@ namespace Emby.Server return Program.CanSelfUpdate; } } + + protected override bool SupportsDualModeSockets + { + get + { + return true; + } + } } } diff --git a/src/Emby.Server/Program.cs b/src/Emby.Server/Program.cs index e5d8351fe5..24e391c739 100644 --- a/src/Emby.Server/Program.cs +++ b/src/Emby.Server/Program.cs @@ -39,19 +39,34 @@ namespace Emby.Server /// public static void Main(string[] args) { - var options = new StartupOptions(); + var options = new StartupOptions(Environment.GetCommandLineArgs()); + + var environmentInfo = new EnvironmentInfo(); - var currentProcess = Process.GetCurrentProcess(); - var baseDirectory = System.AppContext.BaseDirectory; - //var architecturePath = Path.Combine(Path.GetDirectoryName(applicationPath), Environment.Is64BitProcess ? "x64" : "x86"); + string archPath = baseDirectory; + if (environmentInfo.SystemArchitecture == MediaBrowser.Model.System.Architecture.X64) + { + archPath = Path.Combine(archPath, "x64"); + } + else if (environmentInfo.SystemArchitecture == MediaBrowser.Model.System.Architecture.X86) + { + archPath = Path.Combine(archPath, "x86"); + } + else + { + archPath = Path.Combine(archPath, "arm"); + } //Wand.SetMagickCoderModulePath(architecturePath); - //var success = SetDllDirectory(architecturePath); + if (environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows) + { + SetDllDirectory(archPath); + } var appPaths = CreateApplicationPaths(baseDirectory); - SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); + SetSqliteProvider(); var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Debug); @@ -75,7 +90,12 @@ namespace Emby.Server return; } - RunApplication(appPaths, logManager, options); + RunApplication(appPaths, logManager, options, environmentInfo); + } + + private static void SetSqliteProvider() + { + SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); } /// @@ -171,7 +191,7 @@ namespace Emby.Server /// The app paths. /// The log manager. /// The options. - private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options) + private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options, EnvironmentInfo environmentInfo) { var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true); @@ -185,7 +205,7 @@ namespace Emby.Server fileSystem, new PowerManagement(), "emby.windows.zip", - new EnvironmentInfo(), + environmentInfo, imageEncoder, new CoreSystemEvents(), new MemoryStreamFactory(), diff --git a/src/Emby.Server/project.json b/src/Emby.Server/project.json index 0e1cf8bee5..35ebdc2135 100644 --- a/src/Emby.Server/project.json +++ b/src/Emby.Server/project.json @@ -15,7 +15,7 @@ "Microsoft.Win32.Registry": "4.0.0", "System.Runtime.Extensions": "4.1.0", "System.Diagnostics.Process": "4.1.0", - "SQLitePCLRaw.provider.sqlite3.netstandard11": "1.1.0" + "SQLitePCLRaw.provider.sqlite3.netstandard11": "1.1.1-pre20161109081005" }, "frameworks": { From 985c9111cf14431c3e1a1f94953a6d4422d167ee Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 19:57:54 -0500 Subject: [PATCH 5/5] resolve incorrect field saving --- Emby.Server.Implementations/Data/SqliteItemRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 150e4072ac..c720a8d89a 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -864,7 +864,7 @@ namespace Emby.Server.Implementations.Data if (topParent != null) { //Logger.Debug("Item {0} has top parent {1}", item.Id, topParent.Id); - saveItemStatement.TryBind("@IsFolder", topParent.Id.ToString("N")); + saveItemStatement.TryBind("@TopParentId", topParent.Id.ToString("N")); } else {