Skip to content

Commit dbff3f7

Browse files
committed
(#384) Renamed TotalNrItems on SynchronizationEventArgs to ItemsTotal.
Made DateTimeConverter on server Except again if input is empty. Optimised DataTimeConverter to avoid double parsing.
1 parent 5ad984c commit dbff3f7

File tree

6 files changed

+18
-26
lines changed

6 files changed

+18
-26
lines changed

src/CommunityToolkit.Datasync.Client/Offline/Operations/PullOperationManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public async Task<PullResult> ExecuteAsync(IEnumerable<PullRequest> requests, Pu
118118
EventType = SynchronizationEventType.ItemsCommitted,
119119
EntityType = pullResponse.EntityType,
120120
ItemsProcessed = pullResponse.TotalItemsProcessed,
121-
TotalNrItems = pullResponse.TotalRequestItems,
121+
ItemsTotal = pullResponse.TotalRequestItems,
122122
QueryId = pullResponse.QueryId
123123
});
124124
}
@@ -130,7 +130,7 @@ public async Task<PullResult> ExecuteAsync(IEnumerable<PullRequest> requests, Pu
130130
EventType = SynchronizationEventType.PullEnded,
131131
EntityType = pullResponse.EntityType,
132132
ItemsProcessed = pullResponse.TotalItemsProcessed,
133-
TotalNrItems = pullResponse.TotalRequestItems,
133+
ItemsTotal = pullResponse.TotalRequestItems,
134134
QueryId = pullResponse.QueryId,
135135
Exception = pullResponse.Exception,
136136
ServiceResponse = pullResponse.Exception is DatasyncPullException ex ? ex.ServiceResponse : null
@@ -167,7 +167,7 @@ public async Task<PullResult> ExecuteAsync(IEnumerable<PullRequest> requests, Pu
167167
EventType = SynchronizationEventType.ItemsFetched,
168168
EntityType = pullRequest.EntityType,
169169
ItemsProcessed = itemsProcessed,
170-
TotalNrItems = page.Count ?? 0,
170+
ItemsTotal = page.Count ?? 0,
171171
QueryId = pullRequest.QueryId
172172
});
173173

src/CommunityToolkit.Datasync.Client/Offline/OperationsQueue/OperationsQueueManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ internal async Task<PushResult> PushAsync(IEnumerable<Type> entityTypes, PushOpt
275275
this._context.SendSynchronizationEvent(new SynchronizationEventArgs()
276276
{
277277
EventType = SynchronizationEventType.PushStarted,
278-
TotalNrItems = queuedOperations.Count
278+
ItemsTotal = queuedOperations.Count
279279
});
280280

281281
if (queuedOperations.Count == 0)
@@ -301,7 +301,7 @@ internal async Task<PushResult> PushAsync(IEnumerable<Type> entityTypes, PushOpt
301301
{
302302
EventType = SynchronizationEventType.PushItem,
303303
ItemsProcessed = newItemsProcessed,
304-
TotalNrItems = queuedOperations.Count,
304+
ItemsTotal = queuedOperations.Count,
305305
PushOperation = operation,
306306
});
307307
});
@@ -317,7 +317,7 @@ internal async Task<PushResult> PushAsync(IEnumerable<Type> entityTypes, PushOpt
317317
{
318318
EventType = SynchronizationEventType.PushEnded,
319319
ItemsProcessed = nrItemsProcessed,
320-
TotalNrItems = queuedOperations.Count,
320+
ItemsTotal = queuedOperations.Count,
321321
});
322322

323323
return pushResult;

src/CommunityToolkit.Datasync.Client/Offline/SynchronizationEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class SynchronizationEventArgs
7373
/// When pulling records, the total number of items to pull for the given entity in the current pull request
7474
/// When pushing records, the total number of items that are being pushed in the current push request.
7575
/// </summary>
76-
public long TotalNrItems { get; init; }
76+
public long ItemsTotal { get; init; }
7777

7878
/// <summary>
7979
/// The query ID that is being processed on pull operations. Not used on push events.

src/CommunityToolkit.Datasync.Client/Serialization/DateTimeConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
3333
return utc;
3434
}
3535

36-
return DateTime.Parse(token);
36+
return utc.ToLocalTime();
3737
}
3838
}
3939

src/CommunityToolkit.Datasync.Server.Abstractions/Json/DateTimeConverter.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@ public class DateTimeConverter : JsonConverter<DateTime>
1919
/// <inheritdoc />
2020
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2121
{
22-
string? token = reader.GetString();
23-
if (string.IsNullOrEmpty(token))
22+
// Check if datetime was 'default'. If so do not adjust to local time.
23+
DateTime utc = DateTime.Parse(reader.GetString() ?? "", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
24+
if (utc == default)
2425
{
25-
return DateTime.MinValue;
26+
return utc;
2627
}
27-
else
28-
{
29-
// Check if datetime was 'default'. If so do not adjust to local time.
30-
DateTime utc = DateTime.Parse(token, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
31-
if (utc == default)
32-
{
33-
return utc;
34-
}
3528

36-
return DateTime.Parse(token);
37-
}
29+
return utc.ToLocalTime();
3830
}
3931

4032
/// <inheritdoc />

tests/CommunityToolkit.Datasync.Client.Test/Offline/OfflineDbContext_Tests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,13 @@ public async Task SynchronizationProgress_Event_Works()
14671467
case SynchronizationEventType.ItemsFetched:
14681468
currentItemsFetched += 5;
14691469
args.ItemsProcessed.Should().Be(currentItemsFetched);
1470-
args.TotalNrItems.Should().Be(20);
1470+
args.ItemsTotal.Should().Be(20);
14711471
eventFiredForFetch = true;
14721472
break;
14731473
case SynchronizationEventType.ItemsCommitted:
14741474
currentItemsCommited += 5;
14751475
args.ItemsProcessed.Should().Be(currentItemsCommited);
1476-
args.TotalNrItems.Should().Be(20);
1476+
args.ItemsTotal.Should().Be(20);
14771477
eventFiredForCommit = true;
14781478
break;
14791479
case SynchronizationEventType.PullStarted:
@@ -1484,7 +1484,7 @@ public async Task SynchronizationProgress_Event_Works()
14841484
eventFiredForEnd.Should().BeFalse("PullEnded event should only fire once");
14851485
eventFiredForEnd = true;
14861486
args.ItemsProcessed.Should().Be(20);
1487-
args.TotalNrItems.Should().Be(20);
1487+
args.ItemsTotal.Should().Be(20);
14881488
break;
14891489
default:
14901490
Assert.Fail($"Invalid event type: {args.EventType}");
@@ -1572,11 +1572,11 @@ public async Task SynchronizationProgress_Event_Works_For_Push()
15721572
sender.Should().Be(this.context);
15731573
args.Exception.Should().BeNull();
15741574
args.ServiceResponse.Should().BeNull();
1575-
args.TotalNrItems.Should().Be(newMovies.Length);
1575+
args.ItemsTotal.Should().Be(newMovies.Length);
15761576
switch (args.EventType)
15771577
{
15781578
case SynchronizationEventType.PushItem:
1579-
args.TotalNrItems.Should().Be(newMovies.Length);
1579+
args.ItemsTotal.Should().Be(newMovies.Length);
15801580
args.ItemsProcessed.Should().BeInRange(1,newMovies.Length);
15811581
int prevProcessed = Interlocked.Exchange(ref itemsProcessedReported[args.ItemsProcessed-1], 1);
15821582
prevProcessed.Should().Be(0, "Each item should only be reported once");

0 commit comments

Comments
 (0)