From 391b48614d598b5fbfad68b610520a5ae7a57b70 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 28 Dec 2018 15:21:02 +0100 Subject: [PATCH] Remove FireEventIfNotNull It's a pretty useless "helper" class --- Emby.Dlna/Ssdp/DeviceDiscovery.cs | 4 +- .../Activity/ActivityManager.cs | 2 +- .../AppBase/BaseConfigurationManager.cs | 10 ++-- .../ApplicationHost.cs | 7 ++- .../Collections/CollectionManager.cs | 15 +++--- .../ServerConfigurationManager.cs | 2 +- .../Devices/DeviceManager.cs | 4 +- .../HttpServer/HttpListenerHost.cs | 2 +- .../HttpServer/WebSocketConnection.cs | 2 +- .../IO/FileRefresher.cs | 2 +- .../Library/UserDataManager.cs | 5 +- .../Library/UserManager.cs | 17 +++---- .../LiveTv/EmbyTV/TimerManager.cs | 4 +- .../LiveTv/LiveTvManager.cs | 24 +++++----- .../ScheduledTasks/ScheduledTaskWorker.cs | 5 +- .../ScheduledTasks/TaskManager.cs | 10 ++-- .../Session/SessionManager.cs | 19 ++++---- .../Updates/InstallationManager.cs | 17 ++++--- Jellyfin.Server/SocketSharp/SharpWebSocket.cs | 6 +-- MediaBrowser.Common/Events/EventHelper.cs | 46 +------------------ .../Subtitles/SubtitleManager.cs | 5 +- 21 files changed, 73 insertions(+), 135 deletions(-) diff --git a/Emby.Dlna/Ssdp/DeviceDiscovery.cs b/Emby.Dlna/Ssdp/DeviceDiscovery.cs index 85dc4d94f..d91f711d2 100644 --- a/Emby.Dlna/Ssdp/DeviceDiscovery.cs +++ b/Emby.Dlna/Ssdp/DeviceDiscovery.cs @@ -119,7 +119,7 @@ namespace Emby.Dlna.Ssdp } }; - EventHelper.FireEventIfNotNull(DeviceDiscoveredInternal, this, args, _logger); + DeviceDiscoveredInternal?.Invoke(this, args); } private void _DeviceLocator_DeviceUnavailable(object sender, DeviceUnavailableEventArgs e) @@ -139,7 +139,7 @@ namespace Emby.Dlna.Ssdp } }; - EventHelper.FireEventIfNotNull(DeviceLeft, this, args, _logger); + DeviceLeft?.Invoke(this, args); } public void Dispose() diff --git a/Emby.Server.Implementations/Activity/ActivityManager.cs b/Emby.Server.Implementations/Activity/ActivityManager.cs index b0c841397..a67e475e2 100644 --- a/Emby.Server.Implementations/Activity/ActivityManager.cs +++ b/Emby.Server.Implementations/Activity/ActivityManager.cs @@ -30,7 +30,7 @@ namespace Emby.Server.Implementations.Activity _repo.Create(entry); - EventHelper.FireEventIfNotNull(EntryCreated, this, new GenericEventArgs(entry), _logger); + EntryCreated?.Invoke(this, new GenericEventArgs(entry)); } public QueryResult GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit) diff --git a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs index fddf19893..bc5168fe8 100644 --- a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs +++ b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs @@ -283,12 +283,11 @@ namespace Emby.Server.Implementations.AppBase validatingStore.Validate(currentConfiguration, configuration); } - EventHelper.FireEventIfNotNull(NamedConfigurationUpdating, this, new ConfigurationUpdateEventArgs + NamedConfigurationUpdating?.Invoke( this, new ConfigurationUpdateEventArgs { Key = key, NewConfiguration = configuration - - }, Logger); + }); _configurations.AddOrUpdate(key, configuration, (k, v) => configuration); @@ -305,12 +304,11 @@ namespace Emby.Server.Implementations.AppBase protected virtual void OnNamedConfigurationUpdated(string key, object configuration) { - EventHelper.FireEventIfNotNull(NamedConfigurationUpdated, this, new ConfigurationUpdateEventArgs + NamedConfigurationUpdated?.Invoke(this, new ConfigurationUpdateEventArgs { Key = key, NewConfiguration = configuration - - }, Logger); + }); } public Type GetConfigurationType(string key) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 80e9b6b50..236851968 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -2265,7 +2265,7 @@ namespace Emby.Server.Implementations if (fireEvent) { - EventHelper.FireEventIfNotNull(HasUpdateAvailableChanged, this, EventArgs.Empty, Logger); + HasUpdateAvailableChanged?.Invoke(this, EventArgs.Empty); } } } @@ -2381,11 +2381,10 @@ namespace Emby.Server.Implementations { Logger.LogInformation("Application has been updated to version {0}", package.versionStr); - EventHelper.FireEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs + ApplicationUpdated?.Invoke(this, new GenericEventArgs { Argument = package - - }, Logger); + }); NotifyPendingRestart(); } diff --git a/Emby.Server.Implementations/Collections/CollectionManager.cs b/Emby.Server.Implementations/Collections/CollectionManager.cs index d1afb0712..d1d793136 100644 --- a/Emby.Server.Implementations/Collections/CollectionManager.cs +++ b/Emby.Server.Implementations/Collections/CollectionManager.cs @@ -155,12 +155,11 @@ namespace Emby.Server.Implementations.Collections _providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), RefreshPriority.High); } - EventHelper.FireEventIfNotNull(CollectionCreated, this, new CollectionCreatedEventArgs + CollectionCreated?.Invoke(this, new CollectionCreatedEventArgs { Collection = collection, Options = options - - }, _logger); + }); return collection; } @@ -230,12 +229,11 @@ namespace Emby.Server.Implementations.Collections if (fireEvent) { - EventHelper.FireEventIfNotNull(ItemsAddedToCollection, this, new CollectionModifiedEventArgs + ItemsAddedToCollection?.Invoke(this, new CollectionModifiedEventArgs { Collection = collection, ItemsChanged = itemList - - }, _logger); + }); } } } @@ -288,12 +286,11 @@ namespace Emby.Server.Implementations.Collections ForceSave = true }, RefreshPriority.High); - EventHelper.FireEventIfNotNull(ItemsRemovedFromCollection, this, new CollectionModifiedEventArgs + ItemsRemovedFromCollection?.Invoke(this, new CollectionModifiedEventArgs { Collection = collection, ItemsChanged = itemList - - }, _logger); + }); } public IEnumerable CollapseItemsWithinBoxSets(IEnumerable items, User user) diff --git a/Emby.Server.Implementations/Configuration/ServerConfigurationManager.cs b/Emby.Server.Implementations/Configuration/ServerConfigurationManager.cs index 26a7c421f..80a17a784 100644 --- a/Emby.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/Emby.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -143,7 +143,7 @@ namespace Emby.Server.Implementations.Configuration ValidateMetadataPath(newConfig); ValidateSslCertificate(newConfig); - EventHelper.FireEventIfNotNull(ConfigurationUpdating, this, new GenericEventArgs { Argument = newConfig }, Logger); + ConfigurationUpdating?.Invoke(this, new GenericEventArgs { Argument = newConfig }); base.ReplaceConfiguration(newConfiguration); } diff --git a/Emby.Server.Implementations/Devices/DeviceManager.cs b/Emby.Server.Implementations/Devices/DeviceManager.cs index 82df96d8b..f73521d0a 100644 --- a/Emby.Server.Implementations/Devices/DeviceManager.cs +++ b/Emby.Server.Implementations/Devices/DeviceManager.cs @@ -254,14 +254,14 @@ namespace Emby.Server.Implementations.Devices if (CameraImageUploaded != null) { - EventHelper.FireEventIfNotNull(CameraImageUploaded, this, new GenericEventArgs + CameraImageUploaded?.Invoke(this, new GenericEventArgs { Argument = new CameraImageUploadInfo { Device = device, FileInfo = file } - }, _logger); + }); } } diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 704b7f8a6..66b930a80 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -184,7 +184,7 @@ namespace Emby.Server.Implementations.HttpServer if (WebSocketConnected != null) { - EventHelper.FireEventIfNotNull(WebSocketConnected, this, new GenericEventArgs(connection), _logger); + WebSocketConnected?.Invoke(this, new GenericEventArgs(connection)); } } diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs index 8b5dfd444..095675ec4 100644 --- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs +++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs @@ -118,7 +118,7 @@ namespace Emby.Server.Implementations.HttpServer void socket_Closed(object sender, EventArgs e) { - EventHelper.FireEventIfNotNull(Closed, this, EventArgs.Empty, _logger); + Closed?.Invoke(this, EventArgs.Empty); } /// diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs index df484d04c..8c2a937a0 100644 --- a/Emby.Server.Implementations/IO/FileRefresher.cs +++ b/Emby.Server.Implementations/IO/FileRefresher.cs @@ -133,7 +133,7 @@ namespace Emby.Server.Implementations.IO Logger.LogDebug("Timer stopped."); DisposeTimer(); - EventHelper.FireEventIfNotNull(Completed, this, EventArgs.Empty, Logger); + Completed?.Invoke(this, EventArgs.Empty); try { diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs index 62371799b..d4e94244b 100644 --- a/Emby.Server.Implementations/Library/UserDataManager.cs +++ b/Emby.Server.Implementations/Library/UserDataManager.cs @@ -77,15 +77,14 @@ namespace Emby.Server.Implementations.Library var cacheKey = GetCacheKey(userId, item.Id); _userData.AddOrUpdate(cacheKey, userData, (k, v) => userData); - EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs + UserDataSaved?.Invoke(this, new UserDataSaveEventArgs { Keys = keys, UserData = userData, SaveReason = reason, UserId = user.Id, Item = item - - }, _logger); + }); } /// diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs index ed1fe8791..679116fc0 100644 --- a/Emby.Server.Implementations/Library/UserManager.cs +++ b/Emby.Server.Implementations/Library/UserManager.cs @@ -134,7 +134,7 @@ namespace Emby.Server.Implementations.Library /// The user. private void OnUserUpdated(User user) { - EventHelper.FireEventIfNotNull(UserUpdated, this, new GenericEventArgs { Argument = user }, _logger); + UserUpdated?.Invoke(this, new GenericEventArgs { Argument = user }); } #endregion @@ -149,7 +149,7 @@ namespace Emby.Server.Implementations.Library /// The user. private void OnUserDeleted(User user) { - EventHelper.FireEventIfNotNull(UserDeleted, this, new GenericEventArgs { Argument = user }, _logger); + UserDeleted?.Invoke(this, new GenericEventArgs { Argument = user }); } #endregion @@ -470,10 +470,7 @@ namespace Emby.Server.Implementations.Library if (fireLockout) { - if (UserLockedOut != null) - { - EventHelper.FireEventIfNotNull(UserLockedOut, this, new GenericEventArgs(user), _logger); - } + UserLockedOut?.Invoke(this, new GenericEventArgs(user)); } } } @@ -819,7 +816,7 @@ namespace Emby.Server.Implementations.Library UpdateUser(user); - EventHelper.FireEventIfNotNull(UserPasswordChanged, this, new GenericEventArgs(user), _logger); + UserPasswordChanged?.Invoke(this, new GenericEventArgs(user)); } public void ChangeEasyPassword(User user, string newPassword, string newPasswordHash) @@ -843,7 +840,7 @@ namespace Emby.Server.Implementations.Library UpdateUser(user); - EventHelper.FireEventIfNotNull(UserPasswordChanged, this, new GenericEventArgs(user), _logger); + UserPasswordChanged?.Invoke(this, new GenericEventArgs(user)); } /// @@ -1087,7 +1084,7 @@ namespace Emby.Server.Implementations.Library if (fireEvent) { - EventHelper.FireEventIfNotNull(UserPolicyUpdated, this, new GenericEventArgs { Argument = user }, _logger); + UserPolicyUpdated?.Invoke(this, new GenericEventArgs { Argument = user }); } } @@ -1182,7 +1179,7 @@ namespace Emby.Server.Implementations.Library if (fireEvent) { - EventHelper.FireEventIfNotNull(UserConfigurationUpdated, this, new GenericEventArgs { Argument = user }, _logger); + UserConfigurationUpdated?.Invoke(this, new GenericEventArgs { Argument = user }); } } } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs index 5618579f6..7c705c70b 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs @@ -122,7 +122,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV if (startDate < now) { - EventHelper.FireEventIfNotNull(TimerFired, this, new GenericEventArgs { Argument = item }, base.Logger); + TimerFired?.Invoke(this, new GenericEventArgs { Argument = item }); return; } @@ -178,7 +178,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV var timer = GetAll().FirstOrDefault(i => string.Equals(i.Id, timerId, StringComparison.OrdinalIgnoreCase)); if (timer != null) { - EventHelper.FireEventIfNotNull(TimerFired, this, new GenericEventArgs { Argument = timer }, base.Logger); + TimerFired?.Invoke(this, new GenericEventArgs { Argument = timer }); } } diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index a4ffbd2fe..5e6c17413 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -144,13 +144,13 @@ namespace Emby.Server.Implementations.LiveTv { var timerId = e.Argument; - EventHelper.FireEventIfNotNull(TimerCancelled, this, new GenericEventArgs + TimerCancelled?.Invoke(this, new GenericEventArgs { Argument = new TimerEventInfo { Id = timerId } - }, _logger); + }); } private void EmbyTv_TimerCreated(object sender, GenericEventArgs e) @@ -158,14 +158,14 @@ namespace Emby.Server.Implementations.LiveTv var timer = e.Argument; var service = sender as ILiveTvService; - EventHelper.FireEventIfNotNull(TimerCreated, this, new GenericEventArgs + TimerCreated?.Invoke(this, new GenericEventArgs { Argument = new TimerEventInfo { ProgramId = _tvDtoService.GetInternalProgramId(timer.ProgramId), Id = timer.Id } - }, _logger); + }); } public ITunerHost[] TunerHosts @@ -1734,13 +1734,13 @@ namespace Emby.Server.Implementations.LiveTv if (!(service is EmbyTV.EmbyTV)) { - EventHelper.FireEventIfNotNull(TimerCancelled, this, new GenericEventArgs + TimerCancelled?.Invoke(this, new GenericEventArgs { Argument = new TimerEventInfo { Id = id } - }, _logger); + }); } } @@ -1757,13 +1757,13 @@ namespace Emby.Server.Implementations.LiveTv await service.CancelSeriesTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false); - EventHelper.FireEventIfNotNull(SeriesTimerCancelled, this, new GenericEventArgs + SeriesTimerCancelled?.Invoke(this, new GenericEventArgs { Argument = new TimerEventInfo { Id = id } - }, _logger); + }); } public async Task GetTimer(string id, CancellationToken cancellationToken) @@ -2083,14 +2083,14 @@ namespace Emby.Server.Implementations.LiveTv if (!(service is EmbyTV.EmbyTV)) { - EventHelper.FireEventIfNotNull(TimerCreated, this, new GenericEventArgs + TimerCreated?.Invoke(this, new GenericEventArgs { Argument = new TimerEventInfo { ProgramId = _tvDtoService.GetInternalProgramId(info.ProgramId), Id = newTimerId } - }, _logger); + }); } } @@ -2123,14 +2123,14 @@ namespace Emby.Server.Implementations.LiveTv await service.CreateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false); } - EventHelper.FireEventIfNotNull(SeriesTimerCreated, this, new GenericEventArgs + SeriesTimerCreated?.Invoke(this, new GenericEventArgs { Argument = new TimerEventInfo { ProgramId = _tvDtoService.GetInternalProgramId(info.ProgramId), Id = newTimerId } - }, _logger); + }); } public async Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken) diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 7c2ce4af3..c7b43cf57 100644 --- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -465,11 +465,10 @@ namespace Emby.Server.Implementations.ScheduledTasks CurrentProgress = e; - EventHelper.FireEventIfNotNull(TaskProgress, this, new GenericEventArgs + TaskProgress?.Invoke(this, new GenericEventArgs { Argument = e - - }, Logger); + }); } /// diff --git a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs index 0322583dc..c4b6e92e3 100644 --- a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs +++ b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs @@ -331,11 +331,10 @@ namespace Emby.Server.Implementations.ScheduledTasks /// The task. internal void OnTaskExecuting(IScheduledTaskWorker task) { - EventHelper.FireEventIfNotNull(TaskExecuting, this, new GenericEventArgs + TaskExecuting?.Invoke(this, new GenericEventArgs { Argument = task - - }, Logger); + }); } /// @@ -345,12 +344,11 @@ namespace Emby.Server.Implementations.ScheduledTasks /// The result. internal void OnTaskCompleted(IScheduledTaskWorker task, TaskResult result) { - EventHelper.FireEventIfNotNull(TaskCompleted, task, new TaskCompletionEventArgs + TaskCompleted?.Invoke(task, new TaskCompletionEventArgs { Result = result, Task = task - - }, Logger); + }); ExecuteQueuedTasks(); } diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 2b2b3c677..eeb15b305 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -255,11 +255,10 @@ namespace Emby.Server.Implementations.Session if ((activityDate - lastActivityDate).TotalSeconds > 10) { - EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs + SessionActivity?.Invoke(this, new SessionEventArgs { SessionInfo = session - - }, _logger); + }); } return session; @@ -693,7 +692,7 @@ namespace Emby.Server.Implementations.Session } } - EventHelper.FireEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs + PlaybackProgress?.Invoke(this, new PlaybackProgressEventArgs { Item = libraryItem, Users = users, @@ -707,8 +706,7 @@ namespace Emby.Server.Implementations.Session PlaySessionId = info.PlaySessionId, IsAutomated = isAutomated, Session = session - - }, _logger); + }); if (!isAutomated) { @@ -1399,7 +1397,7 @@ namespace Emby.Server.Implementations.Session if (result == null) { - EventHelper.FireEventIfNotNull(AuthenticationFailed, this, new GenericEventArgs(request), _logger); + AuthenticationFailed?.Invoke(this, new GenericEventArgs(request)); throw new SecurityException("Invalid user or password entered."); } @@ -1424,7 +1422,7 @@ namespace Emby.Server.Implementations.Session ServerId = _appHost.SystemId }; - EventHelper.FireEventIfNotNull(AuthenticationSucceeded, this, new GenericEventArgs(returnResult), _logger); + AuthenticationSucceeded?.Invoke(this, new GenericEventArgs(returnResult)); return returnResult; } @@ -1587,11 +1585,10 @@ namespace Emby.Server.Implementations.Session if (saveCapabilities) { - EventHelper.FireEventIfNotNull(CapabilitiesChanged, this, new SessionEventArgs + CapabilitiesChanged?.Invoke(this, new SessionEventArgs { SessionInfo = session - - }, _logger); + }); try { diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 27741863b..bf47b63ea 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -60,7 +60,7 @@ namespace Emby.Server.Implementations.Updates /// The plugin. private void OnPluginUninstalled(IPlugin plugin) { - EventHelper.FireEventIfNotNull(PluginUninstalled, this, new GenericEventArgs { Argument = plugin }, _logger); + PluginUninstalled?.Invoke(this, new GenericEventArgs { Argument = plugin }); } #endregion @@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Updates { _logger.LogInformation("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.versionStr ?? string.Empty, newVersion.classification); - EventHelper.FireEventIfNotNull(PluginUpdated, this, new GenericEventArgs> { Argument = new Tuple(plugin, newVersion) }, _logger); + PluginUpdated?.Invoke(this, new GenericEventArgs> { Argument = new Tuple(plugin, newVersion) }); _applicationHost.NotifyPendingRestart(); } @@ -97,7 +97,7 @@ namespace Emby.Server.Implementations.Updates { _logger.LogInformation("New plugin installed: {0} {1} {2}", package.name, package.versionStr ?? string.Empty, package.classification); - EventHelper.FireEventIfNotNull(PluginInstalled, this, new GenericEventArgs { Argument = package }, _logger); + PluginInstalled?.Invoke(this, new GenericEventArgs { Argument = package }); _applicationHost.NotifyPendingRestart(); } @@ -469,7 +469,7 @@ namespace Emby.Server.Implementations.Updates PackageVersionInfo = package }; - EventHelper.FireEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger); + PackageInstalling?.Invoke(this, installationEventArgs); try { @@ -482,7 +482,7 @@ namespace Emby.Server.Implementations.Updates CompletedInstallationsInternal.Add(installationInfo); - EventHelper.FireEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger); + PackageInstallationCompleted?.Invoke(this, installationEventArgs); } catch (OperationCanceledException) { @@ -493,7 +493,7 @@ namespace Emby.Server.Implementations.Updates _logger.LogInformation("Package installation cancelled: {0} {1}", package.name, package.versionStr); - EventHelper.FireEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger); + PackageInstallationCancelled?.Invoke(this, installationEventArgs); throw; } @@ -506,12 +506,11 @@ namespace Emby.Server.Implementations.Updates CurrentInstallations.Remove(tuple); } - EventHelper.FireEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs + PackageInstallationFailed?.Invoke(this, new InstallationFailedEventArgs { InstallationInfo = installationInfo, Exception = ex - - }, _logger); + }); throw; } diff --git a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs index 1c72035a5..056dabd17 100644 --- a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs +++ b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs @@ -55,15 +55,15 @@ namespace Jellyfin.SocketSharp void socket_OnError(object sender, SocketHttpListener.ErrorEventArgs e) { - _logger.LogError("Error in SharpWebSocket: {0}", e.Message ?? string.Empty); - //EventHelper.FireEventIfNotNull(Closed, this, EventArgs.Empty, _logger); + _logger.LogError("Error in SharpWebSocket: {Message}", e.Message ?? string.Empty); + //Closed?.Invoke(this, EventArgs.Empty); } void socket_OnClose(object sender, SocketHttpListener.CloseEventArgs e) { _taskCompletionSource.TrySetResult(true); - EventHelper.FireEventIfNotNull(Closed, this, EventArgs.Empty, _logger); + Closed?.Invoke(this, EventArgs.Empty); } void socket_OnMessage(object sender, SocketHttpListener.MessageEventArgs e) diff --git a/MediaBrowser.Common/Events/EventHelper.cs b/MediaBrowser.Common/Events/EventHelper.cs index 04a2270e3..2630ce7da 100644 --- a/MediaBrowser.Common/Events/EventHelper.cs +++ b/MediaBrowser.Common/Events/EventHelper.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Common.Events { + // TODO: @bond Remove /// /// Class EventHelper /// @@ -59,50 +60,5 @@ namespace MediaBrowser.Common.Events }); } } - - /// - /// Fires the event. - /// - /// The handler. - /// The sender. - /// The instance containing the event data. - /// The logger. - public static void FireEventIfNotNull(EventHandler handler, object sender, EventArgs args, ILogger logger) - { - if (handler != null) - { - try - { - handler(sender, args); - } - catch (Exception ex) - { - logger.LogError(ex, "Error in event handler"); - } - } - } - - /// - /// Fires the event. - /// - /// - /// The handler. - /// The sender. - /// The args. - /// The logger. - public static void FireEventIfNotNull(EventHandler handler, object sender, T args, ILogger logger) - { - if (handler != null) - { - try - { - handler(sender, args); - } - catch (Exception ex) - { - logger.LogError(ex, "Error in event handler"); - } - } - } } } diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs index 2cf737511..4f08d2150 100644 --- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs +++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs @@ -189,13 +189,12 @@ namespace MediaBrowser.Providers.Subtitles } catch (Exception ex) { - EventHelper.FireEventIfNotNull(SubtitleDownloadFailure, this, new SubtitleDownloadFailureEventArgs + SubtitleDownloadFailure?.Invoke(this, new SubtitleDownloadFailureEventArgs { Item = video, Exception = ex, Provider = provider.Name - - }, _logger); + }); throw; }