2016-08-19 15:56:32 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using MediaBrowser.Controller.Sync;
|
|
|
|
|
using MediaBrowser.Model.Events;
|
|
|
|
|
using MediaBrowser.Model.Sync;
|
|
|
|
|
|
2016-11-03 15:34:16 -07:00
|
|
|
|
namespace Emby.Server.Implementations.Sync
|
2016-08-19 15:56:32 -07:00
|
|
|
|
{
|
|
|
|
|
public class SyncNotificationEntryPoint : IServerEntryPoint
|
|
|
|
|
{
|
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
|
private readonly ISyncManager _syncManager;
|
|
|
|
|
|
|
|
|
|
public SyncNotificationEntryPoint(ISyncManager syncManager, ISessionManager sessionManager)
|
|
|
|
|
{
|
|
|
|
|
_syncManager = syncManager;
|
|
|
|
|
_sessionManager = sessionManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
|
{
|
|
|
|
|
_syncManager.SyncJobItemUpdated += _syncManager_SyncJobItemUpdated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void _syncManager_SyncJobItemUpdated(object sender, GenericEventArgs<SyncJobItem> e)
|
|
|
|
|
{
|
|
|
|
|
var item = e.Argument;
|
|
|
|
|
|
|
|
|
|
if (item.Status == SyncJobItemStatus.ReadyToTransfer)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _sessionManager.SendMessageToUserDeviceSessions(item.TargetId, "SyncJobItemReady", item, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-20 14:40:07 -07:00
|
|
|
|
|
|
|
|
|
if (item.Status == SyncJobItemStatus.Cancelled)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _sessionManager.SendMessageToUserDeviceSessions(item.TargetId, "SyncJobItemCancelled", item, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-19 15:56:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_syncManager.SyncJobItemUpdated -= _syncManager_SyncJobItemUpdated;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|