Migrate ActivityLogEntryPoint.OnPackageInstallationFailed to IEventConsumer

pull/3910/head
Patrick Barron 4 years ago
parent e924444880
commit 98cbf1c2de

@ -1,13 +1,10 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Notifications;
namespace Emby.Server.Implementations.Activity
{
@ -16,7 +13,6 @@ namespace Emby.Server.Implementations.Activity
/// </summary>
public sealed class ActivityLogEntryPoint : IServerEntryPoint
{
private readonly IInstallationManager _installationManager;
private readonly ISessionManager _sessionManager;
private readonly IActivityManager _activityManager;
private readonly ILocalizationManager _localization;
@ -27,24 +23,19 @@ namespace Emby.Server.Implementations.Activity
/// <param name="sessionManager">The session manager.</param>
/// <param name="activityManager">The activity manager.</param>
/// <param name="localization">The localization manager.</param>
/// <param name="installationManager">The installation manager.</param>
public ActivityLogEntryPoint(
ISessionManager sessionManager,
IActivityManager activityManager,
ILocalizationManager localization,
IInstallationManager installationManager)
ILocalizationManager localization)
{
_sessionManager = sessionManager;
_activityManager = activityManager;
_localization = localization;
_installationManager = installationManager;
}
/// <inheritdoc />
public Task RunAsync()
{
_installationManager.PackageInstallationFailed += OnPackageInstallationFailed;
_sessionManager.SessionStarted += OnSessionStarted;
_sessionManager.SessionEnded += OnSessionEnded;
@ -101,34 +92,12 @@ namespace Emby.Server.Implementations.Activity
}).ConfigureAwait(false);
}
private async void OnPackageInstallationFailed(object sender, InstallationFailedEventArgs e)
{
var installationInfo = e.InstallationInfo;
await CreateLogEntry(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localization.GetLocalizedString("NameInstallFailed"),
installationInfo.Name),
NotificationType.InstallationFailed.ToString(),
Guid.Empty)
{
ShortOverview = string.Format(
CultureInfo.InvariantCulture,
_localization.GetLocalizedString("VersionNumber"),
installationInfo.Version),
Overview = e.Exception.Message
}).ConfigureAwait(false);
}
private async Task CreateLogEntry(ActivityLog entry)
=> await _activityManager.CreateAsync(entry).ConfigureAwait(false);
/// <inheritdoc />
public void Dispose()
{
_installationManager.PackageInstallationFailed -= OnPackageInstallationFailed;
_sessionManager.SessionStarted -= OnSessionStarted;
_sessionManager.SessionEnded -= OnSessionEnded;
}

@ -0,0 +1,51 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Events;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Notifications;
namespace Jellyfin.Server.Implementations.Events.Consumers.Updates
{
/// <summary>
/// Creates an entry in the activity log when a package installation fails.
/// </summary>
public class PackageInstallationFailedLogger : IEventConsumer<InstallationFailedEventArgs>
{
private readonly ILocalizationManager _localizationManager;
private readonly IActivityManager _activityManager;
/// <summary>
/// Initializes a new instance of the <see cref="PackageInstallationFailedLogger"/> class.
/// </summary>
/// <param name="localizationManager">The localization manager.</param>
/// <param name="activityManager">The activity manager.</param>
public PackageInstallationFailedLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
{
_localizationManager = localizationManager;
_activityManager = activityManager;
}
/// <inheritdoc />
public async Task OnEvent(InstallationFailedEventArgs eventArgs)
{
await _activityManager.CreateAsync(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localizationManager.GetLocalizedString("NameInstallFailed"),
eventArgs.InstallationInfo.Name),
NotificationType.InstallationFailed.ToString(),
Guid.Empty)
{
ShortOverview = string.Format(
CultureInfo.InvariantCulture,
_localizationManager.GetLocalizedString("VersionNumber"),
eventArgs.InstallationInfo.Version),
Overview = eventArgs.Exception.Message
}).ConfigureAwait(false);
}
}
}

@ -1,10 +1,11 @@
#pragma warning disable CS1591
using System;
using MediaBrowser.Model.Updates;
namespace MediaBrowser.Common.Updates
{
public class InstallationEventArgs
public class InstallationEventArgs : EventArgs
{
public InstallationInfo InstallationInfo { get; set; }

Loading…
Cancel
Save