2014-11-26 04:12:29 +00:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
2013-03-07 05:34:00 +00:00
|
|
|
|
using MediaBrowser.Common.ScheduledTasks;
|
2013-07-01 02:27:50 +00:00
|
|
|
|
using MediaBrowser.Common.Updates;
|
2013-03-07 05:34:00 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-11-26 04:12:29 +00:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2013-03-05 04:25:27 +00:00
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
2013-10-03 01:22:50 +00:00
|
|
|
|
using MediaBrowser.Controller.Session;
|
2015-01-28 04:04:26 +00:00
|
|
|
|
using MediaBrowser.Controller.Sync;
|
2014-05-08 20:09:53 +00:00
|
|
|
|
using MediaBrowser.Model.Events;
|
2015-01-28 04:04:26 +00:00
|
|
|
|
using MediaBrowser.Model.Sync;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
using System;
|
2013-10-03 01:22:50 +00:00
|
|
|
|
using System.Threading;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
2013-07-04 00:11:11 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.EntryPoints
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class WebSocketEvents
|
|
|
|
|
/// </summary>
|
2013-10-03 18:02:23 +00:00
|
|
|
|
public class ServerEventNotifier : IServerEntryPoint
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _server manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IServerManager _serverManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _user manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _installation manager
|
|
|
|
|
/// </summary>
|
2013-03-05 04:25:27 +00:00
|
|
|
|
private readonly IInstallationManager _installationManager;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _kernel
|
|
|
|
|
/// </summary>
|
2013-03-07 05:34:00 +00:00
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
|
|
2013-04-15 18:45:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _task manager
|
|
|
|
|
/// </summary>
|
2013-03-07 05:34:00 +00:00
|
|
|
|
private readonly ITaskManager _taskManager;
|
2013-04-15 18:45:58 +00:00
|
|
|
|
|
2013-10-03 18:02:23 +00:00
|
|
|
|
private readonly ISessionManager _sessionManager;
|
2015-01-28 04:04:26 +00:00
|
|
|
|
private readonly ISyncManager _syncManager;
|
2013-10-03 01:22:50 +00:00
|
|
|
|
|
2015-01-28 04:04:26 +00:00
|
|
|
|
public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, ISessionManager sessionManager, ISyncManager syncManager)
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
|
|
|
|
_serverManager = serverManager;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_installationManager = installationManager;
|
2013-03-07 05:34:00 +00:00
|
|
|
|
_appHost = appHost;
|
|
|
|
|
_taskManager = taskManager;
|
2013-10-03 01:22:50 +00:00
|
|
|
|
_sessionManager = sessionManager;
|
2015-01-28 04:04:26 +00:00
|
|
|
|
_syncManager = syncManager;
|
2013-03-05 04:25:27 +00:00
|
|
|
|
}
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
2013-03-05 04:25:27 +00:00
|
|
|
|
public void Run()
|
|
|
|
|
{
|
2013-03-01 21:22:34 +00:00
|
|
|
|
_userManager.UserDeleted += userManager_UserDeleted;
|
|
|
|
|
_userManager.UserUpdated += userManager_UserUpdated;
|
2014-06-22 05:52:31 +00:00
|
|
|
|
_userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
2013-03-07 05:34:00 +00:00
|
|
|
|
_appHost.HasPendingRestartChanged += kernel_HasPendingRestartChanged;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
2013-03-05 04:25:27 +00:00
|
|
|
|
_installationManager.PluginUninstalled += InstallationManager_PluginUninstalled;
|
2013-07-06 21:23:32 +00:00
|
|
|
|
_installationManager.PackageInstalling += _installationManager_PackageInstalling;
|
|
|
|
|
_installationManager.PackageInstallationCancelled += _installationManager_PackageInstallationCancelled;
|
|
|
|
|
_installationManager.PackageInstallationCompleted += _installationManager_PackageInstallationCompleted;
|
|
|
|
|
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
|
2013-03-07 05:34:00 +00:00
|
|
|
|
|
|
|
|
|
_taskManager.TaskCompleted += _taskManager_TaskCompleted;
|
2015-01-28 04:04:26 +00:00
|
|
|
|
_syncManager.SyncJobCreated += _syncManager_SyncJobCreated;
|
2015-02-04 19:13:00 +00:00
|
|
|
|
_syncManager.SyncJobCancelled += _syncManager_SyncJobCancelled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _syncManager_SyncJobCancelled(object sender, GenericEventArgs<SyncJob> e)
|
|
|
|
|
{
|
|
|
|
|
_sessionManager.SendMessageToUserDeviceSessions(e.Argument.TargetId, "SyncJobCancelled", e.Argument, CancellationToken.None);
|
2015-01-28 04:04:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _syncManager_SyncJobCreated(object sender, GenericEventArgs<SyncJobCreationResult> e)
|
|
|
|
|
{
|
|
|
|
|
_sessionManager.SendMessageToUserDeviceSessions(e.Argument.Job.TargetId, "SyncJobCreated", e.Argument, CancellationToken.None);
|
2013-03-07 05:34:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 21:23:32 +00:00
|
|
|
|
void _installationManager_PackageInstalling(object sender, InstallationEventArgs e)
|
2013-03-07 05:34:00 +00:00
|
|
|
|
{
|
2013-07-06 21:23:32 +00:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstalling", e.InstallationInfo);
|
2013-03-07 05:34:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 21:23:32 +00:00
|
|
|
|
void _installationManager_PackageInstallationCancelled(object sender, InstallationEventArgs e)
|
2013-03-07 05:34:00 +00:00
|
|
|
|
{
|
2013-07-06 21:23:32 +00:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstallationCancelled", e.InstallationInfo);
|
2013-03-01 21:22:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 21:23:32 +00:00
|
|
|
|
void _installationManager_PackageInstallationCompleted(object sender, InstallationEventArgs e)
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
2013-07-06 21:23:32 +00:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstallationCompleted", e.InstallationInfo);
|
2013-03-01 21:22:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 21:23:32 +00:00
|
|
|
|
void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e)
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
2013-07-06 21:23:32 +00:00
|
|
|
|
_serverManager.SendWebSocketMessage("PackageInstallationFailed", e.InstallationInfo);
|
2013-03-01 21:22:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 17:28:03 +00:00
|
|
|
|
void _taskManager_TaskCompleted(object sender, TaskCompletionEventArgs e)
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
2014-05-10 17:28:03 +00:00
|
|
|
|
_serverManager.SendWebSocketMessage("ScheduledTaskEnded", e.Result);
|
2013-03-01 21:22:34 +00: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-10-03 18:02:23 +00:00
|
|
|
|
_sessionManager.SendRestartRequiredNotification(CancellationToken.None);
|
2013-03-01 21:22:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Users the manager_ user updated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The sender.</param>
|
|
|
|
|
/// <param name="e">The e.</param>
|
2013-09-17 02:44:06 +00:00
|
|
|
|
void userManager_UserUpdated(object sender, GenericEventArgs<User> e)
|
2013-03-01 21:22:34 +00:00
|
|
|
|
{
|
2014-08-15 16:35:41 +00:00
|
|
|
|
var dto = _userManager.GetUserDto(e.Argument);
|
2015-01-13 03:46:44 +00:00
|
|
|
|
|
|
|
|
|
SendMessageToUserSession(e.Argument, "UserUpdated", dto);
|
2013-03-01 21:22:34 +00: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)
|
|
|
|
|
{
|
2015-01-13 03:46:44 +00:00
|
|
|
|
SendMessageToUserSession(e.Argument, "UserDeleted", e.Argument.Id.ToString("N"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _userManager_UserConfigurationUpdated(object sender, GenericEventArgs<User> e)
|
|
|
|
|
{
|
|
|
|
|
var dto = _userManager.GetUserDto(e.Argument);
|
|
|
|
|
|
|
|
|
|
SendMessageToUserSession(e.Argument, "UserConfigurationUpdated", dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void SendMessageToUserSession<T>(User user, string name, T data)
|
|
|
|
|
{
|
|
|
|
|
await _sessionManager.SendMessageToUserSessions(user.Id.ToString("N"), name, data, CancellationToken.None);
|
2013-03-01 21:22:34 +00: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;
|
2014-06-22 05:52:31 +00:00
|
|
|
|
_userManager.UserConfigurationUpdated -= _userManager_UserConfigurationUpdated;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
|
|
|
|
_installationManager.PluginUninstalled -= InstallationManager_PluginUninstalled;
|
2013-07-06 21:23:32 +00:00
|
|
|
|
_installationManager.PackageInstalling -= _installationManager_PackageInstalling;
|
|
|
|
|
_installationManager.PackageInstallationCancelled -= _installationManager_PackageInstallationCancelled;
|
|
|
|
|
_installationManager.PackageInstallationCompleted -= _installationManager_PackageInstallationCompleted;
|
|
|
|
|
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
|
2013-03-07 05:34:00 +00:00
|
|
|
|
_appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged;
|
2015-01-28 04:04:26 +00:00
|
|
|
|
_syncManager.SyncJobCreated -= _syncManager_SyncJobCreated;
|
2015-02-04 19:13:00 +00:00
|
|
|
|
_syncManager.SyncJobCancelled -= _syncManager_SyncJobCancelled;
|
2013-03-01 21:22:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|