diff options
Diffstat (limited to 'Emby.Server.Implementations/EntryPoints')
12 files changed, 34 insertions, 364 deletions
diff --git a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs index 561f5ee12..a0947c87d 100644 --- a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs @@ -2,7 +2,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using MediaBrowser.Model.Tasks; using System; using System.Linq; @@ -65,7 +65,7 @@ namespace Emby.Server.Implementations.EntryPoints { DisposeTimer(); - _logger.Info("Automatically restarting the system because it is idle and a restart is required."); + _logger.LogInformation("Automatically restarting the system because it is idle and a restart is required."); try { @@ -73,7 +73,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Error restarting server", ex); + _logger.LogError(ex, "Error restarting server"); } } } @@ -98,7 +98,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Error getting timers", ex); + _logger.LogError(ex, "Error getting timers"); } } diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index aa672a1b7..6cd867921 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -9,7 +9,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Events; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using MediaBrowser.Model.Threading; using Mono.Nat; using System.Threading; @@ -29,9 +29,9 @@ namespace Emby.Server.Implementations.EntryPoints private NatManager _natManager; - public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, ITimerFactory timerFactory) + public ExternalPortForwarding(ILoggerFactory loggerFactory, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, ITimerFactory timerFactory) { - _logger = logmanager.GetLogger("PortMapper"); + _logger = loggerFactory.CreateLogger("PortMapper"); _appHost = appHost; _config = config; _deviceDiscovery = deviceDiscovery; @@ -84,7 +84,7 @@ namespace Emby.Server.Implementations.EntryPoints private void Start() { - _logger.Debug("Starting NAT discovery"); + _logger.LogDebug("Starting NAT discovery"); if (_natManager == null) { _natManager = new NatManager(_logger, _httpClient); @@ -139,7 +139,7 @@ namespace Emby.Server.Implementations.EntryPoints _usnsHandled.Add(identifier); } - _logger.Debug("Found NAT device: " + identifier); + _logger.LogDebug("Found NAT device: " + identifier); IPAddress address; if (IPAddress.TryParse(info.Location.Host, out address)) @@ -166,6 +166,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { + _logger.LogError(ex, "Error"); return; } @@ -216,7 +217,7 @@ namespace Emby.Server.Implementations.EntryPoints catch { // Commenting out because users are reporting problems out of our control - //_logger.ErrorException("Error creating port forwarding rules", ex); + //_logger.LogError(ex, "Error creating port forwarding rules"); } } @@ -253,6 +254,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { + _logger.LogError(ex, "Error creating http port map"); return; } @@ -262,12 +264,13 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { + _logger.LogError(ex, "Error creating https port map"); } } private Task CreatePortMap(INatDevice device, int privatePort, int publicPort) { - _logger.Debug("Creating port map on local port {0} to public port {1} with device {2}", privatePort, publicPort, device.LocalAddress.ToString()); + _logger.LogDebug("Creating port map on local port {0} to public port {1} with device {2}", privatePort, publicPort, device.LocalAddress.ToString()); return device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort) { @@ -284,7 +287,7 @@ namespace Emby.Server.Implementations.EntryPoints private void DisposeNat() { - _logger.Debug("Stopping NAT discovery"); + _logger.LogDebug("Stopping NAT discovery"); if (_timer != null) { @@ -309,7 +312,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Error stopping NAT Discovery", ex); + _logger.LogError(ex, "Error stopping NAT Discovery"); } } } diff --git a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs b/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs deleted file mode 100644 index 8ae85e390..000000000 --- a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs +++ /dev/null @@ -1,65 +0,0 @@ -using MediaBrowser.Controller; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Logging; -using System; -using System.Linq; -using MediaBrowser.Model.System; -using MediaBrowser.Model.Threading; - -namespace Emby.Server.Implementations.EntryPoints -{ - public class KeepServerAwake : IServerEntryPoint - { - private readonly ISessionManager _sessionManager; - private readonly ILogger _logger; - private ITimer _timer; - private readonly IServerApplicationHost _appHost; - private readonly ITimerFactory _timerFactory; - private readonly IPowerManagement _powerManagement; - - public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost, ITimerFactory timerFactory, IPowerManagement powerManagement) - { - _sessionManager = sessionManager; - _logger = logger; - _appHost = appHost; - _timerFactory = timerFactory; - _powerManagement = powerManagement; - } - - public void Run() - { - _timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); - } - - private void OnTimerCallback(object state) - { - var now = DateTime.UtcNow; - - try - { - if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15)) - { - _powerManagement.PreventSystemStandby(); - } - else - { - _powerManagement.AllowSystemStandby(); - } - } - catch (Exception ex) - { - _logger.ErrorException("Error resetting system standby timer", ex); - } - } - - public void Dispose() - { - if (_timer != null) - { - _timer.Dispose(); - _timer = null; - } - } - } -} diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 9a2ae34bc..bb8ef52f1 100644 --- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -3,7 +3,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Globalization; @@ -331,7 +331,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Error in GetLibraryUpdateInfo", ex); + _logger.LogError(ex, "Error in GetLibraryUpdateInfo"); return; } @@ -346,7 +346,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Error sending LibraryChanged message", ex); + _logger.LogError(ex, "Error sending LibraryChanged message"); } } } diff --git a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs index d41d76c6b..0b377dc68 100644 --- a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs @@ -5,7 +5,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.EntryPoints { @@ -66,7 +66,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Error sending message", ex); + _logger.LogError(ex, "Error sending message"); } } diff --git a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs index 4c16b1d39..660ca3a94 100644 --- a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs +++ b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.EntryPoints { @@ -15,10 +16,12 @@ namespace Emby.Server.Implementations.EntryPoints /// </summary> public class RefreshUsersMetadata : IScheduledTask, IConfigurableScheduledTask { + private readonly ILogger _logger; /// <summary> /// The _user manager /// </summary> private readonly IUserManager _userManager; + private IFileSystem _fileSystem; public string Name => "Refresh Users"; @@ -41,8 +44,9 @@ namespace Emby.Server.Implementations.EntryPoints /// <summary> /// Initializes a new instance of the <see cref="RefreshUsersMetadata" /> class. /// </summary> - public RefreshUsersMetadata(IUserManager userManager, IFileSystem fileSystem) + public RefreshUsersMetadata(ILogger logger, IUserManager userManager, IFileSystem fileSystem) { + _logger = logger; _userManager = userManager; _fileSystem = fileSystem; } @@ -55,7 +59,7 @@ namespace Emby.Server.Implementations.EntryPoints { cancellationToken.ThrowIfCancellationRequested(); - await user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken).ConfigureAwait(false); + await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false); } } diff --git a/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs b/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs index e5748989e..72dcabab3 100644 --- a/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs @@ -157,13 +157,9 @@ namespace Emby.Server.Implementations.EntryPoints { await _sessionManager.SendMessageToAdminSessions(name, data, CancellationToken.None); } - catch (ObjectDisposedException) - { - - } catch (Exception) { - //Logger.ErrorException("Error sending message", ex); + } } @@ -173,13 +169,9 @@ namespace Emby.Server.Implementations.EntryPoints { await _sessionManager.SendMessageToUserSessions(new List<Guid> { user.Id }, name, data, CancellationToken.None); } - catch (ObjectDisposedException) - { - - } catch (Exception) { - //Logger.ErrorException("Error sending message", ex); + } } diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index 6d73f98ad..ffd98bf78 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -1,7 +1,7 @@ using Emby.Server.Implementations.Browser; using MediaBrowser.Controller; using MediaBrowser.Controller.Plugins; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using MediaBrowser.Controller.Configuration; namespace Emby.Server.Implementations.EntryPoints @@ -61,4 +61,4 @@ namespace Emby.Server.Implementations.EntryPoints { } } -}
\ No newline at end of file +} diff --git a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs index 5edc5fade..730ced055 100644 --- a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs @@ -1,7 +1,7 @@ using System; using MediaBrowser.Controller; using MediaBrowser.Controller.Plugins; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using MediaBrowser.Model.Serialization; using Emby.Server.Implementations.Udp; using MediaBrowser.Model.Net; @@ -45,9 +45,6 @@ namespace Emby.Server.Implementations.EntryPoints /// </summary> public void Run() { - // ToDo: Fix This - return; - var udpServer = new UdpServer(_logger, _appHost, _json, _socketFactory); try @@ -58,7 +55,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { - _logger.ErrorException("Failed to start UDP Server", ex); + _logger.LogError(ex, "Failed to start UDP Server"); } } diff --git a/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs deleted file mode 100644 index 450764040..000000000 --- a/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs +++ /dev/null @@ -1,131 +0,0 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Logging; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Model.Extensions; - -namespace Emby.Server.Implementations.EntryPoints -{ - /// <summary> - /// Class UsageEntryPoint - /// </summary> - public class UsageEntryPoint : IServerEntryPoint - { - private readonly IServerApplicationHost _applicationHost; - private readonly IHttpClient _httpClient; - private readonly ILogger _logger; - private readonly ISessionManager _sessionManager; - private readonly IUserManager _userManager; - private readonly IServerConfigurationManager _config; - - private readonly ConcurrentDictionary<Guid, ClientInfo> _apps = new ConcurrentDictionary<Guid, ClientInfo>(); - - public UsageEntryPoint(ILogger logger, IServerApplicationHost applicationHost, IHttpClient httpClient, ISessionManager sessionManager, IUserManager userManager, IServerConfigurationManager config) - { - _logger = logger; - _applicationHost = applicationHost; - _httpClient = httpClient; - _sessionManager = sessionManager; - _userManager = userManager; - _config = config; - - _sessionManager.SessionStarted += _sessionManager_SessionStarted; - } - - void _sessionManager_SessionStarted(object sender, SessionEventArgs e) - { - var session = e.SessionInfo; - - if (!string.IsNullOrEmpty(session.Client) && - !string.IsNullOrEmpty(session.DeviceName) && - !string.IsNullOrEmpty(session.DeviceId) && - !string.IsNullOrEmpty(session.ApplicationVersion)) - { - var keys = new List<string> - { - session.Client, - session.DeviceName, - session.DeviceId, - session.ApplicationVersion - }; - - var key = string.Join("_", keys.ToArray()).GetMD5(); - - ClientInfo info; - if (!_apps.TryGetValue(key, out info)) - { - info = new ClientInfo - { - AppName = session.Client, - AppVersion = session.ApplicationVersion, - DeviceName = session.DeviceName, - DeviceId = session.DeviceId - }; - - _apps[key] = info; - - if (_config.Configuration.EnableAnonymousUsageReporting) - { - Task.Run(() => ReportNewSession(info)); - } - } - } - } - - private async Task ReportNewSession(ClientInfo client) - { - try - { - await new UsageReporter(_applicationHost, _httpClient, _logger) - .ReportAppUsage(client, CancellationToken.None) - .ConfigureAwait(false); - } - catch (Exception ex) - { - //_logger.ErrorException("Error sending anonymous usage statistics.", ex); - } - } - - public async void Run() - { - await Task.Delay(5000).ConfigureAwait(false); - OnTimerFired(); - } - - /// <summary> - /// Called when [timer fired]. - /// </summary> - private async void OnTimerFired() - { - if (!_config.Configuration.EnableAnonymousUsageReporting) - { - return; - } - - try - { - await new UsageReporter(_applicationHost, _httpClient, _logger) - .ReportServerUsage(CancellationToken.None) - .ConfigureAwait(false); - } - catch (Exception ex) - { - //_logger.ErrorException("Error sending anonymous usage statistics.", ex); - } - } - - public void Dispose() - { - _sessionManager.SessionStarted -= _sessionManager_SessionStarted; - } - } -} diff --git a/Emby.Server.Implementations/EntryPoints/UsageReporter.cs b/Emby.Server.Implementations/EntryPoints/UsageReporter.cs deleted file mode 100644 index d9c9e1a40..000000000 --- a/Emby.Server.Implementations/EntryPoints/UsageReporter.cs +++ /dev/null @@ -1,130 +0,0 @@ -using MediaBrowser.Common; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Connect; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller; -using MediaBrowser.Model.Logging; - -namespace Emby.Server.Implementations.EntryPoints -{ - public class UsageReporter - { - private readonly IServerApplicationHost _applicationHost; - private readonly IHttpClient _httpClient; - private readonly ILogger _logger; - private const string MbAdminUrl = "https://www.mb3admin.local/admin/"; - - public UsageReporter(IServerApplicationHost applicationHost, IHttpClient httpClient, ILogger logger) - { - _applicationHost = applicationHost; - _httpClient = httpClient; - _logger = logger; - } - - public async Task ReportServerUsage(CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - var data = new Dictionary<string, string> - { - { "feature", _applicationHost.Name }, - { "mac", _applicationHost.SystemId }, - { "serverid", _applicationHost.SystemId }, - { "deviceid", _applicationHost.SystemId }, - { "ver", _applicationHost.ApplicationVersion.ToString() }, - { "platform", _applicationHost.OperatingSystemDisplayName } - }; - - data["plugins"] = string.Join(",", _applicationHost.Plugins.Select(i => i.Id).ToArray()); - - var logErrors = false; -#if DEBUG - logErrors = true; -#endif - var options = new HttpRequestOptions - { - Url = MbAdminUrl + "service/registration/ping", - CancellationToken = cancellationToken, - - // Seeing block length errors - EnableHttpCompression = false, - - LogRequest = false, - LogErrors = logErrors, - BufferContent = false - }; - - options.SetPostData(data); - - using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)) - { - - } - } - - public async Task ReportAppUsage(ClientInfo app, CancellationToken cancellationToken) - { - if (string.IsNullOrEmpty(app.DeviceId)) - { - throw new ArgumentException("Client info must have a device Id"); - } - - _logger.Info("App Activity: app: {0}, version: {1}, deviceId: {2}, deviceName: {3}", - app.AppName ?? "Unknown App", - app.AppVersion ?? "Unknown", - app.DeviceId, - app.DeviceName ?? "Unknown"); - - cancellationToken.ThrowIfCancellationRequested(); - - var data = new Dictionary<string, string> - { - { "feature", app.AppName ?? "Unknown App" }, - { "serverid", _applicationHost.SystemId }, - { "deviceid", app.DeviceId }, - { "mac", app.DeviceId }, - { "ver", app.AppVersion ?? "Unknown" }, - { "platform", app.DeviceName }, - }; - - var logErrors = false; - -#if DEBUG - logErrors = true; -#endif - var options = new HttpRequestOptions - { - Url = MbAdminUrl + "service/registration/ping", - CancellationToken = cancellationToken, - - // Seeing block length errors - EnableHttpCompression = false, - - LogRequest = false, - LogErrors = logErrors, - BufferContent = false - }; - - options.SetPostData(data); - - using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)) - { - - } - } - } - - public class ClientInfo - { - public string AppName { get; set; } - public string AppVersion { get; set; } - public string DeviceName { get; set; } - public string DeviceId { get; set; } - } -} diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs index 36e29e46a..58309ea1c 100644 --- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs @@ -3,7 +3,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using MediaBrowser.Model.Session; using System; using System.Collections.Generic; |
