2013-04-19 22:27:02 +02:00
|
|
|
|
using MediaBrowser.Common.Events;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
using MediaBrowser.Common.ScheduledTasks;
|
2013-07-01 04:27:50 +02:00
|
|
|
|
using MediaBrowser.Common.Updates;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-04-13 20:02:30 +02:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-03-05 05:25:27 +01:00
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
using MediaBrowser.Model.Tasks;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
using MediaBrowser.Model.Updates;
|
|
|
|
|
using System;
|
|
|
|
|
|
2013-07-04 02:11:11 +02:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.EntryPoints
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class WebSocketEvents
|
|
|
|
|
/// </summary>
|
2013-03-05 05:34:00 +01:00
|
|
|
|
public class WebSocketEvents : IServerEntryPoint
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _server manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IServerManager _serverManager;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _user manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _installation manager
|
|
|
|
|
/// </summary>
|
2013-03-05 05:25:27 +01:00
|
|
|
|
private readonly IInstallationManager _installationManager;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _kernel
|
|
|
|
|
/// </summary>
|
2013-03-07 06:34:00 +01:00
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
|
|
2013-04-15 20:45:58 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _task manager
|
|
|
|
|
/// </summary>
|
2013-03-07 06:34:00 +01:00
|
|
|
|
private readonly ITaskManager _taskManager;
|
2013-04-15 20:45:58 +02:00
|
|
|
|
|
2013-03-01 22:22:34 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="WebSocketEvents" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serverManager">The server manager.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
2013-05-17 17:29:22 +02:00
|
|
|
|
public WebSocketEvents(IServerManager serverManager, IServerApplicationHost appHost, ILogger logger, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager)
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
|
|
|
|
_serverManager = serverManager;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_installationManager = installationManager;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
_appHost = appHost;
|
|
|
|
|
_taskManager = taskManager;
|
2013-03-05 05:25:27 +01:00
|
|
|
|
}
|
2013-03-01 22:22:34 +01:00
|
|
|
|
|
2013-03-05 05:25:27 +01:00
|
|
|
|
public void Run()
|
|
|
|
|
{
|
2013-03-01 22:22:34 +01:00
|
|
|
|
_userManager.UserDeleted += userManager_UserDeleted;
|
|
|
|
|
_userManager.UserUpdated += userManager_UserUpdated;
|
|
|
|
|
|
2013-03-07 06:34:00 +01:00
|
|
|
|
_appHost.HasPendingRestartChanged += kernel_HasPendingRestartChanged;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
|
2013-03-05 05:25:27 +01:00
|
|
|
|
_installationManager.PluginUninstalled += InstallationManager_PluginUninstalled;
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_installationManager.PackageInstalling += _installationManager_PackageInstalling;
|
|
|
|
|
_installationManager.PackageInstallationCancelled += _installationManager_PackageInstallationCancelled;
|
|
|
|
|
_installationManager.PackageInstallationCompleted += _installationManager_PackageInstallationCompleted;
|
|
|
|
|
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
|
|
|
|
|
_taskManager.TaskExecuting += _taskManager_TaskExecuting;
|
|
|
|
|
_taskManager.TaskCompleted += _taskManager_TaskCompleted;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 23:23:32 +02:00
|
|
|
|
void _installationManager_PackageInstalling(object sender, InstallationEventArgs e)
|
2013-03-07 06:34:00 +01:00
|
|
|
|
{
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstalling", e.InstallationInfo);
|
2013-03-07 06:34:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 23:23:32 +02:00
|
|
|
|
void _installationManager_PackageInstallationCancelled(object sender, InstallationEventArgs e)
|
2013-03-07 06:34:00 +01:00
|
|
|
|
{
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstallationCancelled", e.InstallationInfo);
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 23:23:32 +02:00
|
|
|
|
void _installationManager_PackageInstallationCompleted(object sender, InstallationEventArgs e)
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstallationCompleted", e.InstallationInfo);
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 23:23:32 +02:00
|
|
|
|
void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e)
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstallationFailed", e.InstallationInfo);
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 23:23:32 +02:00
|
|
|
|
void _taskManager_TaskCompleted(object sender, GenericEventArgs<TaskResult> e)
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_serverManager.SendWebSocketMessage("ScheduledTaskEnded", e.Argument);
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 23:23:32 +02:00
|
|
|
|
void _taskManager_TaskExecuting(object sender, EventArgs e)
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
2013-07-06 23:23:32 +02:00
|
|
|
|
var task = (IScheduledTask)sender;
|
|
|
|
|
_serverManager.SendWebSocketMessage("ScheduledTaskStarted", task.Name);
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Installations the manager_ plugin uninstalled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The sender.</param>
|
|
|
|
|
/// <param name="e">The e.</param>
|
|
|
|
|
void InstallationManager_PluginUninstalled(object sender, GenericEventArgs<IPlugin> e)
|
|
|
|
|
{
|
|
|
|
|
_serverManager.SendWebSocketMessage("PluginUninstalled", e.Argument.GetPluginInfo());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the HasPendingRestartChanged event of the kernel control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The source of the event.</param>
|
|
|
|
|
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
|
|
|
|
void kernel_HasPendingRestartChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-03-28 06:19:58 +01:00
|
|
|
|
_serverManager.SendWebSocketMessage("RestartRequired", _appHost.GetSystemInfo());
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Users the manager_ user updated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The sender.</param>
|
|
|
|
|
/// <param name="e">The e.</param>
|
2013-04-18 00:30:20 +02:00
|
|
|
|
async void userManager_UserUpdated(object sender, GenericEventArgs<User> e)
|
2013-03-01 22:22:34 +01:00
|
|
|
|
{
|
2013-04-18 00:30:20 +02:00
|
|
|
|
var dto = await new UserDtoBuilder(_logger).GetUserDto(e.Argument).ConfigureAwait(false);
|
2013-03-08 17:40:01 +01:00
|
|
|
|
|
|
|
|
|
_serverManager.SendWebSocketMessage("UserUpdated", dto);
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Users the manager_ user deleted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The sender.</param>
|
|
|
|
|
/// <param name="e">The e.</param>
|
|
|
|
|
void userManager_UserDeleted(object sender, GenericEventArgs<User> e)
|
|
|
|
|
{
|
2013-05-10 00:43:11 +02:00
|
|
|
|
_serverManager.SendWebSocketMessage("UserDeleted", e.Argument.Id.ToString("N"));
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
_userManager.UserDeleted -= userManager_UserDeleted;
|
|
|
|
|
_userManager.UserUpdated -= userManager_UserUpdated;
|
|
|
|
|
|
|
|
|
|
_installationManager.PluginUninstalled -= InstallationManager_PluginUninstalled;
|
2013-07-06 23:23:32 +02:00
|
|
|
|
_installationManager.PackageInstalling -= _installationManager_PackageInstalling;
|
|
|
|
|
_installationManager.PackageInstallationCancelled -= _installationManager_PackageInstallationCancelled;
|
|
|
|
|
_installationManager.PackageInstallationCompleted -= _installationManager_PackageInstallationCompleted;
|
|
|
|
|
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
|
2013-03-07 06:34:00 +01:00
|
|
|
|
_appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged;
|
2013-03-01 22:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|