mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-05 13:23:03 +02:00
Migrate ActivityLogEntryPoint.OnSessionStarted to IEventConsumer
This commit is contained in:
parent
98cbf1c2de
commit
ca3a8bdb98
|
@ -36,7 +36,6 @@ namespace Emby.Server.Implementations.Activity
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task RunAsync()
|
public Task RunAsync()
|
||||||
{
|
{
|
||||||
_sessionManager.SessionStarted += OnSessionStarted;
|
|
||||||
_sessionManager.SessionEnded += OnSessionEnded;
|
_sessionManager.SessionEnded += OnSessionEnded;
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
@ -67,38 +66,12 @@ namespace Emby.Server.Implementations.Activity
|
||||||
}).ConfigureAwait(false);
|
}).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)
|
private async Task CreateLogEntry(ActivityLog entry)
|
||||||
=> await _activityManager.CreateAsync(entry).ConfigureAwait(false);
|
=> await _activityManager.CreateAsync(entry).ConfigureAwait(false);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_sessionManager.SessionStarted -= OnSessionStarted;
|
|
||||||
_sessionManager.SessionEnded -= OnSessionEnded;
|
_sessionManager.SessionEnded -= OnSessionEnded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue