add SyncJobCreated event

pull/702/head
Luke Pulverenti 10 years ago
parent 782fe92cf7
commit 5880b34fba

@ -180,6 +180,18 @@ namespace MediaBrowser.Controller.Session
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
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>
/// Sends the restart required message.

@ -12,7 +12,7 @@ namespace MediaBrowser.Controller.Sync
{
public interface ISyncManager
{
event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
event EventHandler<GenericEventArgs<SyncJobCreationResult>> SyncJobCreated;
event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
/// <summary>

@ -3,6 +3,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Session;
using MediaBrowser.Model.Sync;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
using System;
@ -130,5 +131,9 @@ namespace MediaBrowser.Model.ApiClient
/// Occurs when [session ended].
/// </summary>
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.Plugins;
using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Sync;
using System;
using System.Threading;
@ -44,8 +46,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private readonly ITaskManager _taskManager;
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;
_userManager = userManager;
@ -53,6 +56,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_appHost = appHost;
_taskManager = taskManager;
_sessionManager = sessionManager;
_syncManager = syncManager;
}
public void Run()
@ -70,6 +74,12 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
_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)
@ -178,6 +188,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
_appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged;
_syncManager.SyncJobCreated -= _syncManager_SyncJobCreated;
}
}
}

@ -2,7 +2,6 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
@ -11,7 +10,6 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Session;
@ -1639,7 +1637,28 @@ namespace MediaBrowser.Server.Implementations.Session
}
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));

@ -49,7 +49,7 @@ namespace MediaBrowser.Server.Implementations.Sync
private ISyncProvider[] _providers = { };
public event EventHandler<GenericEventArgs<SyncJob>> SyncJobCreated;
public event EventHandler<GenericEventArgs<SyncJobCreationResult>> SyncJobCreated;
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)
@ -103,14 +103,14 @@ namespace MediaBrowser.Server.Implementations.Sync
var target = GetSyncTargets(request.UserId)
.FirstOrDefault(i => string.Equals(request.TargetId, i.Id));
if (target == null)
{
throw new ArgumentException("Sync target not found.");
}
var jobId = Guid.NewGuid().ToString("N");
var job = new SyncJob
{
Id = jobId,
@ -149,26 +149,28 @@ namespace MediaBrowser.Server.Implementations.Sync
await processor.SyncJobItems(jobItemsResult.Items, false, new Progress<double>(), CancellationToken.None)
.ConfigureAwait(false);
if (SyncJobCreated != null)
{
EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs<SyncJob>
{
Argument = job
}, _logger);
}
jobItemsResult = _repo.GetJobItems(new SyncJobItemQuery
{
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting },
JobId = jobId
});
return new SyncJobCreationResult
var returnResult = new SyncJobCreationResult
{
Job = GetJob(jobId),
JobItems = jobItemsResult.Items.ToList()
};
if (SyncJobCreated != null)
{
EventHelper.FireEventIfNotNull(SyncJobCreated, this, new GenericEventArgs<SyncJobCreationResult>
{
Argument = returnResult
}, _logger);
}
return returnResult;
}
public Task UpdateJob(SyncJob job)

Loading…
Cancel
Save