diff options
| author | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
|---|---|---|
| committer | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
| commit | 48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch) | |
| tree | 8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs | |
| parent | c32d8656382a0eacb301692e0084377fc433ae9b (diff) | |
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs')
| -rw-r--r-- | Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs | 215 |
1 files changed, 120 insertions, 95 deletions
diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs index 4e448ac64..079d0af0a 100644 --- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs +++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs @@ -19,6 +19,11 @@ using System.Linq; using System.Text; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Extensions; +using MediaBrowser.Model.Notifications; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Dto; +using MediaBrowser.Controller.Devices; +using MediaBrowser.Controller.Authentication; namespace Emby.Server.Implementations.Activity { @@ -26,7 +31,6 @@ namespace Emby.Server.Implementations.Activity { private readonly IInstallationManager _installationManager; - //private readonly ILogManager _logManager; //private readonly ILogger _logger; private readonly ISessionManager _sessionManager; private readonly ITaskManager _taskManager; @@ -38,10 +42,10 @@ namespace Emby.Server.Implementations.Activity private readonly IUserManager _userManager; private readonly IServerConfigurationManager _config; private readonly IServerApplicationHost _appHost; + private readonly IDeviceManager _deviceManager; - public ActivityLogEntryPoint(ISessionManager sessionManager, ITaskManager taskManager, IActivityManager activityManager, ILocalizationManager localization, IInstallationManager installationManager, ILibraryManager libraryManager, ISubtitleManager subManager, IUserManager userManager, IServerConfigurationManager config, IServerApplicationHost appHost) + public ActivityLogEntryPoint(ISessionManager sessionManager, IDeviceManager deviceManager, ITaskManager taskManager, IActivityManager activityManager, ILocalizationManager localization, IInstallationManager installationManager, ILibraryManager libraryManager, ISubtitleManager subManager, IUserManager userManager, IServerConfigurationManager config, IServerApplicationHost appHost) { - //_logger = _logManager.GetLogger("ActivityLogEntryPoint"); _sessionManager = sessionManager; _taskManager = taskManager; _activityManager = activityManager; @@ -51,21 +55,18 @@ namespace Emby.Server.Implementations.Activity _subManager = subManager; _userManager = userManager; _config = config; - //_logManager = logManager; _appHost = appHost; + _deviceManager = deviceManager; } public void Run() { - //_taskManager.TaskExecuting += _taskManager_TaskExecuting; - //_taskManager.TaskCompleted += _taskManager_TaskCompleted; + _taskManager.TaskCompleted += _taskManager_TaskCompleted; - //_installationManager.PluginInstalled += _installationManager_PluginInstalled; - //_installationManager.PluginUninstalled += _installationManager_PluginUninstalled; - //_installationManager.PluginUpdated += _installationManager_PluginUpdated; - - //_libraryManager.ItemAdded += _libraryManager_ItemAdded; - //_libraryManager.ItemRemoved += _libraryManager_ItemRemoved; + _installationManager.PluginInstalled += _installationManager_PluginInstalled; + _installationManager.PluginUninstalled += _installationManager_PluginUninstalled; + _installationManager.PluginUpdated += _installationManager_PluginUpdated; + _installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed; _sessionManager.SessionStarted += _sessionManager_SessionStarted; _sessionManager.AuthenticationFailed += _sessionManager_AuthenticationFailed; @@ -81,24 +82,33 @@ namespace Emby.Server.Implementations.Activity _userManager.UserCreated += _userManager_UserCreated; _userManager.UserPasswordChanged += _userManager_UserPasswordChanged; _userManager.UserDeleted += _userManager_UserDeleted; - _userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated; + _userManager.UserPolicyUpdated += _userManager_UserPolicyUpdated; _userManager.UserLockedOut += _userManager_UserLockedOut; //_config.ConfigurationUpdated += _config_ConfigurationUpdated; //_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated; - //_logManager.LoggerLoaded += _logManager_LoggerLoaded; + _deviceManager.CameraImageUploaded += _deviceManager_CameraImageUploaded; _appHost.ApplicationUpdated += _appHost_ApplicationUpdated; } + void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e) + { + CreateLogEntry(new ActivityLogEntry + { + Name = string.Format(_localization.GetLocalizedString("CameraImageUploadedFrom"), e.Argument.Device.Name), + Type = NotificationType.CameraImageUploaded.ToString() + }); + } + void _userManager_UserLockedOut(object sender, GenericEventArgs<User> e) { CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserLockedOutWithName"), e.Argument.Name), - Type = "UserLockedOut", - UserId = e.Argument.Id.ToString("N") + Type = NotificationType.UserLockedOut.ToString(), + UserId = e.Argument.Id }); } @@ -106,11 +116,10 @@ namespace Emby.Server.Implementations.Activity { CreateLogEntry(new ActivityLogEntry { - Name = string.Format(_localization.GetLocalizedString("SubtitleDownloadFailureForItem"), Notifications.Notifications.GetItemName(e.Item)), + Name = string.Format(_localization.GetLocalizedString("SubtitleDownloadFailureFromForItem"), e.Provider, Notifications.Notifications.GetItemName(e.Item)), Type = "SubtitleDownloadFailure", ItemId = e.Item.Id.ToString("N"), - ShortOverview = string.Format(_localization.GetLocalizedString("ProviderValue"), e.Provider), - Overview = LogHelper.GetLogMessage(e.Exception).ToString() + ShortOverview = e.Exception.Message }); } @@ -139,10 +148,9 @@ namespace Emby.Server.Implementations.Activity CreateLogEntry(new ActivityLogEntry { - Name = string.Format(_localization.GetLocalizedString("UserStoppedPlayingItemWithValues"), user.Name, Notifications.Notifications.GetItemName(item)), - Type = "PlaybackStopped", - ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), e.ClientName, e.DeviceName), - UserId = user.Id.ToString("N") + Name = string.Format(_localization.GetLocalizedString("UserStoppedPlayingItemWithValues"), user.Name, GetItemName(item), e.DeviceName), + Type = GetPlaybackStoppedNotificationType(item.MediaType), + UserId = user.Id }); } @@ -171,19 +179,71 @@ namespace Emby.Server.Implementations.Activity CreateLogEntry(new ActivityLogEntry { - Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), user.Name, Notifications.Notifications.GetItemName(item)), - Type = "PlaybackStart", - ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), e.ClientName, e.DeviceName), - UserId = user.Id.ToString("N") + Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), user.Name, GetItemName(item), e.DeviceName), + Type = GetPlaybackNotificationType(item.MediaType), + UserId = user.Id }); } + private static string GetItemName(BaseItemDto item) + { + var name = item.Name; + + if (!string.IsNullOrEmpty(item.SeriesName)) + { + name = item.SeriesName + " - " + name; + } + + if (item.Artists != null && item.Artists.Length > 0) + { + name = item.Artists[0] + " - " + name; + } + + return name; + } + + private string GetPlaybackNotificationType(string mediaType) + { + if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.AudioPlayback.ToString(); + } + if (string.Equals(mediaType, MediaType.Game, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.GamePlayback.ToString(); + } + if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.VideoPlayback.ToString(); + } + + return null; + } + + private string GetPlaybackStoppedNotificationType(string mediaType) + { + if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.AudioPlaybackStopped.ToString(); + } + if (string.Equals(mediaType, MediaType.Game, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.GamePlaybackStopped.ToString(); + } + if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) + { + return NotificationType.VideoPlaybackStopped.ToString(); + } + + return null; + } + void _sessionManager_SessionEnded(object sender, SessionEventArgs e) { string name; var session = e.SessionInfo; - if (string.IsNullOrWhiteSpace(session.UserName)) + if (string.IsNullOrEmpty(session.UserName)) { name = string.Format(_localization.GetLocalizedString("DeviceOfflineWithName"), session.DeviceName); @@ -200,17 +260,20 @@ namespace Emby.Server.Implementations.Activity Name = name, Type = "SessionEnded", ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), session.RemoteEndPoint), - UserId = session.UserId.HasValue ? session.UserId.Value.ToString("N") : null + UserId = session.UserId }); } - void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationRequest> e) + void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e) { + var user = e.Argument.User; + CreateLogEntry(new ActivityLogEntry { - Name = string.Format(_localization.GetLocalizedString("AuthenticationSucceededWithUserName"), e.Argument.Username), + Name = string.Format(_localization.GetLocalizedString("AuthenticationSucceededWithUserName"), user.Name), Type = "AuthenticationSucceeded", - ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), e.Argument.RemoteEndPoint) + ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), e.Argument.SessionInfo.RemoteEndPoint), + UserId = user.Id }); } @@ -229,9 +292,8 @@ namespace Emby.Server.Implementations.Activity { CreateLogEntry(new ActivityLogEntry { - Name = _localization.GetLocalizedString("MessageApplicationUpdated"), - Type = "ApplicationUpdated", - ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), e.Argument.versionStr), + Name = string.Format(_localization.GetLocalizedString("MessageApplicationUpdatedTo"), e.Argument.versionStr), + Type = NotificationType.ApplicationUpdateInstalled.ToString(), Overview = e.Argument.description }); } @@ -254,13 +316,13 @@ namespace Emby.Server.Implementations.Activity }); } - void _userManager_UserConfigurationUpdated(object sender, GenericEventArgs<User> e) + void _userManager_UserPolicyUpdated(object sender, GenericEventArgs<User> e) { CreateLogEntry(new ActivityLogEntry { - Name = string.Format(_localization.GetLocalizedString("UserConfigurationUpdatedWithName"), e.Argument.Name), - Type = "UserConfigurationUpdated", - UserId = e.Argument.Id.ToString("N") + Name = string.Format(_localization.GetLocalizedString("UserPolicyUpdatedWithName"), e.Argument.Name), + Type = "UserPolicyUpdated", + UserId = e.Argument.Id }); } @@ -279,7 +341,7 @@ namespace Emby.Server.Implementations.Activity { Name = string.Format(_localization.GetLocalizedString("UserPasswordChangedWithName"), e.Argument.Name), Type = "UserPasswordChanged", - UserId = e.Argument.Id.ToString("N") + UserId = e.Argument.Id }); } @@ -289,7 +351,7 @@ namespace Emby.Server.Implementations.Activity { Name = string.Format(_localization.GetLocalizedString("UserCreatedWithName"), e.Argument.Name), Type = "UserCreated", - UserId = e.Argument.Id.ToString("N") + UserId = e.Argument.Id }); } @@ -309,7 +371,7 @@ namespace Emby.Server.Implementations.Activity string name; var session = e.SessionInfo; - if (string.IsNullOrWhiteSpace(session.UserName)) + if (string.IsNullOrEmpty(session.UserName)) { name = string.Format(_localization.GetLocalizedString("DeviceOnlineWithName"), session.DeviceName); @@ -326,36 +388,7 @@ namespace Emby.Server.Implementations.Activity Name = name, Type = "SessionStarted", ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), session.RemoteEndPoint), - UserId = session.UserId.HasValue ? session.UserId.Value.ToString("N") : null - }); - } - - void _libraryManager_ItemRemoved(object sender, ItemChangeEventArgs e) - { - if (e.Item.SourceType != SourceType.Library) - { - return; - } - - CreateLogEntry(new ActivityLogEntry - { - Name = string.Format(_localization.GetLocalizedString("ItemRemovedWithName"), Notifications.Notifications.GetItemName(e.Item)), - Type = "ItemRemoved" - }); - } - - void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) - { - if (e.Item.SourceType != SourceType.Library) - { - return; - } - - CreateLogEntry(new ActivityLogEntry - { - Name = string.Format(_localization.GetLocalizedString("ItemAddedWithName"), Notifications.Notifications.GetItemName(e.Item)), - Type = "ItemAdded", - ItemId = e.Item.Id.ToString("N") + UserId = session.UserId }); } @@ -364,7 +397,7 @@ namespace Emby.Server.Implementations.Activity CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("PluginUpdatedWithName"), e.Argument.Item1.Name), - Type = "PluginUpdated", + Type = NotificationType.PluginUpdateInstalled.ToString(), ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), e.Argument.Item2.versionStr), Overview = e.Argument.Item2.description }); @@ -375,7 +408,7 @@ namespace Emby.Server.Implementations.Activity CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("PluginUninstalledWithName"), e.Argument.Name), - Type = "PluginUninstalled" + Type = NotificationType.PluginUninstalled.ToString() }); } @@ -384,25 +417,21 @@ namespace Emby.Server.Implementations.Activity CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("PluginInstalledWithName"), e.Argument.name), - Type = "PluginInstalled", + Type = NotificationType.PluginInstalled.ToString(), ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), e.Argument.versionStr) }); } - void _taskManager_TaskExecuting(object sender, GenericEventArgs<IScheduledTaskWorker> e) + void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e) { - var task = e.Argument; - - var activityTask = task.ScheduledTask as IConfigurableScheduledTask; - if (activityTask != null && !activityTask.IsLogged) - { - return; - } + var installationInfo = e.InstallationInfo; CreateLogEntry(new ActivityLogEntry { - Name = string.Format(_localization.GetLocalizedString("ScheduledTaskStartedWithName"), task.Name), - Type = "ScheduledTaskStarted" + Name = string.Format(_localization.GetLocalizedString("NameInstallFailed"), installationInfo.Name), + Type = NotificationType.InstallationFailed.ToString(), + ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), installationInfo.Version), + Overview = e.Exception.Message }); } @@ -424,11 +453,11 @@ namespace Emby.Server.Implementations.Activity { var vals = new List<string>(); - if (!string.IsNullOrWhiteSpace(e.Result.ErrorMessage)) + if (!string.IsNullOrEmpty(e.Result.ErrorMessage)) { vals.Add(e.Result.ErrorMessage); } - if (!string.IsNullOrWhiteSpace(e.Result.LongErrorMessage)) + if (!string.IsNullOrEmpty(e.Result.LongErrorMessage)) { vals.Add(e.Result.LongErrorMessage); } @@ -436,7 +465,7 @@ namespace Emby.Server.Implementations.Activity CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("ScheduledTaskFailedWithName"), task.Name), - Type = "ScheduledTaskFailed", + Type = NotificationType.TaskFailed.ToString(), Overview = string.Join(Environment.NewLine, vals.ToArray(vals.Count)), ShortOverview = runningTime, Severity = LogSeverity.Error @@ -458,15 +487,12 @@ namespace Emby.Server.Implementations.Activity public void Dispose() { - _taskManager.TaskExecuting -= _taskManager_TaskExecuting; _taskManager.TaskCompleted -= _taskManager_TaskCompleted; _installationManager.PluginInstalled -= _installationManager_PluginInstalled; _installationManager.PluginUninstalled -= _installationManager_PluginUninstalled; _installationManager.PluginUpdated -= _installationManager_PluginUpdated; - - _libraryManager.ItemAdded -= _libraryManager_ItemAdded; - _libraryManager.ItemRemoved -= _libraryManager_ItemRemoved; + _installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed; _sessionManager.SessionStarted -= _sessionManager_SessionStarted; _sessionManager.AuthenticationFailed -= _sessionManager_AuthenticationFailed; @@ -482,16 +508,15 @@ namespace Emby.Server.Implementations.Activity _userManager.UserCreated -= _userManager_UserCreated; _userManager.UserPasswordChanged -= _userManager_UserPasswordChanged; _userManager.UserDeleted -= _userManager_UserDeleted; - _userManager.UserConfigurationUpdated -= _userManager_UserConfigurationUpdated; + _userManager.UserPolicyUpdated -= _userManager_UserPolicyUpdated; _userManager.UserLockedOut -= _userManager_UserLockedOut; _config.ConfigurationUpdated -= _config_ConfigurationUpdated; _config.NamedConfigurationUpdated -= _config_NamedConfigurationUpdated; - //_logManager.LoggerLoaded -= _logManager_LoggerLoaded; + _deviceManager.CameraImageUploaded -= _deviceManager_CameraImageUploaded; _appHost.ApplicationUpdated -= _appHost_ApplicationUpdated; - GC.SuppressFinalize(this); } /// <summary> |
