@ -16,33 +16,46 @@ using MediaBrowser.Model.Tasks;
namespace Emby.Server.Implementations.EntryPoints
{
/// <summary>
/// Class WebSocketEvents
/// Class WebSocketEvents .
/// </summary>
public class ServerEventNotifier : IServerEntryPoint
{
/// <summary>
/// The _ user manager
/// The user manager.
/// </summary>
private readonly IUserManager _userManager ;
/// <summary>
/// The _ installation manager
/// The installation manager.
/// </summary>
private readonly IInstallationManager _installationManager ;
/// <summary>
/// The _ kernel
/// The kernel.
/// </summary>
private readonly IServerApplicationHost _appHost ;
/// <summary>
/// The _ task manager
/// The task manager.
/// </summary>
private readonly ITaskManager _taskManager ;
private readonly ISessionManager _sessionManager ;
public ServerEventNotifier ( IServerApplicationHost appHost , IUserManager userManager , IInstallationManager installationManager , ITaskManager taskManager , ISessionManager sessionManager )
/// <summary>
/// Initializes a new instance of the <see cref="ServerEventNotifier"/> class.
/// </summary>
/// <param name="appHost">The application host.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="installationManager">The installation manager.</param>
/// <param name="taskManager">The task manager.</param>
/// <param name="sessionManager">The session manager.</param>
public ServerEventNotifier (
IServerApplicationHost appHost ,
IUserManager userManager ,
IInstallationManager installationManager ,
ITaskManager taskManager ,
ISessionManager sessionManager )
{
_userManager = userManager ;
_installationManager = installationManager ;
@ -51,47 +64,48 @@ namespace Emby.Server.Implementations.EntryPoints
_sessionManager = sessionManager ;
}
/// <inheritdoc />
public Task RunAsync ( )
{
_userManager . UserDeleted + = userManager_ UserDeleted;
_userManager . UserUpdated + = userManager_ UserUpdated;
_userManager . UserPolicyUpdated + = _userManager_ UserPolicyUpdated;
_userManager . UserConfigurationUpdated + = _userManager_ UserConfigurationUpdated;
_userManager . UserDeleted + = On UserDeleted;
_userManager . UserUpdated + = On UserUpdated;
_userManager . UserPolicyUpdated + = On UserPolicyUpdated;
_userManager . UserConfigurationUpdated + = On UserConfigurationUpdated;
_appHost . HasPendingRestartChanged + = kernel_ HasPendingRestartChanged;
_appHost . HasPendingRestartChanged + = On HasPendingRestartChanged;
_installationManager . PluginUninstalled + = InstallationManager_ PluginUninstalled;
_installationManager . PackageInstalling + = _installationManager_ PackageInstalling;
_installationManager . PackageInstallationCancelled + = _installationManager_ PackageInstallationCancelled;
_installationManager . PackageInstallationCompleted + = _installationManager_ PackageInstallationCompleted;
_installationManager . PackageInstallationFailed + = _installationManager_ PackageInstallationFailed;
_installationManager . PluginUninstalled + = On PluginUninstalled;
_installationManager . PackageInstalling + = On PackageInstalling;
_installationManager . PackageInstallationCancelled + = On PackageInstallationCancelled;
_installationManager . PackageInstallationCompleted + = On PackageInstallationCompleted;
_installationManager . PackageInstallationFailed + = On PackageInstallationFailed;
_taskManager . TaskCompleted + = _taskManager_ TaskCompleted;
_taskManager . TaskCompleted + = On TaskCompleted;
return Task . CompletedTask ;
}
void _installationManager_ PackageInstalling( object sender , InstallationEventArgs e )
private void On PackageInstalling( object sender , InstallationEventArgs e )
{
SendMessageToAdminSessions ( "PackageInstalling" , e . InstallationInfo ) ;
}
void _installationManager_ PackageInstallationCancelled( object sender , InstallationEventArgs e )
private void On PackageInstallationCancelled( object sender , InstallationEventArgs e )
{
SendMessageToAdminSessions ( "PackageInstallationCancelled" , e . InstallationInfo ) ;
}
void _installationManager_ PackageInstallationCompleted( object sender , InstallationEventArgs e )
private void On PackageInstallationCompleted( object sender , InstallationEventArgs e )
{
SendMessageToAdminSessions ( "PackageInstallationCompleted" , e . InstallationInfo ) ;
}
void _installationManager_ PackageInstallationFailed( object sender , InstallationFailedEventArgs e )
private void On PackageInstallationFailed( object sender , InstallationFailedEventArgs e )
{
SendMessageToAdminSessions ( "PackageInstallationFailed" , e . InstallationInfo ) ;
}
void _taskManager_ TaskCompleted( object sender , TaskCompletionEventArgs e )
private void On TaskCompleted( object sender , TaskCompletionEventArgs e )
{
SendMessageToAdminSessions ( "ScheduledTaskEnded" , e . Result ) ;
}
@ -101,7 +115,7 @@ namespace Emby.Server.Implementations.EntryPoints
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
void InstallationManager_ PluginUninstalled( object sender , GenericEventArgs < IPlugin > e )
private void On PluginUninstalled( object sender , GenericEventArgs < IPlugin > e )
{
SendMessageToAdminSessions ( "PluginUninstalled" , e . Argument . GetPluginInfo ( ) ) ;
}
@ -111,7 +125,7 @@ namespace Emby.Server.Implementations.EntryPoints
/// </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 )
private void On HasPendingRestartChanged( object sender , EventArgs e )
{
_sessionManager . SendRestartRequiredNotification ( CancellationToken . None ) ;
}
@ -121,7 +135,7 @@ namespace Emby.Server.Implementations.EntryPoints
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
void userManager_ UserUpdated( object sender , GenericEventArgs < User > e )
private void On UserUpdated( object sender , GenericEventArgs < User > e )
{
var dto = _userManager . GetUserDto ( e . Argument ) ;
@ -133,19 +147,19 @@ namespace Emby.Server.Implementations.EntryPoints
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
void userManager_ UserDeleted( object sender , GenericEventArgs < User > e )
private void On UserDeleted( object sender , GenericEventArgs < User > e )
{
SendMessageToUserSession ( e . Argument , "UserDeleted" , e . Argument . Id . ToString ( "N" , CultureInfo . InvariantCulture ) ) ;
}
void _userManager_ UserPolicyUpdated( object sender , GenericEventArgs < User > e )
private void On UserPolicyUpdated( object sender , GenericEventArgs < User > e )
{
var dto = _userManager . GetUserDto ( e . Argument ) ;
SendMessageToUserSession ( e . Argument , "UserPolicyUpdated" , dto ) ;
}
void _userManager_ UserConfigurationUpdated( object sender , GenericEventArgs < User > e )
private void On UserConfigurationUpdated( object sender , GenericEventArgs < User > e )
{
var dto = _userManager . GetUserDto ( e . Argument ) ;
@ -168,7 +182,11 @@ namespace Emby.Server.Implementations.EntryPoints
{
try
{
await _sessionManager . SendMessageToUserSessions ( new List < Guid > { user . Id } , name , data , CancellationToken . None ) ;
await _sessionManager . SendMessageToUserSessions (
new List < Guid > { user . Id } ,
name ,
data ,
CancellationToken . None ) . ConfigureAwait ( false ) ;
}
catch ( Exception )
{
@ -176,12 +194,11 @@ namespace Emby.Server.Implementations.EntryPoints
}
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <inheritdoc />
public void Dispose ( )
{
Dispose ( true ) ;
GC . SuppressFinalize ( this ) ;
}
/// <summary>
@ -192,18 +209,20 @@ namespace Emby.Server.Implementations.EntryPoints
{
if ( dispose )
{
_userManager . UserDeleted - = userManager_UserDeleted ;
_userManager . UserUpdated - = userManager_UserUpdated ;
_userManager . UserPolicyUpdated - = _userManager_UserPolicyUpdated ;
_userManager . UserConfigurationUpdated - = _userManager_UserConfigurationUpdated ;
_userManager . UserDeleted - = OnUserDeleted ;
_userManager . UserUpdated - = OnUserUpdated ;
_userManager . UserPolicyUpdated - = OnUserPolicyUpdated ;
_userManager . UserConfigurationUpdated - = OnUserConfigurationUpdated ;
_installationManager . PluginUninstalled - = OnPluginUninstalled ;
_installationManager . PackageInstalling - = OnPackageInstalling ;
_installationManager . PackageInstallationCancelled - = OnPackageInstallationCancelled ;
_installationManager . PackageInstallationCompleted - = OnPackageInstallationCompleted ;
_installationManager . PackageInstallationFailed - = OnPackageInstallationFailed ;
_installationManager . PluginUninstalled - = InstallationManager_PluginUninstalled ;
_installationManager . PackageInstalling - = _installationManager_PackageInstalling ;
_installationManager . PackageInstallationCancelled - = _installationManager_PackageInstallationCancelled ;
_installationManager . PackageInstallationCompleted - = _installationManager_PackageInstallationCompleted ;
_installationManager . PackageInstallationFailed - = _installationManager_PackageInstallationFailed ;
_appHost . HasPendingRestartChanged - = OnHasPendingRestartChanged ;
_ appHost. HasPendingRestartChanged - = kernel_HasPendingRestartChang ed;
_taskManager . TaskCompleted - = OnTaskCompleted ;
}
}
}