mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-05 21:37:10 -04:00
Migrate ActivityLogEntryPoint.OnPackageInstallationFailed to IEventConsumer
This commit is contained in:
parent
e924444880
commit
98cbf1c2de
@ -1,13 +1,10 @@
|
|||||||
using System;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
using MediaBrowser.Common.Updates;
|
|
||||||
using MediaBrowser.Controller.Plugins;
|
using MediaBrowser.Controller.Plugins;
|
||||||
using MediaBrowser.Controller.Session;
|
using MediaBrowser.Controller.Session;
|
||||||
using MediaBrowser.Model.Activity;
|
using MediaBrowser.Model.Activity;
|
||||||
using MediaBrowser.Model.Globalization;
|
using MediaBrowser.Model.Globalization;
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.Activity
|
namespace Emby.Server.Implementations.Activity
|
||||||
{
|
{
|
||||||
@ -16,7 +13,6 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ActivityLogEntryPoint : IServerEntryPoint
|
public sealed class ActivityLogEntryPoint : IServerEntryPoint
|
||||||
{
|
{
|
||||||
private readonly IInstallationManager _installationManager;
|
|
||||||
private readonly ISessionManager _sessionManager;
|
private readonly ISessionManager _sessionManager;
|
||||||
private readonly IActivityManager _activityManager;
|
private readonly IActivityManager _activityManager;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
@ -27,24 +23,19 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
/// <param name="sessionManager">The session manager.</param>
|
/// <param name="sessionManager">The session manager.</param>
|
||||||
/// <param name="activityManager">The activity manager.</param>
|
/// <param name="activityManager">The activity manager.</param>
|
||||||
/// <param name="localization">The localization manager.</param>
|
/// <param name="localization">The localization manager.</param>
|
||||||
/// <param name="installationManager">The installation manager.</param>
|
|
||||||
public ActivityLogEntryPoint(
|
public ActivityLogEntryPoint(
|
||||||
ISessionManager sessionManager,
|
ISessionManager sessionManager,
|
||||||
IActivityManager activityManager,
|
IActivityManager activityManager,
|
||||||
ILocalizationManager localization,
|
ILocalizationManager localization)
|
||||||
IInstallationManager installationManager)
|
|
||||||
{
|
{
|
||||||
_sessionManager = sessionManager;
|
_sessionManager = sessionManager;
|
||||||
_activityManager = activityManager;
|
_activityManager = activityManager;
|
||||||
_localization = localization;
|
_localization = localization;
|
||||||
_installationManager = installationManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task RunAsync()
|
public Task RunAsync()
|
||||||
{
|
{
|
||||||
_installationManager.PackageInstallationFailed += OnPackageInstallationFailed;
|
|
||||||
|
|
||||||
_sessionManager.SessionStarted += OnSessionStarted;
|
_sessionManager.SessionStarted += OnSessionStarted;
|
||||||
_sessionManager.SessionEnded += OnSessionEnded;
|
_sessionManager.SessionEnded += OnSessionEnded;
|
||||||
|
|
||||||
@ -101,34 +92,12 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
}).ConfigureAwait(false);
|
}).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)
|
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()
|
||||||
{
|
{
|
||||||
_installationManager.PackageInstallationFailed -= OnPackageInstallationFailed;
|
|
||||||
|
|
||||||
_sessionManager.SessionStarted -= OnSessionStarted;
|
_sessionManager.SessionStarted -= OnSessionStarted;
|
||||||
_sessionManager.SessionEnded -= OnSessionEnded;
|
_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
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
|
using System;
|
||||||
using MediaBrowser.Model.Updates;
|
using MediaBrowser.Model.Updates;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Updates
|
namespace MediaBrowser.Common.Updates
|
||||||
{
|
{
|
||||||
public class InstallationEventArgs
|
public class InstallationEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public InstallationInfo InstallationInfo { get; set; }
|
public InstallationInfo InstallationInfo { get; set; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user