Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Update to IsSuccessful so that it's an optional arg, and true/false have correct meaning #603

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions sdk/dotnet/src/Microsoft.Datasync.Client/Offline/SyncContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,21 @@ public async Task PullItemsAsync(string tableName, string query, PullOptions opt

if (instance is not JObject item)
{
SendPullFinishedEvent(tableName, itemCount, false);
throw new DatasyncInvalidOperationException("Received item is not an object");
}

string itemId = ServiceSerializer.GetId(item);
if (itemId == null)
{
SendPullFinishedEvent(tableName, itemCount, false);
throw new DatasyncInvalidOperationException("Received an item without an ID");
}

var pendingOperation = await OperationsQueue.GetOperationByItemIdAsync(tableName, itemId, cancellationToken).ConfigureAwait(false);
if (pendingOperation != null)
{
SendPullFinishedEvent(tableName, itemCount, false);
throw new InvalidOperationException("Received an item for which there is a pending operation.");
}
DateTimeOffset? updatedAt = ServiceSerializer.GetUpdatedAt(item)?.ToUniversalTime();
Expand All @@ -375,7 +378,7 @@ public async Task PullItemsAsync(string tableName, string query, PullOptions opt
await DeltaTokenStore.SetDeltaTokenAsync(tableName, queryId, updatedAt.Value, cancellationToken).ConfigureAwait(false);
}
}
SendPullFinishedEvent(tableName, itemCount);
SendPullFinishedEvent(tableName, itemCount, true);
}

/// <summary>
Expand Down Expand Up @@ -863,11 +866,12 @@ private void SendPullStartedEvent(string tableName)
ServiceClient.SendSynchronizationEvent(new SynchronizationEventArgs
{
EventType = SynchronizationEventType.PullStarted,
TableName = tableName
TableName = tableName,
IsSuccessful = null
});
}

private void SendPullFinishedEvent(string tableName, long itemsReceived)
private void SendPullFinishedEvent(string tableName, long itemsReceived, bool isSuccessful)
{
ServiceClient.SendSynchronizationEvent(new SynchronizationEventArgs
{
Expand All @@ -882,7 +886,8 @@ private void SendPushStartedEvent()
ServiceClient.SendSynchronizationEvent(new SynchronizationEventArgs
{
EventType = SynchronizationEventType.PushStarted,
QueueLength = OperationsQueue.PendingOperations
QueueLength = OperationsQueue.PendingOperations,
IsSuccessful = null
});
}

Expand All @@ -904,7 +909,8 @@ private void SendItemWillBePushedEvent(string tableName, string itemId, long ite
ItemsProcessed = itemCount,
QueueLength = OperationsQueue.PendingOperations,
TableName = tableName,
ItemId = itemId
ItemId = itemId,
IsSuccessful = null
});
}

Expand All @@ -929,7 +935,8 @@ private void SendItemWillBeStoredEvent(string tableName, string itemId, long ite
ItemsProcessed = itemCount,
QueueLength = expectedItems,
TableName = tableName,
ItemId = itemId
ItemId = itemId,
IsSuccessful = null
});
}

Expand All @@ -941,7 +948,8 @@ private void SendItemWasStoredEvent(string tableName, string itemId, long itemCo
ItemsProcessed = itemCount,
QueueLength = expectedItems,
TableName = tableName,
ItemId = itemId
ItemId = itemId,
IsSuccessful = true
});
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public class SynchronizationEventArgs
/// <summary>
/// In the case of a result, whether the push was successful or not.
/// </summary>
public bool IsSuccessful { get; internal set; }
public bool? IsSuccessful { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private static void AssertItemWillBePushed(SynchronizationEventArgs args, string
Assert.Equal(SynchronizationEventType.ItemWillBePushed, args.EventType);
Assert.Equal(table, args.TableName);
Assert.Equal(id, args.ItemId);
Assert.Null(args.IsSuccessful);
}

private static void AssertItemWasPushed(SynchronizationEventArgs args, string table, string id, bool success)
Expand Down