2016-03-27 21:11:27 +00:00
|
|
|
|
using MediaBrowser.Common.ScheduledTasks;
|
2014-12-26 19:34:39 +00:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2014-05-10 17:28:03 +00:00
|
|
|
|
using MediaBrowser.Model.Events;
|
2013-02-21 20:26:35 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Tasks;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2013-02-22 04:23:06 +00:00
|
|
|
|
namespace MediaBrowser.Api.ScheduledTasks
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ScheduledTasksWebSocketListener
|
|
|
|
|
/// </summary>
|
2014-05-10 17:28:03 +00:00
|
|
|
|
public class ScheduledTasksWebSocketListener : BasePeriodicWebSocketListener<IEnumerable<TaskInfo>, WebSocketListenerState>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-23 07:57:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the task manager.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The task manager.</value>
|
|
|
|
|
private ITaskManager TaskManager { get; set; }
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The name.</value>
|
|
|
|
|
protected override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "ScheduledTasksInfo"; }
|
|
|
|
|
}
|
2013-02-21 20:26:35 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ScheduledTasksWebSocketListener" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
2013-02-23 07:57:11 +00:00
|
|
|
|
/// <param name="taskManager">The task manager.</param>
|
|
|
|
|
public ScheduledTasksWebSocketListener(ILogger logger, ITaskManager taskManager)
|
2013-02-21 20:26:35 +00:00
|
|
|
|
: base(logger)
|
|
|
|
|
{
|
2013-02-23 07:57:11 +00:00
|
|
|
|
TaskManager = taskManager;
|
2014-05-10 17:28:03 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2013-02-21 20:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the data to send.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
|
/// <returns>Task{IEnumerable{TaskInfo}}.</returns>
|
2014-05-10 17:28:03 +00:00
|
|
|
|
protected override Task<IEnumerable<TaskInfo>> GetDataToSend(WebSocketListenerState state)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-05-09 23:08:08 +00:00
|
|
|
|
return Task.FromResult(TaskManager.ScheduledTasks
|
2013-11-29 16:58:24 +00:00
|
|
|
|
.OrderBy(i => i.Name)
|
|
|
|
|
.Select(ScheduledTaskHelpers.GetTaskInfo)
|
|
|
|
|
.Where(i => !i.IsHidden));
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2014-05-10 17:28:03 +00:00
|
|
|
|
|
|
|
|
|
protected override bool SendOnTimer
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-14 00:46:45 +00:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool dispose)
|
|
|
|
|
{
|
|
|
|
|
TaskManager.TaskExecuting -= TaskManager_TaskExecuting;
|
|
|
|
|
TaskManager.TaskCompleted -= TaskManager_TaskCompleted;
|
|
|
|
|
|
|
|
|
|
base.Dispose(dispose);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|