aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Sync
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-12-28 16:13:12 -0500
committerGitHub <noreply@github.com>2016-12-28 16:13:12 -0500
commit2cb0f3eed635bb468b3672d08dca9a720b4fb48f (patch)
tree1a0d7c53ec148619ae966a81187413a33ca9a8a4 /Emby.Server.Implementations/Sync
parente47ccdce4247b93faa6d27849b255aac83324c42 (diff)
parentc10b152018967ddafe72efbccfe8ca6c586cbf04 (diff)
Merge pull request #2372 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Server.Implementations/Sync')
-rw-r--r--Emby.Server.Implementations/Sync/CloudSyncProfile.cs16
-rw-r--r--Emby.Server.Implementations/Sync/SyncJobProcessor.cs10
-rw-r--r--Emby.Server.Implementations/Sync/SyncManager.cs44
-rw-r--r--Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs12
-rw-r--r--Emby.Server.Implementations/Sync/SyncRepository.cs89
5 files changed, 104 insertions, 67 deletions
diff --git a/Emby.Server.Implementations/Sync/CloudSyncProfile.cs b/Emby.Server.Implementations/Sync/CloudSyncProfile.cs
index 1a78c8ae6..c0675df81 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 415757609..b1adc64df 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 13f60f5ee..310b35afe 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 46cdb28a4..06e0e66a9 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 885f8e64a..aafce3500 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=?");