-
Notifications
You must be signed in to change notification settings - Fork 28
(#384) added pull progress report via event OfflineDbContext.SynchronizationProgress #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
13e4b42
(#377) Fix for possible concurrent query during pull
StefanCuypers c35d90c
Merge branch 'CommunityToolkit:main' into main
StefanCuypers 1d02110
(#384) Added SynchronizationProgress event
StefanCuypers d4e996d
(#384) Added test scenario for SynchronizationProgress event (Offlin…
StefanCuypers e232d8c
(#384) Added SynchronizationEventType PullStarted and PullEnded.
StefanCuypers d4fd2f7
(#384)
StefanCuypers 5ad984c
(#384) Changed DateTimeConverter on client and server side to handle …
StefanCuypers dbff3f7
(#384) Renamed TotalNrItems on SynchronizationEventArgs to ItemsTotal.
StefanCuypers 76657a0
Update src/CommunityToolkit.Datasync.Client/Offline/SynchronizationEv…
StefanCuypers cf96767
Update src/CommunityToolkit.Datasync.Client/Offline/SynchronizationEv…
StefanCuypers a69e156
Update src/CommunityToolkit.Datasync.Client/Offline/SynchronizationEv…
StefanCuypers a590ff2
Update src/CommunityToolkit.Datasync.Client/Offline/OperationsQueue/O…
StefanCuypers 053b2f0
Added DateTimeConverte tests for verifying default time, local time a…
StefanCuypers 4ffbc92
Changed QueueHandler_WithThreads_Enqueue test to sleep a thread for 2…
StefanCuypers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/CommunityToolkit.Datasync.Client/Offline/SynchronizationEventArgs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace CommunityToolkit.Datasync.Client.Offline; | ||
|
||
/// <summary> | ||
/// The list of synchronization events that we support. | ||
/// </summary> | ||
public enum SynchronizationEventType | ||
{ | ||
/// <summary> | ||
/// Occurs when items have been successfully fetches from the server. | ||
/// </summary> | ||
/// <remarks>This event is raised after a page of entities was succesfully fetched from the server, ready to be commited to the data store.</remarks> | ||
ItemsFetched, | ||
|
||
/// <summary> | ||
/// Occurs when items have been successfully committed to the underlying data store. | ||
/// </summary> | ||
/// <remarks>This event is raised after a page of entities was succesfully commited to the database</remarks> | ||
StefanCuypers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ItemsCommitted, | ||
} | ||
|
||
/// <summary> | ||
/// The event arguments sent when a synchronization event occurs. | ||
/// </summary> | ||
public class SynchronizationEventArgs | ||
{ | ||
/// <summary> | ||
/// The type of event. | ||
/// </summary> | ||
public required SynchronizationEventType EventType { get; init; } | ||
|
||
/// <summary> | ||
/// The EntityType that is being processed. | ||
/// </summary> | ||
public required Type EntityType { get; init; } | ||
|
||
/// <summary> | ||
/// When pulling records, the number of items that have been processed in the current pull request. | ||
/// </summary> | ||
public long ItemsProcessed { get; init; } = -1; | ||
|
||
/// <summary> | ||
/// The total number of items in the current pull request. | ||
/// </summary> | ||
public long TotalNrItems { get; init; } | ||
StefanCuypers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// The query ID that is being processed | ||
/// </summary> | ||
public required string QueryId { get; init; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1433,6 +1433,59 @@ public async Task DbSet_PushAsync_Throws_OnNonOfflineDbContext() | |||||||||
} | ||||||||||
#endregion | ||||||||||
|
||||||||||
#region SynchronizationProgress | ||||||||||
[Fact] | ||||||||||
public async Task SynchronizationProgress_Event_Works() | ||||||||||
{ | ||||||||||
Page<ClientMovie> page1 = CreatePage(5, 20, "$skip=5"); | ||||||||||
Page<ClientMovie> page2 = CreatePage(5, 20, "$skip=10"); | ||||||||||
Page<ClientMovie> page3 = CreatePage(5, 20, "$skip=15"); | ||||||||||
Page<ClientMovie> page4 = CreatePage(5, 20); | ||||||||||
|
||||||||||
this.context.Handler.AddResponse(HttpStatusCode.OK, page1); | ||||||||||
this.context.Handler.AddResponse(HttpStatusCode.OK, page2); | ||||||||||
this.context.Handler.AddResponse(HttpStatusCode.OK, page3); | ||||||||||
this.context.Handler.AddResponse(HttpStatusCode.OK, page4); | ||||||||||
|
||||||||||
bool eventFiredForFetch = true; | ||||||||||
bool eventFiredForCommit = true; | ||||||||||
StefanCuypers marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize 'eventFiredForCommit' to false to ensure proper verification that the event is raised during synchronization.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
long currentItemsFetched = 0; | ||||||||||
long currentItemsCommited = 0; | ||||||||||
|
||||||||||
this.context.SynchronizationProgress += (sender, args) => | ||||||||||
{ | ||||||||||
sender.Should().Be(this.context); | ||||||||||
args.EntityType.Should().Be<ClientMovie>(); | ||||||||||
args.QueryId.Should().Be("CommunityToolkit.Datasync.TestCommon.Databases.ClientMovie"); | ||||||||||
args.TotalNrItems.Should().Be(20); | ||||||||||
switch(args.EventType) | ||||||||||
{ | ||||||||||
case SynchronizationEventType.ItemsFetched: | ||||||||||
currentItemsFetched += 5; | ||||||||||
args.ItemsProcessed.Should().Be(currentItemsFetched); | ||||||||||
eventFiredForFetch = true; | ||||||||||
break; | ||||||||||
case SynchronizationEventType.ItemsCommitted: | ||||||||||
currentItemsCommited += 5; | ||||||||||
args.ItemsProcessed.Should().Be(currentItemsCommited); | ||||||||||
eventFiredForCommit = true; | ||||||||||
break; | ||||||||||
default: | ||||||||||
Assert.Fail($"Invalid event type: {args.EventType}"); | ||||||||||
break; | ||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
await this.context.Movies.PullAsync(); | ||||||||||
|
||||||||||
eventFiredForFetch.Should().BeTrue(); | ||||||||||
eventFiredForCommit.Should().BeTrue(); | ||||||||||
currentItemsFetched.Should().Be(20); | ||||||||||
currentItemsCommited.Should().Be(20); | ||||||||||
} | ||||||||||
|
||||||||||
#endregion | ||||||||||
|
||||||||||
public class NotOfflineDbContext : DbContext | ||||||||||
{ | ||||||||||
public NotOfflineDbContext() : base() | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.