< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Events.Consumers.Session.SessionStartedLogger
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 54
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Threading.Tasks;
 3using Jellyfin.Data.Entities;
 4using MediaBrowser.Controller.Events;
 5using MediaBrowser.Controller.Events.Session;
 6using MediaBrowser.Model.Activity;
 7using MediaBrowser.Model.Globalization;
 8
 9namespace Jellyfin.Server.Implementations.Events.Consumers.Session
 10{
 11    /// <summary>
 12    /// Creates an entry in the activity log when a session is started.
 13    /// </summary>
 14    public class SessionStartedLogger : IEventConsumer<SessionStartedEventArgs>
 15    {
 16        private readonly ILocalizationManager _localizationManager;
 17        private readonly IActivityManager _activityManager;
 18
 19        /// <summary>
 20        /// Initializes a new instance of the <see cref="SessionStartedLogger"/> class.
 21        /// </summary>
 22        /// <param name="localizationManager">The localization manager.</param>
 23        /// <param name="activityManager">The activity manager.</param>
 24        public SessionStartedLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
 25        {
 1626            _localizationManager = localizationManager;
 1627            _activityManager = activityManager;
 1628        }
 29
 30        /// <inheritdoc />
 31        public async Task OnEvent(SessionStartedEventArgs eventArgs)
 32        {
 33            if (string.IsNullOrEmpty(eventArgs.Argument.UserName))
 34            {
 35                return;
 36            }
 37
 38            await _activityManager.CreateAsync(new ActivityLog(
 39                string.Format(
 40                    CultureInfo.InvariantCulture,
 41                    _localizationManager.GetLocalizedString("UserOnlineFromDevice"),
 42                    eventArgs.Argument.UserName,
 43                    eventArgs.Argument.DeviceName),
 44                "SessionStarted",
 45                eventArgs.Argument.UserId)
 46            {
 47                ShortOverview = string.Format(
 48                    CultureInfo.InvariantCulture,
 49                    _localizationManager.GetLocalizedString("LabelIpAddressValue"),
 50                    eventArgs.Argument.RemoteEndPoint)
 51            }).ConfigureAwait(false);
 52        }
 53    }
 54}