2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2019-01-13 19:20:16 +00:00
|
|
|
using System.Collections.Generic;
|
2019-02-28 22:22:57 +00:00
|
|
|
using System.Globalization;
|
2019-01-13 19:20:16 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2019-01-27 14:40:37 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-05-02 22:32:22 +00:00
|
|
|
using Jellyfin.Data.Entities;
|
2014-08-10 22:13:17 +00:00
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
using MediaBrowser.Common.Updates;
|
2019-01-13 19:20:16 +00:00
|
|
|
using MediaBrowser.Controller.Authentication;
|
|
|
|
using MediaBrowser.Controller.Devices;
|
2014-08-10 22:13:17 +00:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
using MediaBrowser.Controller.Subtitles;
|
|
|
|
using MediaBrowser.Model.Activity;
|
2019-01-13 19:20:16 +00:00
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-08-10 22:13:17 +00:00
|
|
|
using MediaBrowser.Model.Events;
|
2016-10-24 02:45:23 +00:00
|
|
|
using MediaBrowser.Model.Globalization;
|
2018-09-12 17:26:21 +00:00
|
|
|
using MediaBrowser.Model.Notifications;
|
2019-01-13 19:20:16 +00:00
|
|
|
using MediaBrowser.Model.Tasks;
|
|
|
|
using MediaBrowser.Model.Updates;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2016-11-03 07:14:14 +00:00
|
|
|
namespace Emby.Server.Implementations.Activity
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-04-14 18:45:57 +00:00
|
|
|
/// <summary>
|
2020-04-11 10:03:10 +00:00
|
|
|
/// Entry point for the activity logger.
|
2020-04-14 18:45:57 +00:00
|
|
|
/// </summary>
|
2020-02-08 21:25:44 +00:00
|
|
|
public sealed class ActivityLogEntryPoint : IServerEntryPoint
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2019-03-25 20:27:03 +00:00
|
|
|
private readonly ILogger _logger;
|
2014-08-10 22:13:17 +00:00
|
|
|
private readonly IInstallationManager _installationManager;
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
private readonly ITaskManager _taskManager;
|
|
|
|
private readonly IActivityManager _activityManager;
|
|
|
|
private readonly ILocalizationManager _localization;
|
|
|
|
private readonly ISubtitleManager _subManager;
|
|
|
|
private readonly IUserManager _userManager;
|
2018-09-12 17:26:21 +00:00
|
|
|
private readonly IDeviceManager _deviceManager;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-11-01 17:38:54 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ActivityLogEntryPoint"/> class.
|
|
|
|
/// </summary>
|
2020-04-14 18:45:57 +00:00
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
/// <param name="sessionManager">The session manager.</param>
|
|
|
|
/// <param name="deviceManager">The device manager.</param>
|
|
|
|
/// <param name="taskManager">The task manager.</param>
|
|
|
|
/// <param name="activityManager">The activity manager.</param>
|
|
|
|
/// <param name="localization">The localization manager.</param>
|
|
|
|
/// <param name="installationManager">The installation manager.</param>
|
|
|
|
/// <param name="subManager">The subtitle manager.</param>
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
2019-03-25 20:27:03 +00:00
|
|
|
public ActivityLogEntryPoint(
|
|
|
|
ILogger<ActivityLogEntryPoint> logger,
|
|
|
|
ISessionManager sessionManager,
|
|
|
|
IDeviceManager deviceManager,
|
|
|
|
ITaskManager taskManager,
|
|
|
|
IActivityManager activityManager,
|
|
|
|
ILocalizationManager localization,
|
|
|
|
IInstallationManager installationManager,
|
|
|
|
ISubtitleManager subManager,
|
2020-02-08 21:25:44 +00:00
|
|
|
IUserManager userManager)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2019-03-25 20:27:03 +00:00
|
|
|
_logger = logger;
|
2014-08-10 22:13:17 +00:00
|
|
|
_sessionManager = sessionManager;
|
2019-03-25 20:27:03 +00:00
|
|
|
_deviceManager = deviceManager;
|
2014-08-10 22:13:17 +00:00
|
|
|
_taskManager = taskManager;
|
|
|
|
_activityManager = activityManager;
|
|
|
|
_localization = localization;
|
|
|
|
_installationManager = installationManager;
|
|
|
|
_subManager = subManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
}
|
|
|
|
|
2020-04-14 18:45:57 +00:00
|
|
|
/// <inheritdoc />
|
2019-01-27 14:40:37 +00:00
|
|
|
public Task RunAsync()
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2019-02-28 21:33:20 +00:00
|
|
|
_taskManager.TaskCompleted += OnTaskCompleted;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_installationManager.PluginInstalled += OnPluginInstalled;
|
|
|
|
_installationManager.PluginUninstalled += OnPluginUninstalled;
|
|
|
|
_installationManager.PluginUpdated += OnPluginUpdated;
|
|
|
|
_installationManager.PackageInstallationFailed += OnPackageInstallationFailed;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_sessionManager.SessionStarted += OnSessionStarted;
|
|
|
|
_sessionManager.AuthenticationFailed += OnAuthenticationFailed;
|
|
|
|
_sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded;
|
|
|
|
_sessionManager.SessionEnded += OnSessionEnded;
|
|
|
|
_sessionManager.PlaybackStart += OnPlaybackStart;
|
|
|
|
_sessionManager.PlaybackStopped += OnPlaybackStopped;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_subManager.SubtitleDownloadFailure += OnSubtitleDownloadFailure;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_userManager.UserCreated += OnUserCreated;
|
|
|
|
_userManager.UserPasswordChanged += OnUserPasswordChanged;
|
|
|
|
_userManager.UserDeleted += OnUserDeleted;
|
|
|
|
_userManager.UserPolicyUpdated += OnUserPolicyUpdated;
|
|
|
|
_userManager.UserLockedOut += OnUserLockedOut;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_deviceManager.CameraImageUploaded += OnCameraImageUploaded;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-01-27 14:40:37 +00:00
|
|
|
return Task.CompletedTask;
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnCameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("CameraImageUploadedFrom"),
|
|
|
|
e.Argument.Device.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
NotificationType.CameraImageUploaded.ToString(),
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnUserLockedOut(object sender, GenericEventArgs<MediaBrowser.Controller.Entities.User> e)
|
2015-03-02 05:16:29 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserLockedOutWithName"),
|
|
|
|
e.Argument.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
NotificationType.UserLockedOut.ToString(),
|
|
|
|
e.Argument.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2015-03-02 05:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnSubtitleDownloadFailure(object sender, SubtitleDownloadFailureEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("SubtitleDownloadFailureFromForItem"),
|
|
|
|
e.Provider,
|
2020-05-02 22:32:22 +00:00
|
|
|
Emby.Notifications.NotificationEntryPoint.GetItemName(e.Item)),
|
|
|
|
"SubtitleDownloadFailure",
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-02-28 22:22:57 +00:00
|
|
|
ItemId = e.Item.Id.ToString("N", CultureInfo.InvariantCulture),
|
2018-09-12 17:26:21 +00:00
|
|
|
ShortOverview = e.Exception.Message
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnPlaybackStopped(object sender, PlaybackStopEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
var item = e.MediaInfo;
|
|
|
|
|
|
|
|
if (item == null)
|
|
|
|
{
|
2019-03-25 20:27:03 +00:00
|
|
|
_logger.LogWarning("PlaybackStopped reported with null media info.");
|
2014-08-10 22:13:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-09 19:26:54 +00:00
|
|
|
if (e.Item != null && e.Item.IsThemeMedia)
|
2014-08-26 02:30:52 +00:00
|
|
|
{
|
|
|
|
// Don't report theme song or local trailer playback
|
|
|
|
return;
|
2017-08-27 00:32:33 +00:00
|
|
|
}
|
2014-08-26 02:30:52 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
if (e.Users.Count == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
var user = e.Users[0];
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2020-04-11 10:03:10 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserStoppedPlayingItemWithValues"),
|
|
|
|
user.Name,
|
|
|
|
GetItemName(item),
|
|
|
|
e.DeviceName),
|
2020-05-02 22:32:22 +00:00
|
|
|
GetPlaybackStoppedNotificationType(item.MediaType),
|
|
|
|
user.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnPlaybackStart(object sender, PlaybackProgressEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
var item = e.MediaInfo;
|
|
|
|
|
|
|
|
if (item == null)
|
|
|
|
{
|
2019-03-25 20:27:03 +00:00
|
|
|
_logger.LogWarning("PlaybackStart reported with null media info.");
|
2014-08-10 22:13:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-09 19:26:54 +00:00
|
|
|
if (e.Item != null && e.Item.IsThemeMedia)
|
2014-08-26 02:30:52 +00:00
|
|
|
{
|
|
|
|
// Don't report theme song or local trailer playback
|
|
|
|
return;
|
2017-08-27 00:32:33 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
if (e.Users.Count == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-02 00:28:16 +00:00
|
|
|
var user = e.Users.First();
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserStartedPlayingItemWithValues"),
|
|
|
|
user.Name,
|
|
|
|
GetItemName(item),
|
|
|
|
e.DeviceName),
|
2020-05-02 22:32:22 +00:00
|
|
|
GetPlaybackNotificationType(item.MediaType),
|
|
|
|
user.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private static string GetItemName(BaseItemDto item)
|
|
|
|
{
|
|
|
|
var name = item.Name;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.SeriesName))
|
|
|
|
{
|
|
|
|
name = item.SeriesName + " - " + name;
|
|
|
|
}
|
|
|
|
|
2019-08-29 20:28:33 +00:00
|
|
|
if (item.Artists != null && item.Artists.Count > 0)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
|
|
|
name = item.Artists[0] + " - " + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
private static string GetPlaybackNotificationType(string mediaType)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
|
|
|
if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return NotificationType.AudioPlayback.ToString();
|
|
|
|
}
|
2019-03-25 20:27:03 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return NotificationType.VideoPlayback.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
private static string GetPlaybackStoppedNotificationType(string mediaType)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
|
|
|
if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return NotificationType.AudioPlaybackStopped.ToString();
|
|
|
|
}
|
2019-03-25 20:27:03 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return NotificationType.VideoPlaybackStopped.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnSessionEnded(object sender, SessionEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
var session = e.SessionInfo;
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (string.IsNullOrEmpty(session.UserName))
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2014-08-14 13:24:30 +00:00
|
|
|
return;
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
2020-04-14 18:45:57 +00:00
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserOfflineFromDevice"),
|
|
|
|
session.UserName,
|
2020-04-14 18:45:57 +00:00
|
|
|
session.DeviceName),
|
2020-05-02 22:32:22 +00:00
|
|
|
"SessionEnded",
|
|
|
|
session.UserId,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("LabelIpAddressValue"),
|
|
|
|
session.RemoteEndPoint),
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnAuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
var user = e.Argument.User;
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("AuthenticationSucceededWithUserName"),
|
|
|
|
user.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
"AuthenticationSucceeded",
|
|
|
|
user.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("LabelIpAddressValue"),
|
|
|
|
e.Argument.SessionInfo.RemoteEndPoint),
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnAuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("FailedLoginAttemptWithUserName"),
|
|
|
|
e.Argument.Username),
|
2020-05-02 22:32:22 +00:00
|
|
|
"AuthenticationFailed",
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Error)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("LabelIpAddressValue"),
|
|
|
|
e.Argument.RemoteEndPoint),
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnUserPolicyUpdated(object sender, GenericEventArgs<MediaBrowser.Controller.Entities.User> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserPolicyUpdatedWithName"),
|
|
|
|
e.Argument.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
"UserPolicyUpdated",
|
|
|
|
e.Argument.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnUserDeleted(object sender, GenericEventArgs<MediaBrowser.Controller.Entities.User> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserDeletedWithName"),
|
|
|
|
e.Argument.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
"UserDeleted",
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnUserPasswordChanged(object sender, GenericEventArgs<MediaBrowser.Controller.Entities.User> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserPasswordChangedWithName"),
|
|
|
|
e.Argument.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
"UserPasswordChanged",
|
|
|
|
e.Argument.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnUserCreated(object sender, GenericEventArgs<MediaBrowser.Controller.Entities.User> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserCreatedWithName"),
|
|
|
|
e.Argument.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
"UserCreated",
|
|
|
|
e.Argument.Id,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnSessionStarted(object sender, SessionEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
var session = e.SessionInfo;
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (string.IsNullOrEmpty(session.UserName))
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2014-08-14 13:24:30 +00:00
|
|
|
return;
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
2020-04-14 18:45:57 +00:00
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("UserOnlineFromDevice"),
|
|
|
|
session.UserName,
|
2020-04-14 18:45:57 +00:00
|
|
|
session.DeviceName),
|
2020-05-02 22:32:22 +00:00
|
|
|
"SessionStarted",
|
|
|
|
session.UserId,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("LabelIpAddressValue"),
|
2020-05-02 22:32:22 +00:00
|
|
|
session.RemoteEndPoint)
|
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnPluginUpdated(object sender, GenericEventArgs<(IPlugin, VersionInfo)> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("PluginUpdatedWithName"),
|
|
|
|
e.Argument.Item1.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
NotificationType.PluginUpdateInstalled.ToString(),
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("VersionNumber"),
|
2020-04-11 10:52:40 +00:00
|
|
|
e.Argument.Item2.version),
|
2020-04-11 10:56:42 +00:00
|
|
|
Overview = e.Argument.Item2.changelog
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnPluginUninstalled(object sender, GenericEventArgs<IPlugin> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("PluginUninstalledWithName"),
|
|
|
|
e.Argument.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
NotificationType.PluginUninstalled.ToString(),
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace))
|
|
|
|
.ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnPluginInstalled(object sender, GenericEventArgs<VersionInfo> e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("PluginInstalledWithName"),
|
|
|
|
e.Argument.name),
|
2020-05-02 22:32:22 +00:00
|
|
|
NotificationType.PluginInstalled.ToString(),
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("VersionNumber"),
|
2020-04-11 10:52:40 +00:00
|
|
|
e.Argument.version)
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnPackageInstallationFailed(object sender, InstallationFailedEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
var installationInfo = e.InstallationInfo;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(
|
2019-08-29 20:28:33 +00:00
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("NameInstallFailed"),
|
|
|
|
installationInfo.Name),
|
2020-05-02 22:32:22 +00:00
|
|
|
NotificationType.InstallationFailed.ToString(),
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Trace)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
ShortOverview = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("VersionNumber"),
|
|
|
|
installationInfo.Version),
|
2018-09-12 17:26:21 +00:00
|
|
|
Overview = e.Exception.Message
|
2020-05-02 22:32:22 +00:00
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async void OnTaskCompleted(object sender, TaskCompletionEventArgs e)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
var result = e.Result;
|
|
|
|
var task = e.Task;
|
|
|
|
|
2020-04-11 10:03:10 +00:00
|
|
|
if (task.ScheduledTask is IConfigurableScheduledTask activityTask
|
|
|
|
&& !activityTask.IsLogged)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-08-27 00:32:33 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
var time = result.EndTimeUtc - result.StartTimeUtc;
|
2019-08-29 20:28:33 +00:00
|
|
|
var runningTime = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
_localization.GetLocalizedString("LabelRunningTimeValue"),
|
|
|
|
ToUserFriendlyString(time));
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2014-10-24 04:54:35 +00:00
|
|
|
if (result.Status == TaskCompletionStatus.Failed)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
var vals = new List<string>();
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!string.IsNullOrEmpty(e.Result.ErrorMessage))
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
vals.Add(e.Result.ErrorMessage);
|
|
|
|
}
|
2019-03-25 20:27:03 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!string.IsNullOrEmpty(e.Result.LongErrorMessage))
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
vals.Add(e.Result.LongErrorMessage);
|
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
await CreateLogEntry(new ActivityLog(
|
|
|
|
string.Format(CultureInfo.InvariantCulture, _localization.GetLocalizedString("ScheduledTaskFailedWithName"), task.Name),
|
|
|
|
NotificationType.TaskFailed.ToString(),
|
|
|
|
Guid.Empty,
|
|
|
|
DateTime.UtcNow,
|
|
|
|
LogLevel.Error)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2019-03-25 20:27:03 +00:00
|
|
|
Overview = string.Join(Environment.NewLine, vals),
|
2020-05-02 22:32:22 +00:00
|
|
|
ShortOverview = runningTime
|
|
|
|
}).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 22:32:22 +00:00
|
|
|
private async Task CreateLogEntry(ActivityLog entry)
|
|
|
|
=> await _activityManager.CreateAsync(entry).ConfigureAwait(false);
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2020-02-08 21:25:44 +00:00
|
|
|
/// <inheritdoc />
|
2014-08-10 22:13:17 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
2019-02-28 21:33:20 +00:00
|
|
|
_taskManager.TaskCompleted -= OnTaskCompleted;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_installationManager.PluginInstalled -= OnPluginInstalled;
|
|
|
|
_installationManager.PluginUninstalled -= OnPluginUninstalled;
|
|
|
|
_installationManager.PluginUpdated -= OnPluginUpdated;
|
|
|
|
_installationManager.PackageInstallationFailed -= OnPackageInstallationFailed;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_sessionManager.SessionStarted -= OnSessionStarted;
|
|
|
|
_sessionManager.AuthenticationFailed -= OnAuthenticationFailed;
|
|
|
|
_sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded;
|
|
|
|
_sessionManager.SessionEnded -= OnSessionEnded;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_sessionManager.PlaybackStart -= OnPlaybackStart;
|
|
|
|
_sessionManager.PlaybackStopped -= OnPlaybackStopped;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_subManager.SubtitleDownloadFailure -= OnSubtitleDownloadFailure;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_userManager.UserCreated -= OnUserCreated;
|
|
|
|
_userManager.UserPasswordChanged -= OnUserPasswordChanged;
|
|
|
|
_userManager.UserDeleted -= OnUserDeleted;
|
|
|
|
_userManager.UserPolicyUpdated -= OnUserPolicyUpdated;
|
|
|
|
_userManager.UserLockedOut -= OnUserLockedOut;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2019-02-28 21:33:20 +00:00
|
|
|
_deviceManager.CameraImageUploaded -= OnCameraImageUploaded;
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructs a user-friendly string for this TimeSpan instance.
|
|
|
|
/// </summary>
|
2020-04-11 10:03:10 +00:00
|
|
|
private static string ToUserFriendlyString(TimeSpan span)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
const int DaysInYear = 365;
|
|
|
|
const int DaysInMonth = 30;
|
|
|
|
|
|
|
|
// Get each non-zero value from TimeSpan component
|
2019-01-13 20:37:13 +00:00
|
|
|
var values = new List<string>();
|
2014-08-10 22:13:17 +00:00
|
|
|
|
|
|
|
// Number of years
|
|
|
|
int days = span.Days;
|
|
|
|
if (days >= DaysInYear)
|
|
|
|
{
|
2016-03-27 21:11:27 +00:00
|
|
|
int years = days / DaysInYear;
|
2014-08-10 22:13:17 +00:00
|
|
|
values.Add(CreateValueString(years, "year"));
|
2020-05-02 22:32:22 +00:00
|
|
|
days = days % DaysInYear;
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
2019-02-28 21:33:20 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
// Number of months
|
|
|
|
if (days >= DaysInMonth)
|
|
|
|
{
|
2016-03-27 21:11:27 +00:00
|
|
|
int months = days / DaysInMonth;
|
2014-08-10 22:13:17 +00:00
|
|
|
values.Add(CreateValueString(months, "month"));
|
2020-05-02 22:32:22 +00:00
|
|
|
days = days % DaysInMonth;
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
2019-02-28 21:33:20 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
// Number of days
|
|
|
|
if (days >= 1)
|
2019-02-28 21:33:20 +00:00
|
|
|
{
|
2014-08-10 22:13:17 +00:00
|
|
|
values.Add(CreateValueString(days, "day"));
|
2019-02-28 21:33:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
// Number of hours
|
|
|
|
if (span.Hours >= 1)
|
2019-02-28 21:33:20 +00:00
|
|
|
{
|
2014-08-10 22:13:17 +00:00
|
|
|
values.Add(CreateValueString(span.Hours, "hour"));
|
2019-02-28 21:33:20 +00:00
|
|
|
}
|
2019-03-25 20:27:03 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
// Number of minutes
|
|
|
|
if (span.Minutes >= 1)
|
2019-02-28 21:33:20 +00:00
|
|
|
{
|
2014-08-10 22:13:17 +00:00
|
|
|
values.Add(CreateValueString(span.Minutes, "minute"));
|
2019-02-28 21:33:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
// Number of seconds (include when 0 if no other components included)
|
|
|
|
if (span.Seconds >= 1 || values.Count == 0)
|
2019-02-28 21:33:20 +00:00
|
|
|
{
|
2014-08-10 22:13:17 +00:00
|
|
|
values.Add(CreateValueString(span.Seconds, "second"));
|
2019-02-28 21:33:20 +00:00
|
|
|
}
|
2014-08-10 22:13:17 +00:00
|
|
|
|
|
|
|
// Combine values into string
|
2019-01-13 20:37:13 +00:00
|
|
|
var builder = new StringBuilder();
|
2014-08-10 22:13:17 +00:00
|
|
|
for (int i = 0; i < values.Count; i++)
|
|
|
|
{
|
|
|
|
if (builder.Length > 0)
|
2019-02-28 21:33:20 +00:00
|
|
|
{
|
2016-03-27 21:11:27 +00:00
|
|
|
builder.Append(i == values.Count - 1 ? " and " : ", ");
|
2019-02-28 21:33:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
builder.Append(values[i]);
|
|
|
|
}
|
2019-03-25 20:27:03 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
// Return result
|
|
|
|
return builder.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructs a string description of a time-span value.
|
|
|
|
/// </summary>
|
2019-10-25 10:47:20 +00:00
|
|
|
/// <param name="value">The value of this item.</param>
|
|
|
|
/// <param name="description">The name of this item (singular form).</param>
|
2014-08-10 22:13:17 +00:00
|
|
|
private static string CreateValueString(int value, string description)
|
|
|
|
{
|
2019-08-29 20:28:33 +00:00
|
|
|
return string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
"{0:#,##0} {1}",
|
|
|
|
value,
|
|
|
|
value == 1 ? description : string.Format(CultureInfo.InvariantCulture, "{0}s", description));
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|