Intercepting changes from client's local database #604
Answered
by
Mimetis
ChristianFrom
asked this question in
Q&A
-
Hello, how do I intercept when something has changed in the client's local database? |
Beta Was this translation helpful? Give feedback.
Answered by
Mimetis
Aug 31, 2021
Replies: 1 comment 1 reply
-
Hi @ChristianFrom. Depending on your need, you have two solutions: If you want to know the rows to send, before trying to sync, you can use this kind of code: // Creating an agent that will handle all the process
var agent = new SyncAgent(clientProvider, serverProvider, options, setup);
// Get changes to be populated to the server
var changes = await agent.LocalOrchestrator.GetChangesAsync();
// enumerate changes retrieved on the client, to be sent to server
foreach (var tableChanges in changes.ClientChangesSelected.TableChangesSelected)
{
var enumerableOfTables = changes.ClientBatchInfo.GetTableAsync(
tableChanges.TableName, tableChanges.SchemaName, options.SerializerFactory);
var enumeratorOfTable = enumerableOfTables.GetAsyncEnumerator();
while (await enumeratorOfTable.MoveNextAsync())
{
var table = enumeratorOfTable.Current;
Console.WriteLine($"Changes for table {table.GetFullName()}");
foreach (var row in table.Rows)
{
Console.WriteLine(row);
}
}
} If you want to know what the rows really send to the server, during a sync, you can use an // Creating an agent that will handle all the process
var agent = new SyncAgent(clientProvider, serverProvider, options, setup);
agent.LocalOrchestrator.OnTableChangesSelected(args =>
{
if (args.Changes == null || args.Changes.Rows.Count == 0)
return;
foreach (var row in args.Changes.Rows)
Console.WriteLine(row);
});
var s = await agent.SynchronizeAsync(progress); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Mimetis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @ChristianFrom.
Depending on your need, you have two solutions:
If you want to know the rows to send, before trying to sync, you can use this kind of code: