add SyncJobCreated event
This commit is contained in:
parent
782fe92cf7
commit
5880b34fba
|
@ -181,6 +181,18 @@ namespace MediaBrowser.Controller.Session
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
Task SendMessageToUserSessions<T>(string userId, string name, T data, CancellationToken cancellationToken);
|
Task SendMessageToUserSessions<T>(string userId, string name, T data, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends the message to user device sessions.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="deviceId">The device identifier.</param>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="data">The data.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>Task.</returns>
|
||||||
|
Task SendMessageToUserDeviceSessions<T>(string deviceId, string name, T data,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends the restart required message.
|
/// Sends the restart required message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace MediaBrowser.Controller.Sync
|
||||||
{
|
{
|
||||||
public interface ISyncManager
|
public interface ISyncManager
|
||||||
{
|
{
|
||||||
event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
|
event EventHandler<GenericEventArgs<SyncJobCreationResult>> SyncJobCreated;
|
||||||
event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
|
event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -3,6 +3,7 @@ using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Events;
|
using MediaBrowser.Model.Events;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
using MediaBrowser.Model.Session;
|
using MediaBrowser.Model.Session;
|
||||||
|
using MediaBrowser.Model.Sync;
|
||||||
using MediaBrowser.Model.Tasks;
|
using MediaBrowser.Model.Tasks;
|
||||||
using MediaBrowser.Model.Updates;
|
using MediaBrowser.Model.Updates;
|
||||||
using System;
|
using System;
|
||||||
|
@ -130,5 +131,9 @@ namespace MediaBrowser.Model.ApiClient
|
||||||
/// Occurs when [session ended].
|
/// Occurs when [session ended].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event EventHandler<GenericEventArgs<SessionInfoDto>> SessionEnded;
|
event EventHandler<GenericEventArgs<SessionInfoDto>> SessionEnded;
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when [synchronize job created].
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler<GenericEventArgs<SyncJobCreationResult>> SyncJobCreated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Net;
|
||||||
using MediaBrowser.Controller.Plugins;
|
using MediaBrowser.Controller.Plugins;
|
||||||
using MediaBrowser.Controller.Session;
|
using MediaBrowser.Controller.Session;
|
||||||
|
using MediaBrowser.Controller.Sync;
|
||||||
using MediaBrowser.Model.Events;
|
using MediaBrowser.Model.Events;
|
||||||
|
using MediaBrowser.Model.Sync;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
@ -44,8 +46,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||||
private readonly ITaskManager _taskManager;
|
private readonly ITaskManager _taskManager;
|
||||||
|
|
||||||
private readonly ISessionManager _sessionManager;
|
private readonly ISessionManager _sessionManager;
|
||||||
|
private readonly ISyncManager _syncManager;
|
||||||
|
|
||||||
public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, ISessionManager sessionManager)
|
public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, ISessionManager sessionManager, ISyncManager syncManager)
|
||||||
{
|
{
|
||||||
_serverManager = serverManager;
|
_serverManager = serverManager;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
@ -53,6 +56,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_taskManager = taskManager;
|
_taskManager = taskManager;
|
||||||
_sessionManager = sessionManager;
|
_sessionManager = sessionManager;
|
||||||
|
_syncManager = syncManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
|
@ -70,6 +74,12 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||||
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
|
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
|
||||||
|
|
||||||
_taskManager.TaskCompleted += _taskManager_TaskCompleted;
|
_taskManager.TaskCompleted += _taskManager_TaskCompleted;
|
||||||
|
_syncManager.SyncJobCreated += _syncManager_SyncJobCreated;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _syncManager_SyncJobCreated(object sender, GenericEventArgs<SyncJobCreationResult> e)
|
||||||
|
{
|
||||||
|
_sessionManager.SendMessageToUserDeviceSessions(e.Argument.Job.TargetId, "SyncJobCreated", e.Argument, CancellationToken.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _installationManager_PackageInstalling(object sender, InstallationEventArgs e)
|
void _installationManager_PackageInstalling(object sender, InstallationEventArgs e)
|
||||||
|
@ -178,6 +188,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
|
||||||
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
|
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
|
||||||
|
|
||||||
_appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged;
|
_appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged;
|
||||||
|
_syncManager.SyncJobCreated -= _syncManager_SyncJobCreated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Devices;
|
using MediaBrowser.Controller.Devices;
|
||||||
using MediaBrowser.Controller.Drawing;
|
using MediaBrowser.Controller.Drawing;
|
||||||
using MediaBrowser.Controller.Dto;
|
using MediaBrowser.Controller.Dto;
|
||||||
|
@ -11,7 +10,6 @@ using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.LiveTv;
|
using MediaBrowser.Controller.LiveTv;
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
using MediaBrowser.Controller.Security;
|
using MediaBrowser.Controller.Security;
|
||||||
using MediaBrowser.Controller.Session;
|
using MediaBrowser.Controller.Session;
|
||||||
|
@ -1639,7 +1637,28 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error in SendPlaybackStoppedNotification.", ex);
|
_logger.ErrorException("Error sending message", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, cancellationToken));
|
||||||
|
|
||||||
|
return Task.WhenAll(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SendMessageToUserDeviceSessions<T>(string deviceId, string name, T data,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null && string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||||
|
|
||||||
|
var tasks = sessions.Select(session => Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await session.SessionController.SendMessage(name, data, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error sending message", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, cancellationToken));
|
}, cancellationToken));
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||||
|
|
||||||
private ISyncProvider[] _providers = { };
|
private ISyncProvider[] _providers = { };
|
||||||
|
|
||||||
public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
|
public event EventHandler<GenericEventArgs<SyncJobCreationResult>> SyncJobCreated;
|
||||||
public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
|
public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
|
||||||
|
|
||||||
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func<IDtoService> dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func<IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func<ISubtitleEncoder> subtitleEncoder, IConfigurationManager config)
|
public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func<IDtoService> dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func<IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func<ISubtitleEncoder> subtitleEncoder, IConfigurationManager config)
|
||||||
|
@ -149,26 +149,28 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||||
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress<double>(), CancellationToken.None)
|
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress<double>(), CancellationToken.None)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (SyncJobCreated != null)
|
|
||||||
{
|
|
||||||
EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs<SyncJob>
|
|
||||||
{
|
|
||||||
Argument = job
|
|
||||||
|
|
||||||
}, _logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
jobItemsResult = _repo.GetJobItems(new SyncJobItemQuery
|
jobItemsResult = _repo.GetJobItems(new SyncJobItemQuery
|
||||||
{
|
{
|
||||||
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting },
|
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting },
|
||||||
JobId = jobId
|
JobId = jobId
|
||||||
});
|
});
|
||||||
|
|
||||||
return new SyncJobCreationResult
|
var returnResult = new SyncJobCreationResult
|
||||||
{
|
{
|
||||||
Job = GetJob(jobId),
|
Job = GetJob(jobId),
|
||||||
JobItems = jobItemsResult.Items.ToList()
|
JobItems = jobItemsResult.Items.ToList()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (SyncJobCreated != null)
|
||||||
|
{
|
||||||
|
EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs<SyncJobCreationResult>
|
||||||
|
{
|
||||||
|
Argument = returnResult
|
||||||
|
|
||||||
|
}, _logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateJob(SyncJob job)
|
public Task UpdateJob(SyncJob job)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user