Files
jellyfin-jellyfin-1/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs

80 lines
2.5 KiB
C#
Raw Normal View History

using System;
using System.Threading;
2019-01-27 15:40:37 +01:00
using System.Threading.Tasks;
using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Plugins;
2013-10-02 21:22:50 -04:00
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Updates;
namespace Emby.Server.Implementations.EntryPoints
{
/// <summary>
2019-11-01 18:38:54 +01:00
/// Class WebSocketEvents.
/// </summary>
public class ServerEventNotifier : IServerEntryPoint
{
/// <summary>
/// The installation manager.
/// </summary>
private readonly IInstallationManager _installationManager;
private readonly ISessionManager _sessionManager;
2013-10-02 21:22:50 -04:00
2019-11-01 18:38:54 +01:00
/// <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;
2013-10-02 21:22:50 -04:00
_sessionManager = sessionManager;
}
2019-11-01 18:38:54 +01:00
/// <inheritdoc />
2019-01-27 15:40:37 +01:00
public Task RunAsync()
{
2019-11-01 18:38:54 +01:00
_installationManager.PackageInstallationCancelled += OnPackageInstallationCancelled;
2013-03-07 00:34:00 -05:00
2019-01-27 15:40:37 +01:00
return Task.CompletedTask;
2013-03-07 00:34:00 -05:00
}
private async void OnPackageInstallationCancelled(object sender, InstallationInfo e)
2013-03-07 00:34:00 -05:00
{
2020-06-03 13:54:55 -06:00
await SendMessageToAdminSessions("PackageInstallationCancelled", e).ConfigureAwait(false);
}
2020-05-25 23:52:51 +02:00
private async Task SendMessageToAdminSessions<T>(string name, T data)
2018-09-12 19:26:21 +02:00
{
try
{
2019-10-25 12:47:20 +02:00
await _sessionManager.SendMessageToAdminSessions(name, data, CancellationToken.None).ConfigureAwait(false);
2018-09-12 19:26:21 +02:00
}
catch (Exception)
{
}
}
2019-11-01 18:38:54 +01:00
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
2019-11-01 18:38:54 +01:00
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)
{
2019-11-01 18:38:54 +01:00
_installationManager.PackageInstallationCancelled -= OnPackageInstallationCancelled;
}
}
}
}