mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-08 20:38:24 +02:00
This commit includes changes to enable and stabilize asyncronous operation in the auto-organize area. Here are the key points: - The auto-organize correction dialog is now closed (almost) instantly. This means that the user does not have to wait until the file copy/move operation is completed in order to continue. (even with local HDs the copy/move process can take several minutes or even much longer with network destination). - This commit also implements locking of files to be organized in order to prevent parallel processing of the same item. In effect, there can be 2 or more manual organization operations active even while the normal auto-organization task is running without causing any problems - The items that are currently being processed are indicated as such in the log with an orange color and a spinner graphic - The client display is refreshed through websocket messages - A side effect of this is that other clients showing the auto-organize log at the same time are always up-to-date as well
68 lines
2.7 KiB
C#
68 lines
2.7 KiB
C#
using MediaBrowser.Controller.FileOrganization;
|
|
using MediaBrowser.Controller.Plugins;
|
|
using MediaBrowser.Model.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using MediaBrowser.Model.Events;
|
|
using MediaBrowser.Model.FileOrganization;
|
|
using MediaBrowser.Controller.Session;
|
|
using System.Threading;
|
|
|
|
namespace MediaBrowser.Server.Implementations.FileOrganization
|
|
{
|
|
/// <summary>
|
|
/// Class SessionInfoWebSocketListener
|
|
/// </summary>
|
|
class FileOrganizationNotifier : IServerEntryPoint
|
|
{
|
|
private readonly IFileOrganizationService _organizationService;
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
public FileOrganizationNotifier(ILogger logger, IFileOrganizationService organizationService, ISessionManager sessionManager)
|
|
{
|
|
_organizationService = organizationService;
|
|
_sessionManager = sessionManager;
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
_organizationService.ItemAdded += _organizationService_ItemAdded;
|
|
_organizationService.ItemRemoved += _organizationService_ItemRemoved;
|
|
_organizationService.ItemUpdated += _organizationService_ItemUpdated;
|
|
_organizationService.LogReset += _organizationService_LogReset;
|
|
}
|
|
|
|
private void _organizationService_LogReset(object sender, EventArgs e)
|
|
{
|
|
_sessionManager.SendMessageToAdminSessions("AutoOrganizeUpdate", (FileOrganizationResult)null, CancellationToken.None);
|
|
}
|
|
|
|
private void _organizationService_ItemUpdated(object sender, GenericEventArgs<FileOrganizationResult> e)
|
|
{
|
|
_sessionManager.SendMessageToAdminSessions("AutoOrganizeUpdate", e.Argument, CancellationToken.None);
|
|
}
|
|
|
|
private void _organizationService_ItemRemoved(object sender, GenericEventArgs<FileOrganizationResult> e)
|
|
{
|
|
_sessionManager.SendMessageToAdminSessions("AutoOrganizeUpdate", (FileOrganizationResult)null, CancellationToken.None);
|
|
}
|
|
|
|
private void _organizationService_ItemAdded(object sender, GenericEventArgs<FileOrganizationResult> e)
|
|
{
|
|
_sessionManager.SendMessageToAdminSessions("AutoOrganizeUpdate", (FileOrganizationResult)null, CancellationToken.None);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_organizationService.ItemAdded -= _organizationService_ItemAdded;
|
|
_organizationService.ItemRemoved -= _organizationService_ItemRemoved;
|
|
_organizationService.ItemUpdated -= _organizationService_ItemUpdated;
|
|
_organizationService.LogReset -= _organizationService_LogReset;
|
|
}
|
|
|
|
|
|
}
|
|
}
|