The Free Software Media System - Server Backend & API
Migrate ActivityLogEntryPoint.OnSessionStarted to IEventConsumer
Patrick Barronca3a8bdb98ae
diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.csindex 00a14fb0bd..d863acd0b4 100644--- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs+++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs@@ -36,7 +36,6 @@ namespace Emby.Server.Implementations.Activity/// <inheritdoc />public Task RunAsync(){- _sessionManager.SessionStarted += OnSessionStarted;_sessionManager.SessionEnded += OnSessionEnded;return Task.CompletedTask;@@ -67,38 +66,12 @@ namespace Emby.Server.Implementations.Activity}).ConfigureAwait(false);}- private async void OnSessionStarted(object sender, SessionEventArgs e)- {- var session = e.SessionInfo;-- if (string.IsNullOrEmpty(session.UserName))- {- return;- }-- await CreateLogEntry(new ActivityLog(- string.Format(- CultureInfo.InvariantCulture,- _localization.GetLocalizedString("UserOnlineFromDevice"),- session.UserName,- session.DeviceName),- "SessionStarted",- session.UserId)- {- ShortOverview = string.Format(- CultureInfo.InvariantCulture,- _localization.GetLocalizedString("LabelIpAddressValue"),- session.RemoteEndPoint)- }).ConfigureAwait(false);- }-private async Task CreateLogEntry(ActivityLog entry)=> await _activityManager.CreateAsync(entry).ConfigureAwait(false);/// <inheritdoc />public void Dispose(){- _sessionManager.SessionStarted -= OnSessionStarted;_sessionManager.SessionEnded -= OnSessionEnded;}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs b/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.csnew file mode 100644index 0000000000..6a0f29b09f--- /dev/null+++ b/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs@@ -0,0 +1,54 @@+using System.Globalization;+using System.Threading.Tasks;+using Jellyfin.Data.Entities;+using MediaBrowser.Controller.Events;+using MediaBrowser.Controller.Events.Session;+using MediaBrowser.Model.Activity;+using MediaBrowser.Model.Globalization;++namespace Jellyfin.Server.Implementations.Events.Consumers.Session+{+ /// <summary>+ /// Creates an entry in the activity log when a session is started.+ /// </summary>+ public class SessionStartedLogger : IEventConsumer<SessionStartedEventArgs>+ {+ private readonly ILocalizationManager _localizationManager;+ private readonly IActivityManager _activityManager;++ /// <summary>+ /// Initializes a new instance of the <see cref="SessionStartedLogger"/> class.+ /// </summary>+ /// <param name="localizationManager">The localization manager.</param>+ /// <param name="activityManager">The activity manager.</param>+ public SessionStartedLogger(ILocalizationManager localizationManager, IActivityManager activityManager)+ {+ _localizationManager = localizationManager;+ _activityManager = activityManager;+ }++ /// <inheritdoc />+ public async Task OnEvent(SessionStartedEventArgs eventArgs)+ {+ if (string.IsNullOrEmpty(eventArgs.Argument.UserName))+ {+ return;+ }++ await _activityManager.CreateAsync(new ActivityLog(+ string.Format(+ CultureInfo.InvariantCulture,+ _localizationManager.GetLocalizedString("UserOnlineFromDevice"),+ eventArgs.Argument.UserName,+ eventArgs.Argument.DeviceName),+ "SessionStarted",+ eventArgs.Argument.UserId)+ {+ ShortOverview = string.Format(+ CultureInfo.InvariantCulture,+ _localizationManager.GetLocalizedString("LabelIpAddressValue"),+ eventArgs.Argument.RemoteEndPoint)+ }).ConfigureAwait(false);+ }+ }+}diff --git a/MediaBrowser.Controller/Events/Session/SessionStartedEventArgs.cs b/MediaBrowser.Controller/Events/Session/SessionStartedEventArgs.csnew file mode 100644index 0000000000..aab19cc46a--- /dev/null+++ b/MediaBrowser.Controller/Events/Session/SessionStartedEventArgs.cs@@ -0,0 +1,19 @@+using Jellyfin.Data.Events;+using MediaBrowser.Controller.Session;++namespace MediaBrowser.Controller.Events.Session+{+ /// <summary>+ /// An event that fires when a session is started.+ /// </summary>+ public class SessionStartedEventArgs : GenericEventArgs<SessionInfo>+ {+ /// <summary>+ /// Initializes a new instance of the <see cref="SessionStartedEventArgs"/> class.+ /// </summary>+ /// <param name="arg">The session info.</param>+ public SessionStartedEventArgs(SessionInfo arg) : base(arg)+ {+ }+ }+}