move WebSocket listeners to Jellyfin.Api

This commit is contained in:
crobibero 2020-08-03 13:09:32 -06:00
parent a28d00eeba
commit cfce1dba08
3 changed files with 56 additions and 47 deletions

View File

@ -5,34 +5,35 @@ using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Events;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.System
namespace Jellyfin.Api.WebSocketListeners
{
/// <summary>
/// Class SessionInfoWebSocketListener.
/// </summary>
public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener<ActivityLogEntry[], WebSocketListenerState>
{
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
protected override string Name => "ActivityLogEntry";
/// <summary>
/// The _kernel.
/// </summary>
private readonly IActivityManager _activityManager;
public ActivityLogWebSocketListener(ILogger<ActivityLogWebSocketListener> logger, IActivityManager activityManager) : base(logger)
/// <summary>
/// Initializes a new instance of the <see cref="ActivityLogWebSocketListener"/> class.
/// </summary>
/// <param name="logger">Instance of the <see cref="ILogger{ActivityLogWebSocketListener}"/> interface.</param>
/// <param name="activityManager">Instance of the <see cref="IActivityManager"/> interface.</param>
public ActivityLogWebSocketListener(ILogger<ActivityLogWebSocketListener> logger, IActivityManager activityManager)
: base(logger)
{
_activityManager = activityManager;
_activityManager.EntryCreated += OnEntryCreated;
}
private void OnEntryCreated(object sender, GenericEventArgs<ActivityLogEntry> e)
{
SendData(true);
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
protected override string Name => "ActivityLogEntry";
/// <summary>
/// Gets the data to send.
@ -50,5 +51,10 @@ namespace MediaBrowser.Api.System
base.Dispose(dispose);
}
private void OnEntryCreated(object sender, GenericEventArgs<ActivityLogEntry> e)
{
SendData(true);
}
}
}

View File

@ -6,7 +6,7 @@ using MediaBrowser.Model.Events;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.ScheduledTasks
namespace Jellyfin.Api.WebSocketListeners
{
/// <summary>
/// Class ScheduledTasksWebSocketListener.
@ -17,7 +17,21 @@ namespace MediaBrowser.Api.ScheduledTasks
/// Gets or sets the task manager.
/// </summary>
/// <value>The task manager.</value>
private ITaskManager TaskManager { get; set; }
private readonly ITaskManager _taskManager;
/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTasksWebSocketListener"/> class.
/// </summary>
/// <param name="logger">Instance of the <see cref="ILogger{ScheduledTasksWebSocketListener}"/> interface.</param>
/// <param name="taskManager">Instance of the <see cref="ITaskManager"/> interface.</param>
public ScheduledTasksWebSocketListener(ILogger<ScheduledTasksWebSocketListener> logger, ITaskManager taskManager)
: base(logger)
{
_taskManager = taskManager;
_taskManager.TaskExecuting += OnTaskExecuting;
_taskManager.TaskCompleted += OnTaskCompleted;
}
/// <summary>
/// Gets the name.
@ -25,53 +39,42 @@ namespace MediaBrowser.Api.ScheduledTasks
/// <value>The name.</value>
protected override string Name => "ScheduledTasksInfo";
/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTasksWebSocketListener" /> class.
/// </summary>
public ScheduledTasksWebSocketListener(ILogger<ScheduledTasksWebSocketListener> logger, ITaskManager taskManager)
: base(logger)
{
TaskManager = taskManager;
TaskManager.TaskExecuting += TaskManager_TaskExecuting;
TaskManager.TaskCompleted += TaskManager_TaskCompleted;
}
void TaskManager_TaskCompleted(object sender, TaskCompletionEventArgs e)
{
SendData(true);
e.Task.TaskProgress -= Argument_TaskProgress;
}
void TaskManager_TaskExecuting(object sender, GenericEventArgs<IScheduledTaskWorker> e)
{
SendData(true);
e.Argument.TaskProgress += Argument_TaskProgress;
}
void Argument_TaskProgress(object sender, GenericEventArgs<double> e)
{
SendData(false);
}
/// <summary>
/// Gets the data to send.
/// </summary>
/// <returns>Task{IEnumerable{TaskInfo}}.</returns>
protected override Task<IEnumerable<TaskInfo>> GetDataToSend()
{
return Task.FromResult(TaskManager.ScheduledTasks
return Task.FromResult(_taskManager.ScheduledTasks
.OrderBy(i => i.Name)
.Select(ScheduledTaskHelpers.GetTaskInfo)
.Where(i => !i.IsHidden));
}
/// <inheritdoc />
protected override void Dispose(bool dispose)
{
TaskManager.TaskExecuting -= TaskManager_TaskExecuting;
TaskManager.TaskCompleted -= TaskManager_TaskCompleted;
_taskManager.TaskExecuting -= OnTaskExecuting;
_taskManager.TaskCompleted -= OnTaskCompleted;
base.Dispose(dispose);
}
private void OnTaskCompleted(object sender, TaskCompletionEventArgs e)
{
SendData(true);
e.Task.TaskProgress -= OnTaskProgress;
}
private void OnTaskExecuting(object sender, GenericEventArgs<IScheduledTaskWorker> e)
{
SendData(true);
e.Argument.TaskProgress += OnTaskProgress;
}
private void OnTaskProgress(object sender, GenericEventArgs<double> e)
{
SendData(false);
}
}
}

View File

@ -5,7 +5,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Sessions
namespace Jellyfin.Api.WebSocketListeners
{
/// <summary>
/// Class SessionInfoWebSocketListener.