@ -8,13 +8,10 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.Plugins ;
using MediaBrowser.Controller.Updates ;
using MediaBrowser.Model.Entities ;
using MediaBrowser.Model.Logging ;
using MediaBrowser.Model.Tasks ;
using MediaBrowser.Model.Updates ;
using System ;
using System.Linq ;
using System.Threading ;
namespace MediaBrowser.ServerApplication.EntryPoints
{
@ -37,11 +34,6 @@ namespace MediaBrowser.ServerApplication.EntryPoints
/// </summary>
private readonly IUserManager _userManager ;
/// <summary>
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager ;
/// <summary>
/// The _installation manager
/// </summary>
@ -57,40 +49,17 @@ namespace MediaBrowser.ServerApplication.EntryPoints
/// </summary>
private readonly ITaskManager _taskManager ;
/// <summary>
/// The _library changed sync lock
/// </summary>
private readonly object _libraryChangedSyncLock = new object ( ) ;
/// <summary>
/// Gets or sets the library update info.
/// </summary>
/// <value>The library update info.</value>
private LibraryUpdateInfo LibraryUpdateInfo { get ; set ; }
/// <summary>
/// Gets or sets the library update timer.
/// </summary>
/// <value>The library update timer.</value>
private Timer LibraryUpdateTimer { get ; set ; }
/// <summary>
/// The library update duration
/// </summary>
private const int LibraryUpdateDuration = 60000 ;
/// <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>
public WebSocketEvents ( IServerManager serverManager , IServerApplicationHost appHost , ILogger logger , IUserManager userManager , I LibraryManager libraryManager , I InstallationManager installationManager , ITaskManager taskManager )
public WebSocketEvents ( IServerManager serverManager , IServerApplicationHost appHost , ILogger logger , IUserManager userManager , IInstallationManager installationManager , ITaskManager taskManager )
{
_serverManager = serverManager ;
_logger = logger ;
_userManager = userManager ;
_libraryManager = libraryManager ;
_installationManager = installationManager ;
_appHost = appHost ;
_taskManager = taskManager ;
@ -103,10 +72,6 @@ namespace MediaBrowser.ServerApplication.EntryPoints
_appHost . HasPendingRestartChanged + = kernel_HasPendingRestartChanged ;
_libraryManager . ItemAdded + = libraryManager_ItemAdded ;
_libraryManager . ItemUpdated + = libraryManager_ItemUpdated ;
_libraryManager . ItemRemoved + = libraryManager_ItemRemoved ;
_installationManager . PluginUninstalled + = InstallationManager_PluginUninstalled ;
_installationManager . PackageInstalling + = installationManager_PackageInstalling ;
_installationManager . PackageInstallationCancelled + = installationManager_PackageInstallationCancelled ;
@ -168,130 +133,6 @@ namespace MediaBrowser.ServerApplication.EntryPoints
_serverManager . SendWebSocketMessage ( "PackageInstalling" , e . Argument ) ;
}
/// <summary>
/// Handles the ItemAdded event of the libraryManager control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void libraryManager_ItemAdded ( object sender , ItemChangeEventArgs e )
{
lock ( _libraryChangedSyncLock )
{
if ( LibraryUpdateInfo = = null )
{
LibraryUpdateInfo = new LibraryUpdateInfo ( ) ;
}
if ( LibraryUpdateTimer = = null )
{
LibraryUpdateTimer = new Timer ( LibraryUpdateTimerCallback , null , LibraryUpdateDuration ,
Timeout . Infinite ) ;
}
else
{
LibraryUpdateTimer . Change ( LibraryUpdateDuration , Timeout . Infinite ) ;
}
if ( e . Item . Parent ! = null )
{
LibraryUpdateInfo . FoldersAddedTo . Add ( e . Item . Parent . Id ) ;
}
LibraryUpdateInfo . ItemsAdded . Add ( e . Item . Id ) ;
}
}
/// <summary>
/// Handles the ItemUpdated event of the libraryManager control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void libraryManager_ItemUpdated ( object sender , ItemChangeEventArgs e )
{
lock ( _libraryChangedSyncLock )
{
if ( LibraryUpdateInfo = = null )
{
LibraryUpdateInfo = new LibraryUpdateInfo ( ) ;
}
if ( LibraryUpdateTimer = = null )
{
LibraryUpdateTimer = new Timer ( LibraryUpdateTimerCallback , null , LibraryUpdateDuration ,
Timeout . Infinite ) ;
}
else
{
LibraryUpdateTimer . Change ( LibraryUpdateDuration , Timeout . Infinite ) ;
}
LibraryUpdateInfo . ItemsUpdated . Add ( e . Item . Id ) ;
}
}
/// <summary>
/// Handles the ItemRemoved event of the libraryManager control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void libraryManager_ItemRemoved ( object sender , ItemChangeEventArgs e )
{
lock ( _libraryChangedSyncLock )
{
if ( LibraryUpdateInfo = = null )
{
LibraryUpdateInfo = new LibraryUpdateInfo ( ) ;
}
if ( LibraryUpdateTimer = = null )
{
LibraryUpdateTimer = new Timer ( LibraryUpdateTimerCallback , null , LibraryUpdateDuration ,
Timeout . Infinite ) ;
}
else
{
LibraryUpdateTimer . Change ( LibraryUpdateDuration , Timeout . Infinite ) ;
}
if ( e . Item . Parent ! = null )
{
LibraryUpdateInfo . FoldersRemovedFrom . Add ( e . Item . Parent . Id ) ;
}
LibraryUpdateInfo . ItemsRemoved . Add ( e . Item . Id ) ;
}
}
/// <summary>
/// Libraries the update timer callback.
/// </summary>
/// <param name="state">The state.</param>
private void LibraryUpdateTimerCallback ( object state )
{
lock ( _libraryChangedSyncLock )
{
// Remove dupes in case some were saved multiple times
LibraryUpdateInfo . FoldersAddedTo = LibraryUpdateInfo . FoldersAddedTo . Distinct ( ) . ToList ( ) ;
LibraryUpdateInfo . FoldersRemovedFrom = LibraryUpdateInfo . FoldersRemovedFrom . Distinct ( ) . ToList ( ) ;
LibraryUpdateInfo . ItemsUpdated = LibraryUpdateInfo . ItemsUpdated
. Where ( i = > ! LibraryUpdateInfo . ItemsAdded . Contains ( i ) )
. Distinct ( )
. ToList ( ) ;
_serverManager . SendWebSocketMessage ( "LibraryChanged" , LibraryUpdateInfo ) ;
if ( LibraryUpdateTimer ! = null )
{
LibraryUpdateTimer . Dispose ( ) ;
LibraryUpdateTimer = null ;
}
LibraryUpdateInfo = null ;
}
}
/// <summary>
/// Installations the manager_ plugin uninstalled.
/// </summary>
@ -350,16 +191,6 @@ namespace MediaBrowser.ServerApplication.EntryPoints
{
if ( dispose )
{
if ( LibraryUpdateTimer ! = null )
{
LibraryUpdateTimer . Dispose ( ) ;
LibraryUpdateTimer = null ;
}
_libraryManager . ItemAdded - = libraryManager_ItemAdded ;
_libraryManager . ItemUpdated - = libraryManager_ItemUpdated ;
_libraryManager . ItemRemoved - = libraryManager_ItemRemoved ;
_userManager . UserDeleted - = userManager_UserDeleted ;
_userManager . UserUpdated - = userManager_UserUpdated ;