From 234c51ea9a7898e2d14f317a30cc81e13cf2810c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 28 Aug 2017 14:19:23 -0400 Subject: 3.2.30.1 --- MediaBrowser.Server.Mono/Program.cs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'MediaBrowser.Server.Mono/Program.cs') diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 443699b5a..21278e00d 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -33,6 +33,9 @@ namespace MediaBrowser.Server.Mono private static ILogger _logger; private static IFileSystem FileSystem; + private static readonly TaskCompletionSource ApplicationTaskCompletionSource = new TaskCompletionSource(); + private static bool _restartOnShutdown; + public static void Main(string[] args) { var applicationPath = Assembly.GetEntryAssembly().Location; @@ -63,9 +66,13 @@ namespace MediaBrowser.Server.Mono } finally { - logger.Info("Shutting down"); - + _logger.Info("Disposing app host"); _appHost.Dispose(); + + if (_restartOnShutdown) + { + StartNewInstance(options); + } } } @@ -86,8 +93,6 @@ namespace MediaBrowser.Server.Mono return new ServerApplicationPaths(programDataPath, appFolderPath, Path.GetDirectoryName(applicationPath)); } - private static readonly TaskCompletionSource ApplicationTaskCompletionSource = new TaskCompletionSource(); - private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options) { // Allow all https requests @@ -243,11 +248,15 @@ namespace MediaBrowser.Server.Mono ApplicationTaskCompletionSource.SetResult(true); } - public static void Restart(StartupOptions startupOptions) + public static void Restart() { - _logger.Info("Disposing app host"); - _appHost.Dispose(); + _restartOnShutdown = true; + + Shutdown(); + } + private static void StartNewInstance(StartupOptions startupOptions) + { _logger.Info("Starting new instance"); string module = startupOptions.GetOption("-restartpath"); @@ -260,9 +269,9 @@ namespace MediaBrowser.Server.Mono if (!startupOptions.ContainsOption("-restartargs")) { var args = Environment.GetCommandLineArgs() - .Skip(1) - .Select(NormalizeCommandLineArgument) - .ToArray(); + .Skip(1) + .Select(NormalizeCommandLineArgument) + .ToArray(); commandLineArgsString = string.Join(" ", args); } @@ -271,9 +280,6 @@ namespace MediaBrowser.Server.Mono _logger.Info("Arguments: {0}", commandLineArgsString); Process.Start(module, commandLineArgsString); - - _logger.Info("Calling Environment.Exit"); - Environment.Exit(0); } private static string NormalizeCommandLineArgument(string arg) -- cgit v1.2.3 From 49b799adbe3d65973b136bee758584748ecf6c2a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Sep 2017 15:49:02 -0400 Subject: 3.2.30.8 --- Emby.Dlna/ContentDirectory/ContentDirectory.cs | 7 +- Emby.Dlna/DlnaManager.cs | 1 + Emby.Dlna/Main/DlnaEntryPoint.cs | 1 + .../MediaReceiverRegistrar.cs | 7 +- Emby.Dlna/PlayTo/Device.cs | 1 + Emby.Dlna/PlayTo/PlayToController.cs | 1 + Emby.Dlna/PlayTo/PlayToManager.cs | 1 + Emby.Drawing.ImageMagick/ImageMagickEncoder.cs | 6 +- Emby.Drawing.Skia/SkiaEncoder.cs | 43 ++++----- Emby.Drawing/ImageProcessor.cs | 10 +- Emby.Drawing/NullImageEncoder.cs | 4 - .../Activity/ActivityLogEntryPoint.cs | 1 + Emby.Server.Implementations/ApplicationHost.cs | 4 +- .../Channels/ChannelManager.cs | 1 + .../Data/ManagedConnection.cs | 1 + .../Diagnostics/CommonProcess.cs | 1 + .../EntryPoints/AutomaticRestartEntryPoint.cs | 1 + .../EntryPoints/ExternalPortForwarding.cs | 1 + .../EntryPoints/KeepServerAwake.cs | 1 + .../EntryPoints/LibraryChangedNotifier.cs | 1 + .../EntryPoints/LoadRegistrations.cs | 1 + .../EntryPoints/RecordingNotifier.cs | 1 + .../EntryPoints/RefreshUsersMetadata.cs | 4 +- .../EntryPoints/ServerEventNotifier.cs | 1 + .../EntryPoints/StartupWizard.cs | 4 +- .../EntryPoints/SystemEvents.cs | 1 + .../EntryPoints/UdpServerEntryPoint.cs | 1 + .../EntryPoints/UsageEntryPoint.cs | 1 + .../EntryPoints/UserDataChangeNotifier.cs | 1 + .../HttpClientManager/HttpClientManager.cs | 21 ---- .../HttpServer/SocketSharp/SharpWebSocket.cs | 1 + Emby.Server.Implementations/IO/FileRefresher.cs | 1 + Emby.Server.Implementations/IO/IsoManager.cs | 1 + Emby.Server.Implementations/IO/LibraryMonitor.cs | 1 + .../Library/MediaSourceManager.cs | 1 + .../LiveTv/EmbyTV/EmbyTV.cs | 1 + .../LiveTv/EmbyTV/EntryPoint.cs | 4 +- .../LiveTv/LiveTvManager.cs | 1 + .../LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs | 2 +- .../TunerHosts/HdHomerun/HdHomerunManager.cs | 1 + .../Logging/SimpleLogManager.cs | 15 ++- Emby.Server.Implementations/Net/NetAcceptSocket.cs | 1 + Emby.Server.Implementations/News/NewsEntryPoint.cs | 1 + .../Notifications/Notifications.cs | 1 + .../Notifications/WebSocketNotifier.cs | 4 +- .../Session/HttpSessionController.cs | 6 +- .../Session/SessionWebSocketListener.cs | 1 + .../Session/WebSocketController.cs | 1 + .../TV/SeriesPostScanTask.cs | 1 + .../Threading/CommonTimer.cs | 1 + .../Updates/InstallationManager.cs | 1 + MediaBrowser.Api/ApiEntryPoint.cs | 8 +- MediaBrowser.Api/BasePeriodicWebSocketListener.cs | 1 + MediaBrowser.Common/Net/HttpResponseInfo.cs | 1 + MediaBrowser.Common/Net/IHttpClient.cs | 2 +- MediaBrowser.Common/Progress/ActionableProgress.cs | 1 + MediaBrowser.Controller/Drawing/IImageEncoder.cs | 2 +- MediaBrowser.Controller/Drawing/ImageStream.cs | 1 + MediaBrowser.Controller/Session/SessionInfo.cs | 1 + MediaBrowser.Model/Net/HttpResponse.cs | 1 + MediaBrowser.Providers/Manager/ProviderManager.cs | 1 + MediaBrowser.Providers/Movies/MovieDbProvider.cs | 15 +-- MediaBrowser.Server.Mac/Main.cs | 22 +++-- MediaBrowser.Server.Mono/Program.cs | 36 +++---- MediaBrowser.ServerApplication/MainStartup.cs | 106 +++++++++++---------- MediaBrowser.XbmcMetadata/EntryPoint.cs | 1 + SharedVersion.cs | 2 +- SocketHttpListener/Net/HttpListener.cs | 1 + SocketHttpListener/WebSocket.cs | 1 + 69 files changed, 200 insertions(+), 180 deletions(-) (limited to 'MediaBrowser.Server.Mono/Program.cs') diff --git a/Emby.Dlna/ContentDirectory/ContentDirectory.cs b/Emby.Dlna/ContentDirectory/ContentDirectory.cs index d547ad8d4..fbd709010 100644 --- a/Emby.Dlna/ContentDirectory/ContentDirectory.cs +++ b/Emby.Dlna/ContentDirectory/ContentDirectory.cs @@ -17,7 +17,7 @@ using MediaBrowser.Model.Xml; namespace Emby.Dlna.ContentDirectory { - public class ContentDirectory : BaseService, IContentDirectory, IDisposable + public class ContentDirectory : BaseService, IContentDirectory { private readonly ILibraryManager _libraryManager; private readonly IImageProcessor _imageProcessor; @@ -143,10 +143,5 @@ namespace Emby.Dlna.ContentDirectory return null; } - - public void Dispose() - { - - } } } diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index 4ff413b9b..bdc523c8b 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -596,6 +596,7 @@ namespace Emby.Dlna public void Dispose() { + GC.SuppressFinalize(this); } } } \ No newline at end of file diff --git a/Emby.Dlna/Main/DlnaEntryPoint.cs b/Emby.Dlna/Main/DlnaEntryPoint.cs index a6facab7d..3dd36a27b 100644 --- a/Emby.Dlna/Main/DlnaEntryPoint.cs +++ b/Emby.Dlna/Main/DlnaEntryPoint.cs @@ -394,6 +394,7 @@ namespace Emby.Dlna.Main _communicationsServer.Dispose(); _communicationsServer = null; } + GC.SuppressFinalize(this); } public void DisposeDlnaServer() diff --git a/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs b/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs index 365354efd..4ed74a684 100644 --- a/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs +++ b/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs @@ -9,7 +9,7 @@ using MediaBrowser.Model.Xml; namespace Emby.Dlna.MediaReceiverRegistrar { - public class MediaReceiverRegistrar : BaseService, IMediaReceiverRegistrar, IDisposable + public class MediaReceiverRegistrar : BaseService, IMediaReceiverRegistrar { private readonly IServerConfigurationManager _config; protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory; @@ -33,10 +33,5 @@ namespace Emby.Dlna.MediaReceiverRegistrar Logger, XmlReaderSettingsFactory) .ProcessControlRequest(request); } - - public void Dispose() - { - - } } } diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs index 213e7367f..5a63be304 100644 --- a/Emby.Dlna/PlayTo/Device.cs +++ b/Emby.Dlna/PlayTo/Device.cs @@ -1105,6 +1105,7 @@ namespace Emby.Dlna.PlayTo _disposed = true; DisposeTimer(); + GC.SuppressFinalize(this); } } diff --git a/Emby.Dlna/PlayTo/PlayToController.cs b/Emby.Dlna/PlayTo/PlayToController.cs index f1b18a543..e8d7c9127 100644 --- a/Emby.Dlna/PlayTo/PlayToController.cs +++ b/Emby.Dlna/PlayTo/PlayToController.cs @@ -685,6 +685,7 @@ namespace Emby.Dlna.PlayTo _device.OnDeviceUnavailable = null; _device.Dispose(); + GC.SuppressFinalize(this); } } diff --git a/Emby.Dlna/PlayTo/PlayToManager.cs b/Emby.Dlna/PlayTo/PlayToManager.cs index e29ef78a8..6f2f5f24b 100644 --- a/Emby.Dlna/PlayTo/PlayToManager.cs +++ b/Emby.Dlna/PlayTo/PlayToManager.cs @@ -225,6 +225,7 @@ namespace Emby.Dlna.PlayTo { _disposed = true; _deviceDiscovery.DeviceDiscovered -= _deviceDiscovery_DeviceDiscovered; + GC.SuppressFinalize(this); } } } diff --git a/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs b/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs index 9abf85e70..2c40bf570 100644 --- a/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs +++ b/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs @@ -12,7 +12,7 @@ using MediaBrowser.Model.System; namespace Emby.Drawing.ImageMagick { - public class ImageMagickEncoder : IImageEncoder + public class ImageMagickEncoder : IImageEncoder, IDisposable { private readonly ILogger _logger; private readonly IApplicationPaths _appPaths; @@ -38,7 +38,8 @@ namespace Emby.Drawing.ImageMagick // Some common file name extensions for RAW picture files include: .cr2, .crw, .dng, .nef, .orf, .rw2, .pef, .arw, .sr2, .srf, and .tif. return new[] { - "tiff", + "tiff", + "tif", "jpeg", "jpg", "png", @@ -327,6 +328,7 @@ namespace Emby.Drawing.ImageMagick { _disposed = true; Wand.CloseEnvironment(); + GC.SuppressFinalize(this); } private void CheckDisposed() diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index b5d6010b0..0eaa96609 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -193,30 +193,31 @@ namespace Emby.Drawing.Skia { using (var stream = new SKFileStream(path)) { - var codec = SKCodec.Create(stream); - - if (codec == null) + using (var codec = SKCodec.Create(stream)) { - origin = SKCodecOrigin.TopLeft; - return null; - } + if (codec == null) + { + origin = SKCodecOrigin.TopLeft; + return null; + } - // create the bitmap - var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height, !requiresTransparencyHack); + // create the bitmap + var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height, !requiresTransparencyHack); - if (bitmap != null) - { - // decode - codec.GetPixels(bitmap.Info, bitmap.GetPixels()); + if (bitmap != null) + { + // decode + codec.GetPixels(bitmap.Info, bitmap.GetPixels()); - origin = codec.Origin; - } - else - { - origin = SKCodecOrigin.TopLeft; - } + origin = codec.Origin; + } + else + { + origin = SKCodecOrigin.TopLeft; + } - return bitmap; + return bitmap; + } } } @@ -593,10 +594,6 @@ namespace Emby.Drawing.Skia get { return "Skia"; } } - public void Dispose() - { - } - public bool SupportsImageCollageCreation { get { return true; } diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 356343bae..1d3f4a8e3 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -126,6 +126,7 @@ namespace Emby.Drawing return new string[] { "tiff", + "tif", "jpeg", "jpg", "png", @@ -967,8 +968,15 @@ namespace Emby.Drawing public void Dispose() { _disposed = true; - _imageEncoder.Dispose(); + + var disposable = _imageEncoder as IDisposable; + if (disposable != null) + { + disposable.Dispose(); + } + _saveImageSizeTimer.Dispose(); + GC.SuppressFinalize(this); } private void CheckDisposed() diff --git a/Emby.Drawing/NullImageEncoder.cs b/Emby.Drawing/NullImageEncoder.cs index f04e8aaf1..95ea42ecf 100644 --- a/Emby.Drawing/NullImageEncoder.cs +++ b/Emby.Drawing/NullImageEncoder.cs @@ -61,9 +61,5 @@ namespace Emby.Drawing { throw new NotImplementedException(); } - - public void Dispose() - { - } } } diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs index 1b6daca73..4e448ac64 100644 --- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs +++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs @@ -491,6 +491,7 @@ namespace Emby.Server.Implementations.Activity //_logManager.LoggerLoaded -= _logManager_LoggerLoaded; _appHost.ApplicationUpdated -= _appHost_ApplicationUpdated; + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index b264cffe6..b3268b156 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -828,7 +828,7 @@ namespace Emby.Server.Implementations RegisterSingleInstance(MemoryStreamFactory); RegisterSingleInstance(SystemEvents); - RegisterSingleInstance(LogManager); + RegisterSingleInstance(LogManager, false); RegisterSingleInstance(Logger); RegisterSingleInstance(EnvironmentInfo); @@ -2341,6 +2341,7 @@ namespace Emby.Server.Implementations _disposed = true; Dispose(true); + GC.SuppressFinalize(this); } } @@ -2354,6 +2355,7 @@ namespace Emby.Server.Implementations { var type = GetType(); + LogManager.AddConsoleOutput(); Logger.Info("Disposing " + type.Name); var parts = DisposableParts.Distinct().Where(i => i.GetType() != type).ToList(); diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.cs index e842005a5..2f726f8ab 100644 --- a/Emby.Server.Implementations/Channels/ChannelManager.cs +++ b/Emby.Server.Implementations/Channels/ChannelManager.cs @@ -1624,6 +1624,7 @@ namespace Emby.Server.Implementations.Channels public void Dispose() { + GC.SuppressFinalize(this); } } } \ No newline at end of file diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.cs index 91a2dfdf6..5d0fc8ebc 100644 --- a/Emby.Server.Implementations/Data/ManagedConnection.cs +++ b/Emby.Server.Implementations/Data/ManagedConnection.cs @@ -77,6 +77,7 @@ namespace Emby.Server.Implementations.Data { Close(); } + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs index 09b8bf22c..a0a5f32ef 100644 --- a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs +++ b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs @@ -104,6 +104,7 @@ namespace Emby.Server.Implementations.Diagnostics public void Dispose() { _process.Dispose(); + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs index 561f5ee12..c2cee00c8 100644 --- a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs @@ -112,6 +112,7 @@ namespace Emby.Server.Implementations.EntryPoints _appHost.HasPendingRestartChanged -= _appHost_HasPendingRestartChanged; DisposeTimer(); + GC.SuppressFinalize(this); } private void DisposeTimer() diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index c96799b2f..9b434d606 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -294,6 +294,7 @@ namespace Emby.Server.Implementations.EntryPoints { _disposed = true; DisposeNat(); + GC.SuppressFinalize(this); } private void DisposeNat() diff --git a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs b/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs index 8ae85e390..221580681 100644 --- a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs +++ b/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs @@ -60,6 +60,7 @@ namespace Emby.Server.Implementations.EntryPoints _timer.Dispose(); _timer = null; } + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 80a188bc0..796d8cf48 100644 --- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -426,6 +426,7 @@ namespace Emby.Server.Implementations.EntryPoints public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs b/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs index 0203b5192..21e075cf5 100644 --- a/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs +++ b/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs @@ -68,6 +68,7 @@ namespace Emby.Server.Implementations.EntryPoints _timer.Dispose(); _timer = null; } + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs index b674fc39b..f73b40b46 100644 --- a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs @@ -72,6 +72,7 @@ namespace Emby.Server.Implementations.EntryPoints _liveTvManager.SeriesTimerCancelled -= _liveTvManager_SeriesTimerCancelled; _liveTvManager.TimerCreated -= _liveTvManager_TimerCreated; _liveTvManager.SeriesTimerCreated -= _liveTvManager_SeriesTimerCreated; + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs index 77de849a1..13e14be36 100644 --- a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs +++ b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Library; +using System; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using System.Threading; @@ -36,6 +37,7 @@ namespace Emby.Server.Implementations.EntryPoints /// public void Dispose() { + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs b/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs index 4d640bc95..514321e20 100644 --- a/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs @@ -174,6 +174,7 @@ namespace Emby.Server.Implementations.EntryPoints public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index 424153f22..614c04fd2 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -1,4 +1,5 @@ -using Emby.Server.Implementations.Browser; +using System; +using Emby.Server.Implementations.Browser; using MediaBrowser.Controller; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Logging; @@ -54,6 +55,7 @@ namespace Emby.Server.Implementations.EntryPoints /// public void Dispose() { + GC.SuppressFinalize(this); } } } \ No newline at end of file diff --git a/Emby.Server.Implementations/EntryPoints/SystemEvents.cs b/Emby.Server.Implementations/EntryPoints/SystemEvents.cs index 4ab6d32f3..aa63dae27 100644 --- a/Emby.Server.Implementations/EntryPoints/SystemEvents.cs +++ b/Emby.Server.Implementations/EntryPoints/SystemEvents.cs @@ -43,6 +43,7 @@ namespace Emby.Server.Implementations.EntryPoints public void Dispose() { _systemEvents.SystemShutdown -= _systemEvents_SystemShutdown; + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs index df5a7c985..d04df0d2b 100644 --- a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs @@ -65,6 +65,7 @@ namespace Emby.Server.Implementations.EntryPoints public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs index 99d39ffe0..fb9402986 100644 --- a/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs @@ -130,6 +130,7 @@ namespace Emby.Server.Implementations.EntryPoints public void Dispose() { _sessionManager.SessionStarted -= _sessionManager_SessionStarted; + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs index accdc5e9d..4a7182a43 100644 --- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs @@ -160,6 +160,7 @@ namespace Emby.Server.Implementations.EntryPoints } _userDataManager.UserDataSaved -= _userDataManager_UserDataSaved; + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index f512b723d..fe545ecff 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -822,27 +822,6 @@ namespace Emby.Server.Implementations.HttpClientManager return url; } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - _httpClients.Clear(); - } - } - /// /// Throws the cancellation exception. /// diff --git a/Emby.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs b/Emby.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs index 9823a2ff5..cc7a4557e 100644 --- a/Emby.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs +++ b/Emby.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs @@ -123,6 +123,7 @@ namespace Emby.Server.Implementations.HttpServer.SocketSharp public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs index 0ec62d895..20de8a518 100644 --- a/Emby.Server.Implementations/IO/FileRefresher.cs +++ b/Emby.Server.Implementations/IO/FileRefresher.cs @@ -238,6 +238,7 @@ namespace Emby.Server.Implementations.IO { _disposed = true; DisposeTimer(); + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/IO/IsoManager.cs b/Emby.Server.Implementations/IO/IsoManager.cs index 903d5f301..dc0b9e122 100644 --- a/Emby.Server.Implementations/IO/IsoManager.cs +++ b/Emby.Server.Implementations/IO/IsoManager.cs @@ -70,6 +70,7 @@ namespace Emby.Server.Implementations.IO { mounter.Dispose(); } + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 3994e2b00..56b10a7e6 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -649,6 +649,7 @@ namespace Emby.Server.Implementations.IO public void Dispose() { + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/Library/MediaSourceManager.cs b/Emby.Server.Implementations/Library/MediaSourceManager.cs index 6e0489d88..d60a04353 100644 --- a/Emby.Server.Implementations/Library/MediaSourceManager.cs +++ b/Emby.Server.Implementations/Library/MediaSourceManager.cs @@ -524,6 +524,7 @@ namespace Emby.Server.Implementations.Library public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } private readonly object _disposeLock = new object(); diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 885e3b0ee..92a47bddc 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -2630,6 +2630,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { pair.Value.CancellationTokenSource.Cancel(); } + GC.SuppressFinalize(this); } public List GetRecordingFolders() diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs index 139cf570e..7c5f630a7 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Plugins; +using System; +using MediaBrowser.Controller.Plugins; namespace Emby.Server.Implementations.LiveTv.EmbyTV { @@ -11,6 +12,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public void Dispose() { + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index 089af2a01..b243c6599 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -2779,6 +2779,7 @@ namespace Emby.Server.Implementations.LiveTv public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } private bool _isDisposed = false; diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index eae29bee7..f974b5c2c 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -422,7 +422,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun SupportsTranscoding = true, IsInfiniteStream = true, IgnoreDts = true, - //SupportsProbing = false, + SupportsProbing = false, //AnalyzeDurationMs = 2000000 //IgnoreIndex = true, //ReadAtNativeFramerate = true diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs index 41b058baf..c737c4cba 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs @@ -99,6 +99,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun var task = StopStreaming(); Task.WaitAll(task); + GC.SuppressFinalize(this); } public async Task CheckTunerAvailability(IpAddressInfo remoteIp, int tuner, CancellationToken cancellationToken) diff --git a/Emby.Server.Implementations/Logging/SimpleLogManager.cs b/Emby.Server.Implementations/Logging/SimpleLogManager.cs index 3a6992657..6129f38c4 100644 --- a/Emby.Server.Implementations/Logging/SimpleLogManager.cs +++ b/Emby.Server.Implementations/Logging/SimpleLogManager.cs @@ -107,6 +107,7 @@ namespace Emby.Server.Implementations.Logging } _fileLogger = null; + GC.SuppressFinalize(this); } } @@ -130,13 +131,18 @@ namespace Emby.Server.Implementations.Logging private void LogInternal() { - while (!_cancellationTokenSource.IsCancellationRequested) + while (!_cancellationTokenSource.IsCancellationRequested && !_disposed) { try { foreach (var message in _queue.GetConsumingEnumerable()) { var bytes = Encoding.UTF8.GetBytes(message + Environment.NewLine); + if (_disposed) + { + return; + } + _fileStream.Write(bytes, 0, bytes.Length); _fileStream.Flush(true); @@ -166,17 +172,18 @@ namespace Emby.Server.Implementations.Logging return; } - _fileStream.Flush(); + _fileStream.Flush(true); } public void Dispose() { _cancellationTokenSource.Cancel(); - _disposed = true; + Flush(); - _fileStream.Flush(); + _disposed = true; _fileStream.Dispose(); + GC.SuppressFinalize(this); } } diff --git a/Emby.Server.Implementations/Net/NetAcceptSocket.cs b/Emby.Server.Implementations/Net/NetAcceptSocket.cs index 93638a367..d80341a07 100644 --- a/Emby.Server.Implementations/Net/NetAcceptSocket.cs +++ b/Emby.Server.Implementations/Net/NetAcceptSocket.cs @@ -92,6 +92,7 @@ namespace Emby.Server.Implementations.Net public void Dispose() { Socket.Dispose(); + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/News/NewsEntryPoint.cs b/Emby.Server.Implementations/News/NewsEntryPoint.cs index 3c9a3bbf1..03c79c2c1 100644 --- a/Emby.Server.Implementations/News/NewsEntryPoint.cs +++ b/Emby.Server.Implementations/News/NewsEntryPoint.cs @@ -271,6 +271,7 @@ namespace Emby.Server.Implementations.News _timer.Dispose(); _timer = null; } + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/Notifications/Notifications.cs b/Emby.Server.Implementations/Notifications/Notifications.cs index ac3cc7564..09c1f07e0 100644 --- a/Emby.Server.Implementations/Notifications/Notifications.cs +++ b/Emby.Server.Implementations/Notifications/Notifications.cs @@ -551,6 +551,7 @@ namespace Emby.Server.Implementations.Notifications _deviceManager.CameraImageUploaded -= _deviceManager_CameraImageUploaded; _userManager.UserLockedOut -= _userManager_UserLockedOut; + GC.SuppressFinalize(this); } private void DisposeLibraryUpdateTimer() diff --git a/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs b/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs index 0d89ba84f..6e57e7f81 100644 --- a/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs +++ b/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Net; +using System; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Notifications; using MediaBrowser.Controller.Plugins; using System.Linq; @@ -49,6 +50,7 @@ namespace Emby.Server.Implementations.Notifications public void Dispose() { _notificationsRepo.NotificationAdded -= _notificationsRepo_NotificationAdded; + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/Session/HttpSessionController.cs b/Emby.Server.Implementations/Session/HttpSessionController.cs index dbac76bb4..bd53da1bd 100644 --- a/Emby.Server.Implementations/Session/HttpSessionController.cs +++ b/Emby.Server.Implementations/Session/HttpSessionController.cs @@ -14,7 +14,7 @@ using System.Threading.Tasks; namespace Emby.Server.Implementations.Session { - public class HttpSessionController : ISessionController, IDisposable + public class HttpSessionController : ISessionController { private readonly IHttpClient _httpClient; private readonly IJsonSerializer _json; @@ -195,9 +195,5 @@ namespace Emby.Server.Implementations.Session return "?" + args; } - - public void Dispose() - { - } } } diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs index 2735bb237..a5af843db 100644 --- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs +++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs @@ -102,6 +102,7 @@ namespace Emby.Server.Implementations.Session public void Dispose() { _serverManager.WebSocketConnected -= _serverManager_WebSocketConnected; + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.cs index f0ff0b5dd..ee9ee8969 100644 --- a/Emby.Server.Implementations/Session/WebSocketController.cs +++ b/Emby.Server.Implementations/Session/WebSocketController.cs @@ -283,6 +283,7 @@ namespace Emby.Server.Implementations.Session { socket.Closed -= connection_Closed; } + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/TV/SeriesPostScanTask.cs b/Emby.Server.Implementations/TV/SeriesPostScanTask.cs index 23b6a3cb5..764df8baf 100644 --- a/Emby.Server.Implementations/TV/SeriesPostScanTask.cs +++ b/Emby.Server.Implementations/TV/SeriesPostScanTask.cs @@ -217,6 +217,7 @@ namespace Emby.Server.Implementations.TV public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/Emby.Server.Implementations/Threading/CommonTimer.cs b/Emby.Server.Implementations/Threading/CommonTimer.cs index 9451b07f3..bb67325d1 100644 --- a/Emby.Server.Implementations/Threading/CommonTimer.cs +++ b/Emby.Server.Implementations/Threading/CommonTimer.cs @@ -31,6 +31,7 @@ namespace Emby.Server.Implementations.Threading public void Dispose() { _timer.Dispose(); + GC.SuppressFinalize(this); } } } diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 75328a39a..180463040 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -722,6 +722,7 @@ namespace Emby.Server.Implementations.Updates public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } } } diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 21552617d..04cef60bf 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -81,18 +81,14 @@ namespace MediaBrowser.Api return value.Split(separator); } - /// - /// Runs this instance. - /// public void Run() { + } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// public void Dispose() { + GC.SuppressFinalize(this); } } } diff --git a/MediaBrowser.Api/BasePeriodicWebSocketListener.cs b/MediaBrowser.Api/BasePeriodicWebSocketListener.cs index 8004d7e9b..c7a9d97ba 100644 --- a/MediaBrowser.Api/BasePeriodicWebSocketListener.cs +++ b/MediaBrowser.Api/BasePeriodicWebSocketListener.cs @@ -314,6 +314,7 @@ namespace MediaBrowser.Api public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } } diff --git a/MediaBrowser.Common/Net/HttpResponseInfo.cs b/MediaBrowser.Common/Net/HttpResponseInfo.cs index ed941a447..0d7fb69cb 100644 --- a/MediaBrowser.Common/Net/HttpResponseInfo.cs +++ b/MediaBrowser.Common/Net/HttpResponseInfo.cs @@ -70,6 +70,7 @@ namespace MediaBrowser.Common.Net { _disposable.Dispose(); } + GC.SuppressFinalize(this); } } } diff --git a/MediaBrowser.Common/Net/IHttpClient.cs b/MediaBrowser.Common/Net/IHttpClient.cs index 4eabbc803..15257715f 100644 --- a/MediaBrowser.Common/Net/IHttpClient.cs +++ b/MediaBrowser.Common/Net/IHttpClient.cs @@ -9,7 +9,7 @@ namespace MediaBrowser.Common.Net /// /// Interface IHttpClient /// - public interface IHttpClient : IDisposable + public interface IHttpClient { /// /// Gets the response. diff --git a/MediaBrowser.Common/Progress/ActionableProgress.cs b/MediaBrowser.Common/Progress/ActionableProgress.cs index 503f3f407..5b318c6a7 100644 --- a/MediaBrowser.Common/Progress/ActionableProgress.cs +++ b/MediaBrowser.Common/Progress/ActionableProgress.cs @@ -30,6 +30,7 @@ namespace MediaBrowser.Common.Progress public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index 131d0bd9e..757448eb2 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -3,7 +3,7 @@ using MediaBrowser.Model.Drawing; namespace MediaBrowser.Controller.Drawing { - public interface IImageEncoder : IDisposable + public interface IImageEncoder { /// /// Gets the supported input formats. diff --git a/MediaBrowser.Controller/Drawing/ImageStream.cs b/MediaBrowser.Controller/Drawing/ImageStream.cs index 353abaca3..b5e14eb6c 100644 --- a/MediaBrowser.Controller/Drawing/ImageStream.cs +++ b/MediaBrowser.Controller/Drawing/ImageStream.cs @@ -23,6 +23,7 @@ namespace MediaBrowser.Controller.Drawing { Stream.Dispose(); } + GC.SuppressFinalize(this); } } } diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index 90c1de2f2..367a7a467 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -303,6 +303,7 @@ namespace MediaBrowser.Controller.Session StopAutomaticProgress(); _sessionManager = null; + GC.SuppressFinalize(this); } } } diff --git a/MediaBrowser.Model/Net/HttpResponse.cs b/MediaBrowser.Model/Net/HttpResponse.cs index f4bd8e681..7c3d1d73d 100644 --- a/MediaBrowser.Model/Net/HttpResponse.cs +++ b/MediaBrowser.Model/Net/HttpResponse.cs @@ -59,6 +59,7 @@ namespace MediaBrowser.Model.Net { _disposable.Dispose(); } + GC.SuppressFinalize(this); } } } diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index d249b6b00..c36d4cf63 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -1110,6 +1110,7 @@ namespace MediaBrowser.Providers.Manager { _disposeCancellationTokenSource.Cancel(); } + GC.SuppressFinalize(this); } } } \ No newline at end of file diff --git a/MediaBrowser.Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Providers/Movies/MovieDbProvider.cs index ec1c49742..fe798d4f0 100644 --- a/MediaBrowser.Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbProvider.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Providers.Movies /// /// Class MovieDbProvider /// - public class MovieDbProvider : IRemoteMetadataProvider, IDisposable, IHasOrder + public class MovieDbProvider : IRemoteMetadataProvider, IHasOrder { internal static MovieDbProvider Current { get; private set; } @@ -130,14 +130,6 @@ namespace MediaBrowser.Providers.Movies get { return "TheMovieDb"; } } - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - } - /// /// The _TMDB settings task /// @@ -434,11 +426,6 @@ namespace MediaBrowser.Providers.Movies return await _httpClient.Get(options).ConfigureAwait(false); } - public void Dispose() - { - Dispose(true); - } - /// /// Class TmdbTitle /// diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index 3863937f8..6af58e66c 100644 --- a/MediaBrowser.Server.Mac/Main.cs +++ b/MediaBrowser.Server.Mac/Main.cs @@ -56,20 +56,22 @@ namespace MediaBrowser.Server.Mac var appPaths = CreateApplicationPaths(appFolderPath, customProgramDataPath); - var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); - logManager.ReloadLogger(LogSeverity.Info); - logManager.AddConsoleOutput(); + using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) + { + logManager.ReloadLogger(LogSeverity.Info); + logManager.AddConsoleOutput(); - var logger = _logger = logManager.GetLogger("Main"); + var logger = _logger = logManager.GetLogger("Main"); - ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); + ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - StartApplication(appPaths, logManager, options); - NSApplication.Init (); - NSApplication.Main (args); - } + StartApplication(appPaths, logManager, options); + NSApplication.Init(); + NSApplication.Main(args); + } + } private static ServerApplicationPaths CreateApplicationPaths(string appFolderPath, string programDataPath) { diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 21278e00d..98ad8bb02 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -50,28 +50,30 @@ namespace MediaBrowser.Server.Mono var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath); - var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); - logManager.ReloadLogger(LogSeverity.Info); - logManager.AddConsoleOutput(); + using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) + { + logManager.ReloadLogger(LogSeverity.Info); + logManager.AddConsoleOutput(); - var logger = _logger = logManager.GetLogger("Main"); + var logger = _logger = logManager.GetLogger("Main"); - ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); - - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); - try - { - RunApplication(appPaths, logManager, options); - } - finally - { - _logger.Info("Disposing app host"); - _appHost.Dispose(); + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - if (_restartOnShutdown) + try { - StartNewInstance(options); + RunApplication(appPaths, logManager, options); + } + finally + { + _logger.Info("Disposing app host"); + _appHost.Dispose(); + + if (_restartOnShutdown) + { + StartNewInstance(options); + } } } } diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 1429824ff..31acd1820 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -72,69 +72,71 @@ namespace MediaBrowser.ServerApplication var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); - var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); - logManager.ReloadLogger(LogSeverity.Debug); - logManager.AddConsoleOutput(); + using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) + { + logManager.ReloadLogger(LogSeverity.Debug); + logManager.AddConsoleOutput(); - var logger = _logger = logManager.GetLogger("Main"); + var logger = _logger = logManager.GetLogger("Main"); - ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); + ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); - // Install directly - if (options.ContainsOption("-installservice")) - { - logger.Info("Performing service installation"); - InstallService(ApplicationPath, logger); - return; - } + // Install directly + if (options.ContainsOption("-installservice")) + { + logger.Info("Performing service installation"); + InstallService(ApplicationPath, logger); + return; + } - // Restart with admin rights, then install - if (options.ContainsOption("-installserviceasadmin")) - { - logger.Info("Performing service installation"); - RunServiceInstallation(ApplicationPath); - return; - } + // Restart with admin rights, then install + if (options.ContainsOption("-installserviceasadmin")) + { + logger.Info("Performing service installation"); + RunServiceInstallation(ApplicationPath); + return; + } - // Uninstall directly - if (options.ContainsOption("-uninstallservice")) - { - logger.Info("Performing service uninstallation"); - UninstallService(ApplicationPath, logger); - return; - } + // Uninstall directly + if (options.ContainsOption("-uninstallservice")) + { + logger.Info("Performing service uninstallation"); + UninstallService(ApplicationPath, logger); + return; + } - // Restart with admin rights, then uninstall - if (options.ContainsOption("-uninstallserviceasadmin")) - { - logger.Info("Performing service uninstallation"); - RunServiceUninstallation(ApplicationPath); - return; - } + // Restart with admin rights, then uninstall + if (options.ContainsOption("-uninstallserviceasadmin")) + { + logger.Info("Performing service uninstallation"); + RunServiceUninstallation(ApplicationPath); + return; + } - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - RunServiceInstallationIfNeeded(ApplicationPath); + RunServiceInstallationIfNeeded(ApplicationPath); - if (IsAlreadyRunning(ApplicationPath, currentProcess)) - { - logger.Info("Shutting down because another instance of Emby Server is already running."); - return; - } + if (IsAlreadyRunning(ApplicationPath, currentProcess)) + { + logger.Info("Shutting down because another instance of Emby Server is already running."); + return; + } - if (PerformUpdateIfNeeded(appPaths, logger)) - { - logger.Info("Exiting to perform application update."); - return; - } + if (PerformUpdateIfNeeded(appPaths, logger)) + { + logger.Info("Exiting to perform application update."); + return; + } - try - { - RunApplication(appPaths, logManager, IsRunningAsService, options); - } - finally - { - OnServiceShutdown(); + try + { + RunApplication(appPaths, logManager, IsRunningAsService, options); + } + finally + { + OnServiceShutdown(); + } } } diff --git a/MediaBrowser.XbmcMetadata/EntryPoint.cs b/MediaBrowser.XbmcMetadata/EntryPoint.cs index b1c687a6e..98460f767 100644 --- a/MediaBrowser.XbmcMetadata/EntryPoint.cs +++ b/MediaBrowser.XbmcMetadata/EntryPoint.cs @@ -81,6 +81,7 @@ namespace MediaBrowser.XbmcMetadata public void Dispose() { _userDataManager.UserDataSaved -= _userDataManager_UserDataSaved; + GC.SuppressFinalize(this); } private async void SaveMetadataForItem(BaseItem item, ItemUpdateType updateReason) diff --git a/SharedVersion.cs b/SharedVersion.cs index fe1bfdeb6..85588a9af 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.30.7")] +[assembly: AssemblyVersion("3.2.30.8")] diff --git a/SocketHttpListener/Net/HttpListener.cs b/SocketHttpListener/Net/HttpListener.cs index 4ae472f9e..32c5e90e0 100644 --- a/SocketHttpListener/Net/HttpListener.cs +++ b/SocketHttpListener/Net/HttpListener.cs @@ -248,6 +248,7 @@ namespace SocketHttpListener.Net Close(true); //TODO: Should we force here or not? disposed = true; + GC.SuppressFinalize(this); } internal void CheckDisposed() diff --git a/SocketHttpListener/WebSocket.cs b/SocketHttpListener/WebSocket.cs index 9966d3fcf..57c075e32 100644 --- a/SocketHttpListener/WebSocket.cs +++ b/SocketHttpListener/WebSocket.cs @@ -880,6 +880,7 @@ namespace SocketHttpListener void IDisposable.Dispose() { Close(CloseStatusCode.Away, null); + GC.SuppressFinalize(this); } #endregion -- cgit v1.2.3 From 4ceb9eb6c5ac2d98a5499a96cdb56af88b0e6bb6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 9 Sep 2017 14:51:24 -0400 Subject: update restart function --- Emby.Server.Implementations/ApplicationHost.cs | 105 +++++++++------ MediaBrowser.Api/System/SystemService.cs | 6 +- MediaBrowser.Common/IApplicationHost.cs | 6 +- MediaBrowser.Model/System/SystemInfo.cs | 2 + MediaBrowser.Server.Mono/Program.cs | 51 +++---- MediaBrowser.ServerApplication/MainStartup.cs | 176 ++++++++++--------------- SharedVersion.cs | 2 +- 7 files changed, 165 insertions(+), 183 deletions(-) (limited to 'MediaBrowser.Server.Mono/Program.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 673798294..02308f79f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1,5 +1,4 @@ -using Emby.Common.Implementations; -using Emby.Common.Implementations.Serialization; +using Emby.Common.Implementations.Serialization; using Emby.Dlna; using Emby.Dlna.ConnectionManager; using Emby.Dlna.ContentDirectory; @@ -8,12 +7,16 @@ using Emby.Dlna.MediaReceiverRegistrar; using Emby.Dlna.Ssdp; using Emby.Drawing; using Emby.Photos; +using Emby.Server.Core.Cryptography; using Emby.Server.Implementations.Activity; +using Emby.Server.Implementations.Archiving; using Emby.Server.Implementations.Channels; using Emby.Server.Implementations.Collections; using Emby.Server.Implementations.Configuration; +using Emby.Server.Implementations.Cryptography; using Emby.Server.Implementations.Data; using Emby.Server.Implementations.Devices; +using Emby.Server.Implementations.Diagnostics; using Emby.Server.Implementations.Dto; using Emby.Server.Implementations.FFMpeg; using Emby.Server.Implementations.HttpServer; @@ -23,14 +26,20 @@ using Emby.Server.Implementations.Library; using Emby.Server.Implementations.LiveTv; using Emby.Server.Implementations.Localization; using Emby.Server.Implementations.MediaEncoder; -using Emby.Server.Implementations.Migrations; +using Emby.Server.Implementations.Net; using Emby.Server.Implementations.Notifications; using Emby.Server.Implementations.Playlists; +using Emby.Server.Implementations.Reflection; +using Emby.Server.Implementations.ScheduledTasks; using Emby.Server.Implementations.Security; +using Emby.Server.Implementations.Serialization; using Emby.Server.Implementations.Session; using Emby.Server.Implementations.Social; +using Emby.Server.Implementations.Threading; using Emby.Server.Implementations.TV; using Emby.Server.Implementations.Updates; +using Emby.Server.Implementations.Xml; +using Emby.Server.MediaEncoding.Subtitles; using MediaBrowser.Api; using MediaBrowser.Common; using MediaBrowser.Common.Configuration; @@ -52,9 +61,6 @@ using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; @@ -72,10 +78,13 @@ using MediaBrowser.Controller.Subtitles; using MediaBrowser.Controller.Sync; using MediaBrowser.Controller.TV; using MediaBrowser.LocalMetadata.Savers; +using MediaBrowser.MediaEncoding.BdInfo; using MediaBrowser.Model.Activity; using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.Events; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; @@ -87,7 +96,9 @@ using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Services; using MediaBrowser.Model.Social; using MediaBrowser.Model.System; +using MediaBrowser.Model.Tasks; using MediaBrowser.Model.Text; +using MediaBrowser.Model.Threading; using MediaBrowser.Model.Updates; using MediaBrowser.Model.Xml; using MediaBrowser.Providers.Chapters; @@ -97,7 +108,6 @@ using MediaBrowser.WebDashboard.Api; using MediaBrowser.XbmcMetadata.Providers; using OpenSubtitlesHandler; using ServiceStack; -using SocketHttpListener.Primitives; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -111,22 +121,6 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Threading.Tasks; -using Emby.Server.Core.Cryptography; -using Emby.Server.Implementations.Archiving; -using Emby.Server.Implementations.Cryptography; -using Emby.Server.Implementations.Diagnostics; -using Emby.Server.Implementations.Net; -using Emby.Server.Implementations.Reflection; -using Emby.Server.Implementations.ScheduledTasks; -using Emby.Server.Implementations.Serialization; -using Emby.Server.Implementations.Threading; -using Emby.Server.Implementations.Xml; -using Emby.Server.MediaEncoding.Subtitles; -using MediaBrowser.MediaEncoding.BdInfo; -using MediaBrowser.Model.Cryptography; -using MediaBrowser.Model.Events; -using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; using StringExtensions = MediaBrowser.Controller.Extensions.StringExtensions; using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certificate; @@ -135,7 +129,7 @@ namespace Emby.Server.Implementations /// /// Class CompositionRoot /// - public abstract class ApplicationHost : IServerApplicationHost, IDependencyContainer + public abstract class ApplicationHost : IServerApplicationHost, IDependencyContainer, IDisposable { /// /// Gets a value indicating whether this instance can self restart. @@ -171,6 +165,8 @@ namespace Emby.Server.Implementations /// true if this instance has pending application restart; otherwise, false. public bool HasPendingRestart { get; private set; } + public bool IsShuttingDown { get; private set; } + /// /// Gets or sets the logger. /// @@ -367,7 +363,7 @@ namespace Emby.Server.Implementations protected IAuthService AuthService { get; private set; } protected readonly StartupOptions StartupOptions; - private readonly string _releaseAssetFilename; + protected readonly string ReleaseAssetFilename; internal IPowerManagement PowerManagement { get; private set; } internal IImageEncoder ImageEncoder { get; private set; } @@ -420,7 +416,7 @@ namespace Emby.Server.Implementations Logger = LogManager.GetLogger("App"); StartupOptions = options; - _releaseAssetFilename = releaseAssetFilename; + ReleaseAssetFilename = releaseAssetFilename; PowerManagement = powerManagement; ImageEncoder = imageEncoder; @@ -1755,25 +1751,35 @@ namespace Emby.Server.Implementations /// /// Restarts this instance. /// - public async Task Restart() + public void Restart() { if (!CanSelfRestart) { throw new PlatformNotSupportedException("The server is unable to self-restart. Please restart manually."); } - try + if (IsShuttingDown) { - await SessionManager.SendServerRestartNotification(CancellationToken.None).ConfigureAwait(false); + return; } - catch (Exception ex) + + IsShuttingDown = true; + + Task.Run(async () => { - Logger.ErrorException("Error sending server restart notification", ex); - } + try + { + await SessionManager.SendServerRestartNotification(CancellationToken.None).ConfigureAwait(false); + } + catch (Exception ex) + { + Logger.ErrorException("Error sending server restart notification", ex); + } - Logger.Info("Calling RestartInternal"); + Logger.Info("Calling RestartInternal"); - RestartInternal(); + RestartInternal(); + }); } protected abstract void RestartInternal(); @@ -1880,6 +1886,7 @@ namespace Emby.Server.Implementations return new SystemInfo { HasPendingRestart = HasPendingRestart, + IsShuttingDown = IsShuttingDown, Version = ApplicationVersion.ToString(), WebSocketPortNumber = HttpPort, FailedPluginAssemblies = FailedAssemblies.ToArray(), @@ -2107,6 +2114,13 @@ namespace Emby.Server.Implementations /// public async Task Shutdown() { + if (IsShuttingDown) + { + return; + } + + IsShuttingDown = true; + try { await SessionManager.SendServerShutdownNotification(CancellationToken.None).ConfigureAwait(false); @@ -2185,22 +2199,29 @@ namespace Emby.Server.Implementations /// Task{CheckForUpdateResult}. public async Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) { - var cacheLength = TimeSpan.FromHours(1); + var cacheLength = TimeSpan.FromMinutes(5); var updateLevel = SystemUpdateLevel; - if (updateLevel != PackageVersionClass.Release) - { - cacheLength = TimeSpan.FromMinutes(5); - } - - var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename, - "MBServer", "Mbserver.zip", cacheLength, cancellationToken).ConfigureAwait(false); + var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", + "Emby", + ApplicationVersion, + updateLevel, + ReleaseAssetFilename, + "MBServer", + UpdateTargetFileName, + cacheLength, + cancellationToken).ConfigureAwait(false); HasUpdateAvailable = result.IsUpdateAvailable; return result; } + protected virtual string UpdateTargetFileName + { + get { return "Mbserver.zip"; } + } + /// /// Updates the application. /// diff --git a/MediaBrowser.Api/System/SystemService.cs b/MediaBrowser.Api/System/SystemService.cs index 37613c1c8..d850b2ce7 100644 --- a/MediaBrowser.Api/System/SystemService.cs +++ b/MediaBrowser.Api/System/SystemService.cs @@ -192,11 +192,7 @@ namespace MediaBrowser.Api.System /// The request. public void Post(RestartApplication request) { - Task.Run(async () => - { - await Task.Delay(100).ConfigureAwait(false); - await _appHost.Restart().ConfigureAwait(false); - }); + _appHost.Restart(); } /// diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs index 2b5ae6799..dc0c9ac9b 100644 --- a/MediaBrowser.Common/IApplicationHost.cs +++ b/MediaBrowser.Common/IApplicationHost.cs @@ -42,6 +42,8 @@ namespace MediaBrowser.Common /// true if this instance has pending kernel reload; otherwise, false. bool HasPendingRestart { get; } + bool IsShuttingDown { get; } + /// /// Gets a value indicating whether this instance can self restart. /// @@ -57,11 +59,11 @@ namespace MediaBrowser.Common /// Notifies the pending restart. /// void NotifyPendingRestart(); - + /// /// Restarts this instance. /// - Task Restart(); + void Restart(); /// /// Gets the application version. diff --git a/MediaBrowser.Model/System/SystemInfo.cs b/MediaBrowser.Model/System/SystemInfo.cs index fce9dea4f..f9f3bf52e 100644 --- a/MediaBrowser.Model/System/SystemInfo.cs +++ b/MediaBrowser.Model/System/SystemInfo.cs @@ -36,6 +36,8 @@ namespace MediaBrowser.Model.System /// true if this instance has pending restart; otherwise, false. public bool HasPendingRestart { get; set; } + public bool IsShuttingDown { get; set; } + /// /// Gets or sets a value indicating whether [supports library monitor]. /// diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 98ad8bb02..c53a80ae6 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -11,6 +11,7 @@ using System.Net.Security; using System.Reflection; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Emby.Drawing; using Emby.Server.Core.Cryptography; using Emby.Server.Core; using Emby.Server.Implementations; @@ -18,6 +19,7 @@ using Emby.Server.Implementations.EnvironmentInfo; using Emby.Server.Implementations.IO; using Emby.Server.Implementations.Logging; using Emby.Server.Implementations.Networking; +using MediaBrowser.Controller; using MediaBrowser.Model.IO; using MediaBrowser.Model.System; using Mono.Unix.Native; @@ -28,10 +30,10 @@ namespace MediaBrowser.Server.Mono { public class MainClass { - private static ApplicationHost _appHost; - private static ILogger _logger; private static IFileSystem FileSystem; + private static IServerApplicationPaths _appPaths; + private static ILogManager _logManager; private static readonly TaskCompletionSource ApplicationTaskCompletionSource = new TaskCompletionSource(); private static bool _restartOnShutdown; @@ -49,9 +51,12 @@ namespace MediaBrowser.Server.Mono var customProgramDataPath = options.GetOption("-programdata"); var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath); + _appPaths = appPaths; using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) { + _logManager = logManager; + logManager.ReloadLogger(LogSeverity.Info); logManager.AddConsoleOutput(); @@ -68,7 +73,6 @@ namespace MediaBrowser.Server.Mono finally { _logger.Info("Disposing app host"); - _appHost.Dispose(); if (_restartOnShutdown) { @@ -106,40 +110,41 @@ namespace MediaBrowser.Server.Mono FileSystem = fileSystem; - var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths, environmentInfo); - - _appHost = new MonoAppHost(appPaths, + using (var appHost = new MonoAppHost(appPaths, logManager, options, fileSystem, new PowerManagement(), "emby.mono.zip", environmentInfo, - imageEncoder, + new NullImageEncoder(), new SystemEvents(logManager.GetLogger("SystemEvents")), - new NetworkManager(logManager.GetLogger("NetworkManager"))); - - if (options.ContainsOption("-v")) + new NetworkManager(logManager.GetLogger("NetworkManager")))) { - Console.WriteLine(_appHost.ApplicationVersion.ToString()); - return; - } + appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo); - Console.WriteLine("appHost.Init"); + if (options.ContainsOption("-v")) + { + Console.WriteLine(appHost.ApplicationVersion.ToString()); + return; + } - var initProgress = new Progress(); + Console.WriteLine("appHost.Init"); - var task = _appHost.Init(initProgress); - Task.WaitAll(task); + var initProgress = new Progress(); - Console.WriteLine("Running startup tasks"); + var task = appHost.Init(initProgress); + Task.WaitAll(task); - task = _appHost.RunStartupTasks(); - Task.WaitAll(task); + Console.WriteLine("Running startup tasks"); - task = ApplicationTaskCompletionSource.Task; + task = appHost.RunStartupTasks(); + Task.WaitAll(task); - Task.WaitAll(task); + task = ApplicationTaskCompletionSource.Task; + + Task.WaitAll(task); + } } private static MonoEnvironmentInfo GetEnvironmentInfo() @@ -231,7 +236,7 @@ namespace MediaBrowser.Server.Mono { var exception = (Exception)e.ExceptionObject; - new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager, FileSystem, new ConsoleLogger()).Log(exception); + new UnhandledExceptionWriter(_appPaths, _logger, _logManager, FileSystem, new ConsoleLogger()).Log(exception); if (!Debugger.IsAttached) { diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 31acd1820..3fe9c5aa7 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -25,6 +25,7 @@ using Emby.Server.Implementations.EnvironmentInfo; using Emby.Server.Implementations.IO; using Emby.Server.Implementations.Logging; using MediaBrowser.Common.Net; +using MediaBrowser.Controller; using MediaBrowser.Model.IO; using SystemEvents = Emby.Server.Implementations.SystemEvents; @@ -32,13 +33,13 @@ namespace MediaBrowser.ServerApplication { public class MainStartup { - private static ApplicationHost _appHost; + private static IServerApplicationPaths _appPaths; + private static ILogManager _logManager; private static ILogger _logger; public static bool IsRunningAsService = false; private static bool _canRestartService = false; - private static bool _appHostDisposed; [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetDllDirectory(string lpPathName); @@ -46,6 +47,7 @@ namespace MediaBrowser.ServerApplication public static string ApplicationPath; private static IFileSystem FileSystem; + private static bool _restartOnShutdown; /// /// Defines the entry point of the application. @@ -71,9 +73,12 @@ namespace MediaBrowser.ServerApplication SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); + _appPaths = appPaths; using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) { + _logManager = logManager; + logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); @@ -129,17 +134,28 @@ namespace MediaBrowser.ServerApplication return; } - try - { - RunApplication(appPaths, logManager, IsRunningAsService, options); - } - finally + RunApplication(appPaths, logManager, IsRunningAsService, options); + + logger.Info("Shutdown complete"); + + if (_restartOnShutdown) { - OnServiceShutdown(); + logger.Info("Starting new server process"); + var restartCommandLine = GetRestartCommandLine(); + + Process.Start(restartCommandLine.Item1, restartCommandLine.Item2); } } } + public static Tuple GetRestartCommandLine() + { + var currentProcess = Process.GetCurrentProcess(); + var processModulePath = currentProcess.MainModule.FileName; + + return new Tuple(processModulePath, Environment.CommandLine); + } + /// /// Determines whether [is already running] [the specified current process]. /// @@ -314,7 +330,7 @@ namespace MediaBrowser.ServerApplication FileSystem = fileSystem; - _appHost = new WindowsAppHost(appPaths, + using (var appHost = new WindowsAppHost(appPaths, logManager, options, fileSystem, @@ -323,60 +339,59 @@ namespace MediaBrowser.ServerApplication environmentInfo, new NullImageEncoder(), new SystemEvents(logManager.GetLogger("SystemEvents")), - new Networking.NetworkManager(logManager.GetLogger("NetworkManager"))); - - var initProgress = new Progress(); - - if (!runService) + new Networking.NetworkManager(logManager.GetLogger("NetworkManager")))) { - if (!options.ContainsOption("-nosplash")) ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash")); + var initProgress = new Progress(); - // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes - SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT | - ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); - } + if (!runService) + { + if (!options.ContainsOption("-nosplash")) ShowSplashScreen(appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash")); - var task = _appHost.Init(initProgress); - Task.WaitAll(task); + // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes + SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT | + ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); + } - if (!runService) - { - task = InstallVcredist2013IfNeeded(_appHost, _logger); + var task = appHost.Init(initProgress); Task.WaitAll(task); - // needed by skia - task = InstallVcredist2015IfNeeded(_appHost, _logger); - Task.WaitAll(task); - } + if (!runService) + { + task = InstallVcredist2013IfNeeded(appHost.HttpClient, _logger); + Task.WaitAll(task); - // set image encoder here - _appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths); + // needed by skia + task = InstallVcredist2015IfNeeded(appHost.HttpClient, _logger); + Task.WaitAll(task); + } - task = task.ContinueWith(new Action(a => _appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent); + // set image encoder here + appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths); - if (runService) - { - StartService(logManager); - } - else - { - Task.WaitAll(task); + task = task.ContinueWith(new Action(a => appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent); - Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; + if (runService) + { + StartService(logManager); + } + else + { + Task.WaitAll(task); - HideSplashScreen(); + HideSplashScreen(); - ShowTrayIcon(); + ShowTrayIcon(appHost); + } } } private static ServerNotifyIcon _serverNotifyIcon; private static TaskScheduler _mainTaskScheduler; - private static void ShowTrayIcon() + private static void ShowTrayIcon(ApplicationHost appHost) { //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); - _serverNotifyIcon = new ServerNotifyIcon(_appHost.LogManager, _appHost, _appHost.ServerConfigurationManager, _appHost.LocalizationManager); + _serverNotifyIcon = new ServerNotifyIcon(appHost.LogManager, appHost, appHost.ServerConfigurationManager, appHost.LocalizationManager); _mainTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Application.Run(); } @@ -413,14 +428,6 @@ namespace MediaBrowser.ServerApplication } } - static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) - { - if (e.Reason == SessionSwitchReason.SessionLogon) - { - BrowserLauncher.OpenDashboard(_appHost); - } - } - public static void Invoke(Action action) { if (IsRunningAsService) @@ -452,14 +459,6 @@ namespace MediaBrowser.ServerApplication /// The instance containing the event data. static void service_Disposed(object sender, EventArgs e) { - OnServiceShutdown(); - } - - private static void OnServiceShutdown() - { - _logger.Info("Shutting down"); - - DisposeAppHost(); } /// @@ -562,7 +561,7 @@ namespace MediaBrowser.ServerApplication { var exception = (Exception)e.ExceptionObject; - new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager, FileSystem, new ConsoleLogger()).Log(exception); + new UnhandledExceptionWriter(_appPaths, _logger, _logManager, FileSystem, new ConsoleLogger()).Log(exception); if (!IsRunningAsService) { @@ -623,45 +622,22 @@ namespace MediaBrowser.ServerApplication } else { - DisposeAppHost(); - ShutdownWindowsApplication(); } } public static void Restart() { - DisposeAppHost(); - if (IsRunningAsService) { - RestartWindowsService(); } else { - //_logger.Info("Hiding server notify icon"); - //_serverNotifyIcon.Visible = false; - - _logger.Info("Starting new instance"); - //Application.Restart(); - Process.Start(ApplicationPath); - + _restartOnShutdown = true; ShutdownWindowsApplication(); } } - private static void DisposeAppHost() - { - if (!_appHostDisposed) - { - _logger.Info("Disposing app host"); - - _appHostDisposed = true; - _appHost.Dispose(); - _logger.Info("App host dispose complete"); - } - } - private static void ShutdownWindowsApplication() { if (_serverNotifyIcon != null) @@ -671,9 +647,7 @@ namespace MediaBrowser.ServerApplication } _logger.Info("Calling Application.Exit"); - //Application.Exit(); - - Environment.Exit(0); + Application.Exit(); } private static void ShutdownWindowsService() @@ -689,23 +663,7 @@ namespace MediaBrowser.ServerApplication } } - private static void RestartWindowsService() - { - _logger.Info("Restarting background service"); - - var startInfo = new ProcessStartInfo - { - FileName = "cmd.exe", - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden, - Verb = "runas", - ErrorDialog = false, - Arguments = String.Format("/c sc stop {0} & sc start {0} & sc start {0}", BackgroundService.GetExistingServiceName()) - }; - Process.Start(startInfo); - } - - private static async Task InstallVcredist2013IfNeeded(ApplicationHost appHost, ILogger logger) + private static async Task InstallVcredist2013IfNeeded(IHttpClient httpClient, ILogger logger) { // Reference // http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed @@ -737,7 +695,7 @@ namespace MediaBrowser.ServerApplication try { - await InstallVcredist(GetVcredist2013Url()).ConfigureAwait(false); + await InstallVcredist(GetVcredist2013Url(), httpClient).ConfigureAwait(false); } catch (Exception ex) { @@ -757,7 +715,7 @@ namespace MediaBrowser.ServerApplication return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x86.exe"; } - private static async Task InstallVcredist2015IfNeeded(ApplicationHost appHost, ILogger logger) + private static async Task InstallVcredist2015IfNeeded(IHttpClient httpClient, ILogger logger) { // Reference // http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed @@ -813,7 +771,7 @@ namespace MediaBrowser.ServerApplication try { - await InstallVcredist(GetVcredist2015Url()).ConfigureAwait(false); + await InstallVcredist(GetVcredist2015Url(), httpClient).ConfigureAwait(false); } catch (Exception ex) { @@ -833,10 +791,8 @@ namespace MediaBrowser.ServerApplication return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2015/vc_redist.x86.exe"; } - private async static Task InstallVcredist(string url) + private async static Task InstallVcredist(string url, IHttpClient httpClient) { - var httpClient = _appHost.HttpClient; - var tmp = await httpClient.GetTempFile(new HttpRequestOptions { Url = url, diff --git a/SharedVersion.cs b/SharedVersion.cs index 93d7c2e19..2de4c7944 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.30.10")] +[assembly: AssemblyVersion("3.2.30.11")] -- cgit v1.2.3 From c6bd66a9f938b0c4227010f04b8f8b1df32feb58 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 9 Sep 2017 20:24:45 -0400 Subject: 3.2.30.12 --- .../People/MovieDbPersonProvider.cs | 31 ++---- MediaBrowser.Server.Mono/Program.cs | 23 ++--- MediaBrowser.ServerApplication/MainStartup.cs | 104 +++------------------ SharedVersion.cs | 2 +- 4 files changed, 29 insertions(+), 131 deletions(-) (limited to 'MediaBrowser.Server.Mono/Program.cs') diff --git a/MediaBrowser.Providers/People/MovieDbPersonProvider.cs b/MediaBrowser.Providers/People/MovieDbPersonProvider.cs index d8c9ce801..9aeaa8d1f 100644 --- a/MediaBrowser.Providers/People/MovieDbPersonProvider.cs +++ b/MediaBrowser.Providers/People/MovieDbPersonProvider.cs @@ -36,10 +36,6 @@ namespace MediaBrowser.Providers.People private readonly IHttpClient _httpClient; private readonly ILogger _logger; - private int _requestCount; - private readonly object _requestCountLock = new object(); - private DateTime _lastRequestCountReset; - public MovieDbPersonProvider(IFileSystem fileSystem, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger) { _fileSystem = fileSystem; @@ -89,26 +85,8 @@ namespace MediaBrowser.Providers.People if (searchInfo.IsAutomated) { - lock (_requestCountLock) - { - if ((DateTime.UtcNow - _lastRequestCountReset).TotalHours >= 1) - { - _requestCount = 0; - _lastRequestCountReset = DateTime.UtcNow; - } - - var requestCount = _requestCount; - - if (requestCount >= 40) - { - //_logger.Debug("Throttling Tmdb people"); - - // This needs to be throttled - return new List(); - } - - _requestCount = requestCount + 1; - } + // Don't hammer moviedb searching by name + return new List(); } var url = string.Format(@"https://api.themoviedb.org/3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), MovieDbProvider.ApiKey); @@ -179,7 +157,10 @@ namespace MediaBrowser.Providers.People var item = new Person(); result.HasMetadata = true; - item.Name = info.name; + // Take name from incoming info, don't rename the person + // TODO: This should go in PersonMetadataService, not each person provider + item.Name = id.Name; + item.HomePageUrl = info.homepage; if (!string.IsNullOrWhiteSpace(info.place_of_birth)) diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index c53a80ae6..04298e325 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -41,7 +41,6 @@ namespace MediaBrowser.Server.Mono public static void Main(string[] args) { var applicationPath = Assembly.GetEntryAssembly().Location; - var appFolderPath = Path.GetDirectoryName(applicationPath); SetSqliteProvider(); @@ -66,18 +65,13 @@ namespace MediaBrowser.Server.Mono AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - try - { - RunApplication(appPaths, logManager, options); - } - finally - { - _logger.Info("Disposing app host"); + RunApplication(appPaths, logManager, options); - if (_restartOnShutdown) - { - StartNewInstance(options); - } + _logger.Info("Disposing app host"); + + if (_restartOnShutdown) + { + StartNewInstance(options); } } } @@ -121,8 +115,6 @@ namespace MediaBrowser.Server.Mono new SystemEvents(logManager.GetLogger("SystemEvents")), new NetworkManager(logManager.GetLogger("NetworkManager")))) { - appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo); - if (options.ContainsOption("-v")) { Console.WriteLine(appHost.ApplicationVersion.ToString()); @@ -134,6 +126,9 @@ namespace MediaBrowser.Server.Mono var initProgress = new Progress(); var task = appHost.Init(initProgress); + + appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo); + Task.WaitAll(task); Console.WriteLine("Running startup tasks"); diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 3fe9c5aa7..27eb3e0e1 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -39,7 +39,6 @@ namespace MediaBrowser.ServerApplication private static ILogger _logger; public static bool IsRunningAsService = false; - private static bool _canRestartService = false; [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetDllDirectory(string lpPathName); @@ -58,11 +57,6 @@ namespace MediaBrowser.ServerApplication var options = new StartupOptions(Environment.GetCommandLineArgs()); IsRunningAsService = options.ContainsOption("-service"); - if (IsRunningAsService) - { - //_canRestartService = CanRestartWindowsService(); - } - var currentProcess = Process.GetCurrentProcess(); ApplicationPath = currentProcess.MainModule.FileName; @@ -86,22 +80,6 @@ namespace MediaBrowser.ServerApplication ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); - // Install directly - if (options.ContainsOption("-installservice")) - { - logger.Info("Performing service installation"); - InstallService(ApplicationPath, logger); - return; - } - - // Restart with admin rights, then install - if (options.ContainsOption("-installserviceasadmin")) - { - logger.Info("Performing service installation"); - RunServiceInstallation(ApplicationPath); - return; - } - // Uninstall directly if (options.ContainsOption("-uninstallservice")) { @@ -120,8 +98,6 @@ namespace MediaBrowser.ServerApplication AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - RunServiceInstallationIfNeeded(ApplicationPath); - if (IsAlreadyRunning(ApplicationPath, currentProcess)) { logger.Info("Shutting down because another instance of Emby Server is already running."); @@ -156,6 +132,14 @@ namespace MediaBrowser.ServerApplication return new Tuple(processModulePath, Environment.CommandLine); } + private static bool IsServiceInstalled() + { + var serviceName = BackgroundService.GetExistingServiceName(); + var ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName); + + return ctl != null; + } + /// /// Determines whether [is already running] [the specified current process]. /// @@ -261,7 +245,7 @@ namespace MediaBrowser.ServerApplication var resourcesPath = Path.GetDirectoryName(applicationPath); - if (runAsService) + if (runAsService && IsServiceInstalled()) { var systemPath = Path.GetDirectoryName(applicationPath); @@ -283,7 +267,7 @@ namespace MediaBrowser.ServerApplication { if (IsRunningAsService) { - return _canRestartService; + return false; } else { @@ -306,7 +290,7 @@ namespace MediaBrowser.ServerApplication if (IsRunningAsService) { - return _canRestartService; + return false; } else { @@ -370,7 +354,7 @@ namespace MediaBrowser.ServerApplication task = task.ContinueWith(new Action(a => appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent); - if (runService) + if (runService && IsServiceInstalled()) { StartService(logManager); } @@ -447,37 +431,9 @@ namespace MediaBrowser.ServerApplication { var service = new BackgroundService(logManager.GetLogger("Service")); - service.Disposed += service_Disposed; - ServiceBase.Run(service); } - /// - /// Handles the Disposed event of the service control. - /// - /// The source of the event. - /// The instance containing the event data. - static void service_Disposed(object sender, EventArgs e) - { - } - - /// - /// Installs the service. - /// - private static void InstallService(string applicationPath, ILogger logger) - { - try - { - ManagedInstallerClass.InstallHelper(new[] { applicationPath }); - - logger.Info("Service installation succeeded"); - } - catch (Exception ex) - { - logger.ErrorException("Uninstall failed", ex); - } - } - /// /// Uninstalls the service. /// @@ -495,40 +451,6 @@ namespace MediaBrowser.ServerApplication } } - private static void RunServiceInstallationIfNeeded(string applicationPath) - { - var serviceName = BackgroundService.GetExistingServiceName(); - var ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName); - - if (ctl == null) - { - RunServiceInstallation(applicationPath); - } - } - - /// - /// Runs the service installation. - /// - private static void RunServiceInstallation(string applicationPath) - { - var startInfo = new ProcessStartInfo - { - FileName = applicationPath, - - Arguments = "-installservice", - - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden, - Verb = "runas", - ErrorDialog = false - }; - - using (var process = Process.Start(startInfo)) - { - process.WaitForExit(); - } - } - /// /// Runs the service uninstallation. /// @@ -616,7 +538,7 @@ namespace MediaBrowser.ServerApplication public static void Shutdown() { - if (IsRunningAsService) + if (IsRunningAsService && IsServiceInstalled()) { ShutdownWindowsService(); } diff --git a/SharedVersion.cs b/SharedVersion.cs index 2de4c7944..6d2d4b25c 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.30.11")] +[assembly: AssemblyVersion("3.2.30.12")] -- cgit v1.2.3 From 335ec27edc49243fa4310ebc1cec414c01dc0ab4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 11 Sep 2017 14:49:20 -0400 Subject: update themes --- MediaBrowser.Server.Mono/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Server.Mono/Program.cs') diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 04298e325..566a84da2 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -127,10 +127,10 @@ namespace MediaBrowser.Server.Mono var task = appHost.Init(initProgress); - appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo); - Task.WaitAll(task); + appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo); + Console.WriteLine("Running startup tasks"); task = appHost.RunStartupTasks(); -- cgit v1.2.3