@@ -13,6 +13,67 @@ namespace CommunityToolkit.Datasync.Client.Offline;
13
13
/// </summary>
14
14
public static class Extensions
15
15
{
16
+ /// <summary>
17
+ /// Pulls the changes from the remote service for the specified dataset
18
+ /// </summary>
19
+ /// <param name="dataset">The dataset to pull from the remote service.</param>
20
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
21
+ /// <returns>The results of the pull operation.</returns>
22
+ public static Task < PullResult > PullAsync < TEntity > ( this DbSet < TEntity > dataset , CancellationToken cancellationToken = default ) where TEntity : class
23
+ => dataset . PullAsync ( new PullOptions ( ) , cancellationToken ) ;
24
+
25
+ /// <summary>
26
+ /// Pulls the changes from the remote service for the specified dataset
27
+ /// </summary>
28
+ /// <param name="dataset">The dataset to pull from the remote service.</param>
29
+ /// <param name="options">The options to use on this pull request.</param>
30
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
31
+ /// <returns>The results of the pull operation.</returns>
32
+ public static Task < PullResult > PullAsync < TEntity > ( this DbSet < TEntity > dataset , PullOptions options , CancellationToken cancellationToken = default ) where TEntity : class
33
+ {
34
+ DbContext context = dataset . GetService < ICurrentDbContext > ( ) . Context ;
35
+ if ( context is OfflineDbContext offlineContext )
36
+ {
37
+ return offlineContext . PullAsync ( [ typeof ( TEntity ) ] , options , cancellationToken ) ;
38
+ }
39
+ else
40
+ {
41
+ throw new DatasyncException ( $ "Provided dataset is not a part of an { nameof ( OfflineDbContext ) } ") ;
42
+ }
43
+ }
44
+
45
+ /// <summary>
46
+ /// Pulls the changes from the remote service for all synchronizable entities.
47
+ /// </summary>
48
+ /// <param name="context">The offline database context to use.</param>
49
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
50
+ /// <returns>The results of the pull operation.</returns>
51
+ [ ExcludeFromCodeCoverage ]
52
+ public static Task < PullResult > PullAsync ( this OfflineDbContext context , CancellationToken cancellationToken = default )
53
+ => context . PullAsync ( context . QueueManager . GetSynchronizableEntityTypes ( ) , new PullOptions ( ) , cancellationToken ) ;
54
+
55
+ /// <summary>
56
+ /// Pulls the changes from the remote service for all synchronizable entities.
57
+ /// </summary>
58
+ /// <param name="context">The offline database context to use.</param>
59
+ /// <param name="options">The options to use on this pull request.</param>
60
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
61
+ /// <returns>The results of the pull operation.</returns>
62
+ [ ExcludeFromCodeCoverage ]
63
+ public static Task < PullResult > PullAsync ( this OfflineDbContext context , PullOptions options , CancellationToken cancellationToken = default )
64
+ => context . PullAsync ( context . QueueManager . GetSynchronizableEntityTypes ( ) , options , cancellationToken ) ;
65
+
66
+ /// <summary>
67
+ /// Pulls the changes from the remote service for the specified synchronizable entities.
68
+ /// </summary>
69
+ /// <param name="context">The offline database context to use.</param>
70
+ /// <param name="entityTypes">The list of entity types to pull.</param>
71
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
72
+ /// <returns>The results of the pull operation.</returns>
73
+ [ ExcludeFromCodeCoverage ]
74
+ public static Task < PullResult > PullAsync ( this OfflineDbContext context , IEnumerable < Type > entityTypes , CancellationToken cancellationToken = default )
75
+ => context . PullAsync ( entityTypes , new PullOptions ( ) , cancellationToken ) ;
76
+
16
77
/// <summary>
17
78
/// Pushes the pending operations against the remote service for the provided dataset
18
79
/// </summary>
0 commit comments