diff options
Diffstat (limited to 'Emby.Server.Implementations/Sync')
5 files changed, 104 insertions, 67 deletions
diff --git a/Emby.Server.Implementations/Sync/CloudSyncProfile.cs b/Emby.Server.Implementations/Sync/CloudSyncProfile.cs index 1a78c8ae66..c0675df817 100644 --- a/Emby.Server.Implementations/Sync/CloudSyncProfile.cs +++ b/Emby.Server.Implementations/Sync/CloudSyncProfile.cs @@ -68,7 +68,7 @@ namespace Emby.Server.Implementations.Sync }, new ProfileCondition { - Condition = ProfileConditionType.EqualsAny, + Condition = ProfileConditionType.Equals, Property = ProfileConditionValue.NumVideoStreams, Value = "1", IsRequired = false @@ -232,20 +232,6 @@ namespace Emby.Server.Implementations.Sync { new ProfileCondition { - Condition = ProfileConditionType.LessThanEqual, - Property = ProfileConditionValue.AudioChannels, - Value = "2", - IsRequired = true - }, - new ProfileCondition - { - Condition = ProfileConditionType.LessThanEqual, - Property = ProfileConditionValue.AudioBitrate, - Value = "320000", - IsRequired = true - }, - new ProfileCondition - { Condition = ProfileConditionType.Equals, Property = ProfileConditionValue.IsSecondaryAudio, Value = "false", diff --git a/Emby.Server.Implementations/Sync/SyncJobProcessor.cs b/Emby.Server.Implementations/Sync/SyncJobProcessor.cs index 415757609d..b1adc64df6 100644 --- a/Emby.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/Emby.Server.Implementations/Sync/SyncJobProcessor.cs @@ -515,8 +515,14 @@ namespace Emby.Server.Implementations.Sync jobItem.Progress = 0; - var syncOptions = _config.GetSyncOptions(); var job = _syncManager.GetJob(jobItem.JobId); + if (job == null) + { + _logger.Error("Job not found. Cannot complete the sync job."); + await _syncManager.CancelJobItem(jobItem.Id).ConfigureAwait(false); + return; + } + var user = _userManager.GetUserById(job.UserId); if (user == null) { @@ -552,6 +558,8 @@ namespace Emby.Server.Implementations.Sync } } + var syncOptions = _config.GetSyncOptions(); + var video = item as Video; if (video != null) { diff --git a/Emby.Server.Implementations/Sync/SyncManager.cs b/Emby.Server.Implementations/Sync/SyncManager.cs index 13f60f5eea..310b35afe3 100644 --- a/Emby.Server.Implementations/Sync/SyncManager.cs +++ b/Emby.Server.Implementations/Sync/SyncManager.cs @@ -1030,6 +1030,18 @@ namespace Emby.Server.Implementations.Sync { await CancelJobItem(jobItem.Id).ConfigureAwait(false); } + + var syncJobResult = await GetJobs(new SyncJobQuery + { + ItemId = item, + TargetId = targetId + + }).ConfigureAwait(false); + + foreach (var job in syncJobResult.Items) + { + await CancelJob(job.Id).ConfigureAwait(false); + } } } @@ -1037,15 +1049,7 @@ namespace Emby.Server.Implementations.Sync { var jobItem = _repo.GetJobItem(id); - if (jobItem.Status != SyncJobItemStatus.Queued && jobItem.Status != SyncJobItemStatus.ReadyToTransfer && jobItem.Status != SyncJobItemStatus.Converting && jobItem.Status != SyncJobItemStatus.Failed && jobItem.Status != SyncJobItemStatus.Synced && jobItem.Status != SyncJobItemStatus.Transferring) - { - throw new ArgumentException("Operation is not valid for this job item"); - } - - if (jobItem.Status != SyncJobItemStatus.Synced) - { - jobItem.Status = SyncJobItemStatus.Cancelled; - } + jobItem.Status = SyncJobItemStatus.Cancelled; jobItem.Progress = 0; jobItem.IsMarkedForRemoval = true; @@ -1071,18 +1075,18 @@ namespace Emby.Server.Implementations.Sync _logger.ErrorException("Error deleting directory {0}", ex, path); } - //var jobItemsResult = GetJobItems(new SyncJobItemQuery - //{ - // AddMetadata = false, - // JobId = jobItem.JobId, - // Limit = 0, - // Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Failed, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring } - //}); + var jobItemsResult = GetJobItems(new SyncJobItemQuery + { + AddMetadata = false, + JobId = jobItem.JobId, + Limit = 0, + Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring } + }); - //if (jobItemsResult.TotalRecordCount == 0) - //{ - // await CancelJob(jobItem.JobId).ConfigureAwait(false); - //} + if (jobItemsResult.TotalRecordCount == 0) + { + await CancelJob(jobItem.JobId).ConfigureAwait(false); + } } public Task MarkJobItemForRemoval(string id) diff --git a/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs b/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs index 46cdb28a4d..06e0e66a91 100644 --- a/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs +++ b/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs @@ -38,6 +38,18 @@ namespace Emby.Server.Implementations.Sync } } + + if (item.Status == SyncJobItemStatus.Cancelled) + { + try + { + await _sessionManager.SendMessageToUserDeviceSessions(item.TargetId, "SyncJobItemCancelled", item, CancellationToken.None).ConfigureAwait(false); + } + catch + { + + } + } } public void Dispose() diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index 885f8e64a6..aafce3500f 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -221,48 +221,70 @@ namespace Emby.Server.Implementations.Sync using (var connection = CreateConnection()) { string commandText; - var paramList = new List<object>(); if (insert) { - commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Bitrate, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)"; } else { - commandText = "update SyncJobs set TargetId=?,Name=?,Profile=?,Quality=?,Bitrate=?,Status=?,Progress=?,UserId=?,ItemIds=?,Category=?,ParentId=?,UnwatchedOnly=?,ItemLimit=?,SyncNewContent=?,DateCreated=?,DateLastModified=?,ItemCount=? where Id=?"; + commandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Bitrate=@Bitrate,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@Id"; } - paramList.Add(job.TargetId); - paramList.Add(job.Name); - paramList.Add(job.Profile); - paramList.Add(job.Quality); - paramList.Add(job.Bitrate); - paramList.Add(job.Status.ToString()); - paramList.Add(job.Progress); - paramList.Add(job.UserId); + connection.RunInTransaction(conn => + { + using (var statement = PrepareStatementSafe(connection, commandText)) + { + statement.TryBind("@TargetId", job.TargetId); + statement.TryBind("@Name", job.Name); + statement.TryBind("@Profile", job.Profile); + statement.TryBind("@Quality", job.Quality); + statement.TryBind("@Bitrate", job.Bitrate); + statement.TryBind("@Status", job.Status.ToString()); + statement.TryBind("@Progress", job.Progress); + statement.TryBind("@UserId", job.UserId); + + statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); + + if (job.Category.HasValue) + { + statement.TryBind("@Category", job.Category.Value.ToString()); + } + else + { + statement.TryBindNull("@Category"); + } - paramList.Add(string.Join(",", job.RequestedItemIds.ToArray())); - paramList.Add(job.Category); - paramList.Add(job.ParentId); - paramList.Add(job.UnwatchedOnly); - paramList.Add(job.ItemLimit); - paramList.Add(job.SyncNewContent); - paramList.Add(job.DateCreated.ToDateTimeParamValue()); - paramList.Add(job.DateLastModified.ToDateTimeParamValue()); - paramList.Add(job.ItemCount); + if (!string.IsNullOrWhiteSpace(job.ParentId)) + { + statement.TryBind("@ParentId", job.ParentId); + } + else + { + statement.TryBindNull("@ParentId"); + } - if (insert) - { - paramList.Insert(0, job.Id.ToGuidParamValue()); - } - else - { - paramList.Add(job.Id.ToGuidParamValue()); - } + statement.TryBind("@UnwatchedOnly", job.UnwatchedOnly); - connection.RunInTransaction(conn => - { - conn.Execute(commandText, paramList.ToArray()); + if (job.ItemLimit.HasValue) + { + statement.TryBind("@ItemLimit", job.ItemLimit); + } + else + { + statement.TryBindNull("@ItemLimit"); + } + + statement.TryBind("@SyncNewContent", job.SyncNewContent); + + statement.TryBind("@DateCreated", job.DateCreated.ToDateTimeParamValue()); + statement.TryBind("@DateLastModified", job.DateLastModified.ToDateTimeParamValue()); + + statement.TryBind("@ItemCount", job.ItemCount); + statement.TryBind("@Id", job.Id.ToGuidParamValue()); + + statement.MoveNext(); + } }, TransactionMode); } } @@ -338,6 +360,11 @@ namespace Emby.Server.Implementations.Sync whereClauses.Add("UserId=?"); paramList.Add(query.UserId); } + if (!string.IsNullOrWhiteSpace(query.ItemId)) + { + whereClauses.Add("ItemIds like ?"); + paramList.Add("%" + query.ItemId + "%"); + } if (query.SyncNewContent.HasValue) { whereClauses.Add("SyncNewContent=?"); |
