2016-06-08 02:21:13 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.EntryPoints
|
|
|
|
|
{
|
|
|
|
|
public class RecordingNotifier : IServerEntryPoint
|
|
|
|
|
{
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
public RecordingNotifier(ISessionManager sessionManager, IUserManager userManager, ILogger logger, ILiveTvManager liveTvManager)
|
|
|
|
|
{
|
|
|
|
|
_sessionManager = sessionManager;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
|
{
|
|
|
|
|
_liveTvManager.TimerCancelled += _liveTvManager_TimerCancelled;
|
|
|
|
|
_liveTvManager.SeriesTimerCancelled += _liveTvManager_SeriesTimerCancelled;
|
|
|
|
|
_liveTvManager.TimerCreated += _liveTvManager_TimerCreated;
|
|
|
|
|
_liveTvManager.SeriesTimerCreated += _liveTvManager_SeriesTimerCreated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _liveTvManager_SeriesTimerCreated(object sender, Model.Events.GenericEventArgs<TimerEventInfo> e)
|
|
|
|
|
{
|
2016-06-08 11:22:10 -04:00
|
|
|
|
SendMessage("SeriesTimerCreated", e.Argument);
|
2016-06-08 02:21:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _liveTvManager_TimerCreated(object sender, Model.Events.GenericEventArgs<TimerEventInfo> e)
|
|
|
|
|
{
|
2016-06-08 11:22:10 -04:00
|
|
|
|
SendMessage("TimerCreated", e.Argument);
|
2016-06-08 02:21:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _liveTvManager_SeriesTimerCancelled(object sender, Model.Events.GenericEventArgs<TimerEventInfo> e)
|
|
|
|
|
{
|
2016-06-08 11:22:10 -04:00
|
|
|
|
SendMessage("SeriesTimerCancelled", e.Argument);
|
2016-06-08 02:21:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _liveTvManager_TimerCancelled(object sender, Model.Events.GenericEventArgs<TimerEventInfo> e)
|
|
|
|
|
{
|
2016-06-08 11:22:10 -04:00
|
|
|
|
SendMessage("TimerCancelled", e.Argument);
|
2016-06-08 02:21:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void SendMessage(string name, TimerEventInfo info)
|
|
|
|
|
{
|
2016-08-20 14:43:13 -04:00
|
|
|
|
var users = _userManager.Users.Where(i => i.Policy.EnableLiveTvAccess).Select(i => i.Id.ToString("N")).ToList();
|
2016-06-08 02:21:13 -04:00
|
|
|
|
|
2016-08-20 14:43:13 -04:00
|
|
|
|
try
|
2016-06-08 02:21:13 -04:00
|
|
|
|
{
|
2016-08-20 14:43:13 -04:00
|
|
|
|
await _sessionManager.SendMessageToUserSessions<TimerEventInfo>(users, name, info, CancellationToken.None);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error sending message", ex);
|
2016-06-08 02:21:13 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_liveTvManager.TimerCancelled -= _liveTvManager_TimerCancelled;
|
|
|
|
|
_liveTvManager.SeriesTimerCancelled -= _liveTvManager_SeriesTimerCancelled;
|
|
|
|
|
_liveTvManager.TimerCreated -= _liveTvManager_TimerCreated;
|
|
|
|
|
_liveTvManager.SeriesTimerCreated -= _liveTvManager_SeriesTimerCreated;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|