2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2019-01-13 20:20:41 +01:00
|
|
|
using System.Threading;
|
2019-01-27 15:40:37 +01:00
|
|
|
using System.Threading.Tasks;
|
2013-06-30 22:27:50 -04:00
|
|
|
using MediaBrowser.Common.Updates;
|
2013-03-04 23:25:27 -05:00
|
|
|
using MediaBrowser.Controller.Plugins;
|
2013-10-02 21:22:50 -04:00
|
|
|
using MediaBrowser.Controller.Session;
|
2020-05-24 15:04:10 +09:00
|
|
|
using MediaBrowser.Model.Updates;
|
2013-03-01 16:22:34 -05:00
|
|
|
|
2016-11-03 18:06:00 -04:00
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2013-03-01 16:22:34 -05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Class WebSocketEvents.
|
2013-03-01 16:22:34 -05:00
|
|
|
/// </summary>
|
2013-10-03 14:02:23 -04:00
|
|
|
public class ServerEventNotifier : IServerEntryPoint
|
2013-03-01 16:22:34 -05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-12-10 16:22:03 +01:00
|
|
|
/// The installation manager.
|
2013-03-01 16:22:34 -05:00
|
|
|
/// </summary>
|
2013-03-04 23:25:27 -05:00
|
|
|
private readonly IInstallationManager _installationManager;
|
2013-03-01 16:22:34 -05:00
|
|
|
|
2013-10-03 14:02:23 -04:00
|
|
|
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)
|
2013-03-01 16:22:34 -05:00
|
|
|
{
|
|
|
|
|
_installationManager = installationManager;
|
2013-10-02 21:22:50 -04:00
|
|
|
_sessionManager = sessionManager;
|
2013-03-04 23:25:27 -05:00
|
|
|
}
|
2013-03-01 16:22:34 -05:00
|
|
|
|
2019-11-01 18:38:54 +01:00
|
|
|
/// <inheritdoc />
|
2019-01-27 15:40:37 +01:00
|
|
|
public Task RunAsync()
|
2013-03-04 23:25:27 -05:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
2020-06-04 03:20:48 +09: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);
|
2013-03-01 16:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
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 />
|
2013-03-01 16:22:34 -05:00
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
2019-11-01 18:38:54 +01:00
|
|
|
GC.SuppressFinalize(this);
|
2013-03-01 16:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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;
|
2013-03-01 16:22:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|