Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,13 @@ internal async Task<PushResult> PushAsync(IEnumerable<Type> entityTypes, PushOpt
if (operation.Kind != OperationKind.Delete)
{
_ = response.ContentStream.Seek(0L, SeekOrigin.Begin); // Reset the memory stream to the beginning.
object? newValue = JsonSerializer.Deserialize(response.ContentStream, entityType, DatasyncSerializer.JsonSerializerOptions);
object? oldValue = await this._context.FindAsync(entityType, [operation.ItemId], cancellationToken).ConfigureAwait(false);
object? newValue = await JsonSerializer.DeserializeAsync(
response.ContentStream,
entityType,
DatasyncSerializer.JsonSerializerOptions,
cancellationToken);

object? oldValue = await FindOldValue(operation, entityType, cancellationToken);
ReplaceDatabaseValue(oldValue, newValue);
}

Expand All @@ -410,6 +415,32 @@ internal async Task<PushResult> PushAsync(IEnumerable<Type> entityTypes, PushOpt
return null;
}

/// <summary>
/// Internal helper - find the old value for a datasync operation and an entity type.
/// </summary>
/// <param name="operation">The datasync operation.</param>
/// <param name="entityType">The entity type.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>The object associated with the datasync operation, or <c>null</c>.</returns>
internal async ValueTask<object?> FindOldValue(DatasyncOperation operation, Type entityType, CancellationToken cancellationToken)
{
this.pushlock.Enter();
try
{
object? oldValue = await this._context
.FindAsync(
entityType,
[operation.ItemId],
cancellationToken)
.ConfigureAwait(false);
return oldValue;
}
finally
{
this.pushlock.Exit();
}
}

/// <summary>
/// Internal helper - replaces an old value of an entity in the database with a new value.
/// </summary>
Expand Down
Loading