mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Migrate ServerEventNotifier.OnPackageInstallationCancelled to IEventConsumer
This commit is contained in:
parent
e82dd8b70e
commit
a40064a146
@ -1,79 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Updates;
|
|
||||||
using MediaBrowser.Controller.Plugins;
|
|
||||||
using MediaBrowser.Controller.Session;
|
|
||||||
using MediaBrowser.Model.Updates;
|
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.EntryPoints
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Class WebSocketEvents.
|
|
||||||
/// </summary>
|
|
||||||
public class ServerEventNotifier : IServerEntryPoint
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The installation manager.
|
|
||||||
/// </summary>
|
|
||||||
private readonly IInstallationManager _installationManager;
|
|
||||||
|
|
||||||
private readonly ISessionManager _sessionManager;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ServerEventNotifier"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="installationManager">The installation manager.</param>
|
|
||||||
/// <param name="sessionManager">The session manager.</param>
|
|
||||||
public ServerEventNotifier(
|
|
||||||
IInstallationManager installationManager,
|
|
||||||
ISessionManager sessionManager)
|
|
||||||
{
|
|
||||||
_installationManager = installationManager;
|
|
||||||
_sessionManager = sessionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task RunAsync()
|
|
||||||
{
|
|
||||||
_installationManager.PackageInstallationCancelled += OnPackageInstallationCancelled;
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnPackageInstallationCancelled(object sender, InstallationInfo e)
|
|
||||||
{
|
|
||||||
await SendMessageToAdminSessions("PackageInstallationCancelled", e).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task SendMessageToAdminSessions<T>(string name, T data)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _sessionManager.SendMessageToAdminSessions(name, data, CancellationToken.None).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Releases unmanaged and - optionally - managed resources.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
||||||
protected virtual void Dispose(bool dispose)
|
|
||||||
{
|
|
||||||
if (dispose)
|
|
||||||
{
|
|
||||||
_installationManager.PackageInstallationCancelled -= OnPackageInstallationCancelled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,31 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Controller.Events;
|
||||||
|
using MediaBrowser.Controller.Events.Updates;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Implementations.Events.Consumers.Updates
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Notifies admin users when a plugin installation is cancelled.
|
||||||
|
/// </summary>
|
||||||
|
public class PluginInstallationCancelledNotifier : IEventConsumer<PluginInstallationCancelledEventArgs>
|
||||||
|
{
|
||||||
|
private readonly ISessionManager _sessionManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="PluginInstallationCancelledNotifier"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionManager">The session manager.</param>
|
||||||
|
public PluginInstallationCancelledNotifier(ISessionManager sessionManager)
|
||||||
|
{
|
||||||
|
_sessionManager = sessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task OnEvent(PluginInstallationCancelledEventArgs eventArgs)
|
||||||
|
{
|
||||||
|
await _sessionManager.SendMessageToAdminSessions("PackageInstallationCancelled", eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using Jellyfin.Data.Events;
|
||||||
|
using MediaBrowser.Model.Updates;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Controller.Events.Updates
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An event that occurs when a plugin installation is cancelled.
|
||||||
|
/// </summary>
|
||||||
|
public class PluginInstallationCancelledEventArgs : GenericEventArgs<InstallationInfo>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="PluginInstallationCancelledEventArgs"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arg">The installation info.</param>
|
||||||
|
public PluginInstallationCancelledEventArgs(InstallationInfo arg) : base(arg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user