diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 552091280..23cdf8b7a 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -130,6 +130,7 @@ + diff --git a/MediaBrowser.Api/Sync/SyncJobWebSocketListener.cs b/MediaBrowser.Api/Sync/SyncJobWebSocketListener.cs new file mode 100644 index 000000000..61a26d160 --- /dev/null +++ b/MediaBrowser.Api/Sync/SyncJobWebSocketListener.cs @@ -0,0 +1,120 @@ +using MediaBrowser.Controller.Net; +using MediaBrowser.Controller.Sync; +using MediaBrowser.Model.Events; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Sync; +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace MediaBrowser.Api.Sync +{ + /// + /// Class SessionInfoWebSocketListener + /// + class SyncJobWebSocketListener : BasePeriodicWebSocketListener + { + /// + /// Gets the name. + /// + /// The name. + protected override string Name + { + get { return "SyncJob"; } + } + + private readonly ISyncManager _syncManager; + private string _jobId; + + public SyncJobWebSocketListener(ILogger logger, ISyncManager syncManager) + : base(logger) + { + _syncManager = syncManager; + _syncManager.SyncJobCancelled += _syncManager_SyncJobCancelled; + _syncManager.SyncJobUpdated += _syncManager_SyncJobUpdated; + _syncManager.SyncJobItemCreated += _syncManager_SyncJobItemCreated; + _syncManager.SyncJobItemUpdated += _syncManager_SyncJobItemUpdated; + } + + void _syncManager_SyncJobItemUpdated(object sender, GenericEventArgs e) + { + if (string.Equals(e.Argument.Id, _jobId, StringComparison.Ordinal)) + { + SendData(false); + } + } + + void _syncManager_SyncJobItemCreated(object sender, GenericEventArgs e) + { + if (string.Equals(e.Argument.Id, _jobId, StringComparison.Ordinal)) + { + SendData(true); + } + } + + protected override void ParseMessageParams(string[] values) + { + base.ParseMessageParams(values); + + if (values.Length > 0) + { + _jobId = values[0]; + } + } + + void _syncManager_SyncJobUpdated(object sender, GenericEventArgs e) + { + if (string.Equals(e.Argument.Id, _jobId, StringComparison.Ordinal)) + { + SendData(false); + } + } + + void _syncManager_SyncJobCancelled(object sender, GenericEventArgs e) + { + if (string.Equals(e.Argument.Id, _jobId, StringComparison.Ordinal)) + { + SendData(true); + } + } + + /// + /// Gets the data to send. + /// + /// The state. + /// Task{SystemInfo}. + protected override Task GetDataToSend(WebSocketListenerState state) + { + var job = _syncManager.GetJob(_jobId); + var items = _syncManager.GetJobItems(new SyncJobItemQuery + { + AddMetadata = true, + JobId = _jobId + }); + + var info = new CompleteSyncJobInfo + { + Job = job, + JobItems = items.Items.ToList() + }; + + return Task.FromResult(info); + } + + protected override bool SendOnTimer + { + get + { + return false; + } + } + + protected override void Dispose(bool dispose) + { + _syncManager.SyncJobCancelled -= _syncManager_SyncJobCancelled; + _syncManager.SyncJobUpdated -= _syncManager_SyncJobUpdated; + + base.Dispose(dispose); + } + } +} diff --git a/MediaBrowser.Api/Sync/SyncService.cs b/MediaBrowser.Api/Sync/SyncService.cs index 93d8a8d0a..13c716136 100644 --- a/MediaBrowser.Api/Sync/SyncService.cs +++ b/MediaBrowser.Api/Sync/SyncService.cs @@ -206,7 +206,7 @@ namespace MediaBrowser.Api.Sync { var jobItem = _syncManager.GetJobItem(request.Id); - if (jobItem.Status != SyncJobItemStatus.Transferring) + if (jobItem.Status < SyncJobItemStatus.ReadyToTransfer) { throw new ArgumentException("The job item is not yet ready for transfer."); } @@ -286,7 +286,7 @@ namespace MediaBrowser.Api.Sync { var jobItem = _syncManager.GetJobItem(request.Id); - if (jobItem.Status != SyncJobItemStatus.Transferring) + if (jobItem.Status < SyncJobItemStatus.ReadyToTransfer) { throw new ArgumentException("The job item is not yet ready for transfer."); } diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index a24a42535..318c5fff3 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -846,6 +846,11 @@ namespace MediaBrowser.Controller.Entities BaseItem queryParent, User user) { + if (items == null) + { + throw new ArgumentNullException("items"); + } + if (CollapseBoxSetItems(query, queryParent, user)) { items = BaseItem.CollectionManager.CollapseItemsWithinBoxSets(items, user); diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs index ad9ab90a0..fe0fb3295 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs @@ -81,12 +81,17 @@ namespace MediaBrowser.Controller.MediaEncoding VideoCodec = info.VideoCodec; VideoBitRate = info.VideoBitrate; AudioStreamIndex = info.AudioStreamIndex; - SubtitleStreamIndex = info.SubtitleStreamIndex; MaxRefFrames = info.MaxRefFrames; MaxVideoBitDepth = info.MaxVideoBitDepth; SubtitleMethod = info.SubtitleDeliveryMethod; Cabac = info.Cabac; Context = info.Context; + + if (info.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode || + info.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Embed) + { + SubtitleStreamIndex = info.SubtitleStreamIndex; + } } } } diff --git a/MediaBrowser.Controller/Sync/ISyncManager.cs b/MediaBrowser.Controller/Sync/ISyncManager.cs index 362b9c3bc..dc15a394e 100644 --- a/MediaBrowser.Controller/Sync/ISyncManager.cs +++ b/MediaBrowser.Controller/Sync/ISyncManager.cs @@ -15,7 +15,9 @@ namespace MediaBrowser.Controller.Sync event EventHandler> SyncJobCreated; event EventHandler> SyncJobCancelled; event EventHandler> SyncJobUpdated; - + event EventHandler> SyncJobItemUpdated; + event EventHandler> SyncJobItemCreated; + /// /// Creates the job. /// @@ -35,7 +37,7 @@ namespace MediaBrowser.Controller.Sync /// The query. /// QueryResult<SyncJobItem>. QueryResult GetJobItems(SyncJobItemQuery query); - + /// /// Gets the job. /// @@ -63,7 +65,7 @@ namespace MediaBrowser.Controller.Sync /// The identifier. /// Task. Task CancelJobItem(string id); - + /// /// Cancels the job. /// diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 310170b5f..ba3065bc9 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -1043,6 +1043,9 @@ Session\UserDataChangeInfo.cs + + Sync\CompleteSyncJobInfo.cs + Sync\DeviceFileInfo.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 31d2e6470..8d22f25a9 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -1002,6 +1002,9 @@ Session\UserDataChangeInfo.cs + + Sync\CompleteSyncJobInfo.cs + Sync\DeviceFileInfo.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 9fe138a49..a7d11d507 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -893,6 +893,21 @@ namespace MediaBrowser.Model.ApiClient /// if set to true [keep existing authentication]. void ChangeServerLocation(string address, bool keepExistingAuth = false); + /// + /// Starts the receiving synchronize job updates. + /// + /// The interval ms. + /// The job identifier. + /// Task. + Task StartReceivingSyncJobUpdates(int intervalMs, string jobId); + + /// + /// Stops the receiving synchronize job updates. + /// + /// The interval ms. + /// Task. + Task StopReceivingSyncJobUpdates(int intervalMs); + /// /// Starts the receiving synchronize jobs updates. /// diff --git a/MediaBrowser.Model/ApiClient/IServerEvents.cs b/MediaBrowser.Model/ApiClient/IServerEvents.cs index 311cb8b21..ae2d5d323 100644 --- a/MediaBrowser.Model/ApiClient/IServerEvents.cs +++ b/MediaBrowser.Model/ApiClient/IServerEvents.cs @@ -144,5 +144,9 @@ namespace MediaBrowser.Model.ApiClient /// Occurs when [synchronize jobs updated]. /// event EventHandler>> SyncJobsUpdated; + /// + /// Occurs when [synchronize job updated]. + /// + event EventHandler> SyncJobUpdated; } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 0962cbe7a..c8e09dd82 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -368,6 +368,7 @@ + diff --git a/MediaBrowser.Model/Sync/CompleteSyncJobInfo.cs b/MediaBrowser.Model/Sync/CompleteSyncJobInfo.cs new file mode 100644 index 000000000..52d3fab3c --- /dev/null +++ b/MediaBrowser.Model/Sync/CompleteSyncJobInfo.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Model.Sync +{ + public class CompleteSyncJobInfo + { + public SyncJob Job { get; set; } + public List JobItems { get; set; } + + public CompleteSyncJobInfo() + { + JobItems = new List(); + } + } +} diff --git a/MediaBrowser.Model/Sync/SyncJobItemStatus.cs b/MediaBrowser.Model/Sync/SyncJobItemStatus.cs index 913f9e259..c4e23c63c 100644 --- a/MediaBrowser.Model/Sync/SyncJobItemStatus.cs +++ b/MediaBrowser.Model/Sync/SyncJobItemStatus.cs @@ -5,10 +5,11 @@ namespace MediaBrowser.Model.Sync { Queued = 0, Converting = 1, - Transferring = 2, - Synced = 3, - RemovedFromDevice = 4, - Failed = 5, - Cancelled = 6 + ReadyToTransfer = 2, + Transferring = 3, + Synced = 4, + RemovedFromDevice = 5, + Failed = 6, + Cancelled = 7 } } diff --git a/MediaBrowser.Model/Sync/SyncJobStatus.cs b/MediaBrowser.Model/Sync/SyncJobStatus.cs index 6c0068a8a..ac211a32a 100644 --- a/MediaBrowser.Model/Sync/SyncJobStatus.cs +++ b/MediaBrowser.Model/Sync/SyncJobStatus.cs @@ -5,10 +5,11 @@ namespace MediaBrowser.Model.Sync { Queued = 0, Converting = 1, - Transferring = 2, - Completed = 3, - CompletedWithError = 4, - Failed = 5, - Cancelled = 6 + ReadyToTransfer = 2, + Transferring = 3, + Completed = 4, + CompletedWithError = 5, + Failed = 6, + Cancelled = 7 } } diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 61c24cf54..7b36321f1 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -162,7 +162,8 @@ namespace MediaBrowser.Server.Implementations.Dto { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, - SyncJobItemStatus.Transferring + SyncJobItemStatus.Transferring, + SyncJobItemStatus.ReadyToTransfer } }); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index d7ea444a3..29871d928 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -517,6 +517,11 @@ namespace MediaBrowser.Server.Implementations.Library public IEnumerable ReplaceVideosWithPrimaryVersions(IEnumerable items) { + if (items == null) + { + throw new ArgumentNullException("items"); + } + var dict = new Dictionary(); foreach (var item in items) diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index 5e881e3b6..3fddf274c 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -53,6 +53,7 @@ "SyncJobStatusFailed": "Failed", "SyncJobStatusCancelled": "Cancelled", "SyncJobStatusCompleted": "Synced", + "SyncJobStatusReadyToTransfer": "Ready to Transfer", "SyncJobStatusTransferring": "Transferring", "SyncJobStatusCompletedWithError": "Synced with errors", "LabelCollection": "Collection", @@ -216,8 +217,8 @@ "MessageConfirmRestart": "Are you sure you wish to restart Media Browser Server?", "MessageConfirmShutdown": "Are you sure you wish to shutdown Media Browser Server?", "ButtonUpdateNow": "Update Now", - "ValueItemCount": "{0} item", - "ValueItemCountPlural": "{0} items", + "ValueItemCount": "{0} item", + "ValueItemCountPlural": "{0} items", "NewVersionOfSomethingAvailable": "A new version of {0} is available!", "VersionXIsAvailableForDownload": "Version {0} is now available for download.", "LabelVersionNumber": "Version {0}", diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index c373faf1e..e418448db 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Server.Implementations.Sync { private readonly ILibraryManager _libraryManager; private readonly ISyncRepository _syncRepo; - private readonly ISyncManager _syncManager; + private readonly SyncManager _syncManager; private readonly ILogger _logger; private readonly IUserManager _userManager; private readonly ITVSeriesManager _tvSeriesManager; @@ -38,7 +38,7 @@ namespace MediaBrowser.Server.Implementations.Sync private readonly IConfigurationManager _config; private readonly IFileSystem _fileSystem; - public SyncJobProcessor(ILibraryManager libraryManager, ISyncRepository syncRepo, ISyncManager syncManager, ILogger logger, IUserManager userManager, ITVSeriesManager tvSeriesManager, IMediaEncoder mediaEncoder, ISubtitleEncoder subtitleEncoder, IConfigurationManager config, IFileSystem fileSystem) + public SyncJobProcessor(ILibraryManager libraryManager, ISyncRepository syncRepo, SyncManager syncManager, ILogger logger, IUserManager userManager, ITVSeriesManager tvSeriesManager, IMediaEncoder mediaEncoder, ISubtitleEncoder subtitleEncoder, IConfigurationManager config, IFileSystem fileSystem) { _libraryManager = libraryManager; _syncRepo = syncRepo; @@ -106,6 +106,7 @@ namespace MediaBrowser.Server.Implementations.Sync }; await _syncRepo.Create(jobItem).ConfigureAwait(false); + _syncManager.OnSyncJobItemCreated(jobItem); jobItems.Add(jobItem); } @@ -184,11 +185,19 @@ namespace MediaBrowser.Server.Implementations.Sync { job.Status = SyncJobStatus.Cancelled; } + else if (jobItems.All(i => i.Status == SyncJobItemStatus.ReadyToTransfer)) + { + job.Status = SyncJobStatus.ReadyToTransfer; + } + else if (jobItems.All(i => i.Status == SyncJobItemStatus.Transferring)) + { + job.Status = SyncJobStatus.Transferring; + } else if (jobItems.Any(i => i.Status == SyncJobItemStatus.Converting)) { job.Status = SyncJobStatus.Converting; } - else if (pct >= 100) + else if (jobItems.All(i => i.Status == SyncJobItemStatus.Cancelled || i.Status == SyncJobItemStatus.Failed || i.Status == SyncJobItemStatus.Synced || i.Status == SyncJobItemStatus.RemovedFromDevice)) { if (jobItems.Any(i => i.Status == SyncJobItemStatus.Failed)) { @@ -201,12 +210,12 @@ namespace MediaBrowser.Server.Implementations.Sync } else { - job.Status = SyncJobStatus.Transferring; + job.Status = SyncJobStatus.Queued; } await _syncRepo.Update(job).ConfigureAwait(false); - ((SyncManager)_syncManager).OnSyncJobUpdated(job); + _syncManager.OnSyncJobUpdated(job); } public async Task> GetItemsForSync(SyncCategory? category, string parentId, IEnumerable itemIds, User user, bool unwatchedOnly) @@ -414,7 +423,7 @@ namespace MediaBrowser.Server.Implementations.Sync { jobItem.Status = SyncJobItemStatus.Failed; _logger.Error("Unable to locate library item for JobItem {0}, ItemId {1}", jobItem.Id, jobItem.ItemId); - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); return; } @@ -423,7 +432,7 @@ namespace MediaBrowser.Server.Implementations.Sync { jobItem.Status = SyncJobItemStatus.Failed; _logger.Error("Unable to locate SyncTarget for JobItem {0}, SyncTargetId {1}", jobItem.Id, jobItem.TargetId); - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); return; } @@ -490,7 +499,7 @@ namespace MediaBrowser.Server.Implementations.Sync if (streamInfo.PlayMethod == PlayMethod.Transcode) { // Save the job item now since conversion could take a while - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); try @@ -504,7 +513,7 @@ namespace MediaBrowser.Server.Implementations.Sync if ((DateTime.UtcNow - lastJobUpdate).TotalSeconds >= DatabaseProgressUpdateIntervalSeconds) { jobItem.Progress = pct / 2; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); } }); @@ -528,7 +537,7 @@ namespace MediaBrowser.Server.Implementations.Sync if (jobItem.Status == SyncJobItemStatus.Failed || jobItem.Status == SyncJobItemStatus.Queued) { - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); return; } @@ -555,14 +564,14 @@ namespace MediaBrowser.Server.Implementations.Sync if (externalSubs.Count > 0) { // Save the job item now since conversion could take a while - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await ConvertSubtitles(jobItem, externalSubs, streamInfo, cancellationToken).ConfigureAwait(false); } jobItem.Progress = 50; - jobItem.Status = SyncJobItemStatus.Transferring; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + jobItem.Status = SyncJobItemStatus.ReadyToTransfer; + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); } private bool RequiresExtraction(SubtitleStreamInfo stream, MediaSourceInfo mediaSource) @@ -666,7 +675,7 @@ namespace MediaBrowser.Server.Implementations.Sync } jobItem.Status = SyncJobItemStatus.Converting; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); try @@ -680,7 +689,7 @@ namespace MediaBrowser.Server.Implementations.Sync if ((DateTime.UtcNow - lastJobUpdate).TotalSeconds >= DatabaseProgressUpdateIntervalSeconds) { jobItem.Progress = pct / 2; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); } }); @@ -704,7 +713,7 @@ namespace MediaBrowser.Server.Implementations.Sync if (jobItem.Status == SyncJobItemStatus.Failed || jobItem.Status == SyncJobItemStatus.Queued) { - await _syncRepo.Update(jobItem).ConfigureAwait(false); + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); return; } @@ -729,8 +738,8 @@ namespace MediaBrowser.Server.Implementations.Sync } jobItem.Progress = 50; - jobItem.Status = SyncJobItemStatus.Transferring; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + jobItem.Status = SyncJobItemStatus.ReadyToTransfer; + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); } private async Task Sync(SyncJobItem jobItem, Photo item, DeviceProfile profile, CancellationToken cancellationToken) @@ -738,17 +747,17 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.OutputPath = item.Path; jobItem.Progress = 50; - jobItem.Status = SyncJobItemStatus.Transferring; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + jobItem.Status = SyncJobItemStatus.ReadyToTransfer; + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); } private async Task SyncGeneric(SyncJobItem jobItem, BaseItem item, CancellationToken cancellationToken) { jobItem.OutputPath = item.Path; - + jobItem.Progress = 50; - jobItem.Status = SyncJobItemStatus.Transferring; - await _syncRepo.Update(jobItem).ConfigureAwait(false); + jobItem.Status = SyncJobItemStatus.ReadyToTransfer; + await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); } private async Task DownloadFile(SyncJobItem jobItem, MediaSourceInfo mediaSource, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 6eef268b9..eecbd78d1 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -52,6 +52,8 @@ namespace MediaBrowser.Server.Implementations.Sync public event EventHandler> SyncJobCreated; public event EventHandler> SyncJobCancelled; public event EventHandler> SyncJobUpdated; + public event EventHandler> SyncJobItemUpdated; + public event EventHandler> SyncJobItemCreated; public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func mediaEncoder, IFileSystem fileSystem, Func subtitleEncoder, IConfigurationManager config) { @@ -202,6 +204,32 @@ namespace MediaBrowser.Server.Implementations.Sync } } + internal async Task UpdateSyncJobItemInternal(SyncJobItem jobItem) + { + await _repo.Update(jobItem).ConfigureAwait(false); + + if (SyncJobUpdated != null) + { + EventHelper.FireEventIfNotNull(SyncJobItemUpdated, this, new GenericEventArgs + { + Argument = jobItem + + }, _logger); + } + } + + internal void OnSyncJobItemCreated(SyncJobItem job) + { + if (SyncJobUpdated != null) + { + EventHelper.FireEventIfNotNull(SyncJobItemCreated, this, new GenericEventArgs + { + Argument = job + + }, _logger); + } + } + public async Task> GetJobs(SyncJobQuery query) { var result = _repo.GetJobs(query); @@ -504,7 +532,7 @@ namespace MediaBrowser.Server.Implementations.Sync } } - await _repo.Update(jobItem).ConfigureAwait(false); + await UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); var processor = GetSyncJobProcessor(); @@ -610,7 +638,10 @@ namespace MediaBrowser.Server.Implementations.Sync var jobItemResult = GetJobItems(new SyncJobItemQuery { TargetId = targetId, - Statuses = new List { SyncJobItemStatus.Transferring } + Statuses = new List + { + SyncJobItemStatus.ReadyToTransfer + } }); return jobItemResult.Items @@ -669,7 +700,7 @@ namespace MediaBrowser.Server.Implementations.Sync { // Content is no longer on the device jobItem.Status = SyncJobItemStatus.RemovedFromDevice; - await _repo.Update(jobItem).ConfigureAwait(false); + await UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); } } @@ -761,7 +792,7 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.Progress = 0; jobItem.IsMarkedForRemoval = false; - await _repo.Update(jobItem).ConfigureAwait(false); + await UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); var processor = GetSyncJobProcessor(); @@ -772,7 +803,7 @@ namespace MediaBrowser.Server.Implementations.Sync { var jobItem = _repo.GetJobItem(id); - if (jobItem.Status != SyncJobItemStatus.Queued && jobItem.Status != SyncJobItemStatus.Transferring && jobItem.Status != SyncJobItemStatus.Converting) + if (jobItem.Status != SyncJobItemStatus.Queued && jobItem.Status != SyncJobItemStatus.ReadyToTransfer && jobItem.Status != SyncJobItemStatus.Converting) { throw new ArgumentException("Operation is not valid for this job item"); } @@ -781,7 +812,7 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.Progress = 0; jobItem.IsMarkedForRemoval = true; - await _repo.Update(jobItem).ConfigureAwait(false); + await UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); var processor = GetSyncJobProcessor(); @@ -814,7 +845,7 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.IsMarkedForRemoval = true; - await _repo.Update(jobItem).ConfigureAwait(false); + await UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); var processor = GetSyncJobProcessor(); @@ -832,7 +863,7 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.IsMarkedForRemoval = false; - await _repo.Update(jobItem).ConfigureAwait(false); + await UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); var processor = GetSyncJobProcessor(); diff --git a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs index b68a97817..ccc9508e8 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.Sync public Task Execute(CancellationToken cancellationToken, IProgress progress) { - return new SyncJobProcessor(_libraryManager, _syncRepo, _syncManager, _logger, _userManager, _tvSeriesManager, _mediaEncoder, _subtitleEncoder, _config, _fileSystem) + return new SyncJobProcessor(_libraryManager, _syncRepo, (SyncManager)_syncManager, _logger, _userManager, _tvSeriesManager, _mediaEncoder, _subtitleEncoder, _config, _fileSystem) .Sync(progress, cancellationToken); } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 4b104fe25..1a65fba67 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.559 + 3.0.560 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 40a395a63..d28f98aff 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.559 + 3.0.560 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index 17597b582..d4b030ba1 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.559 + 3.0.560 MediaBrowser.Model - Signed Edition Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index c9a635f64..e5b7a27ba 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.559 + 3.0.560 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +