
With multiple synchronisation, it is best to allow the users to select which synchronisation to use to minimise the transaction from server to client and vice versa.
The image below is a Synchronise form that is subdivided into two groups, Send and Receive. The user has a clear understanding of what they can do with the form.
The sync expression would look like this:
Synchroniser.DisableAll()
// Check which sync rule to enable.
IF ckSendJobData
{
Synchroniser.EnableSyncRule("SyncSendJobData", true)
}
IF ckReceiveNewJobs
{
Synchroniser.EnableSyncRule("SyncGetNewJobs", true)
}
IF ckUpdateParts
{
Synchroniser.EnableSyncRule("SyncUpdateParts", true)
}
// Start synchronisation.
Form.ShowSyncDialog(false)
// Initialise checkboxes to default values.
ckReceiveNewJobs = false
ckSendJobData = false
ckUpdateParts = false
Note:
It is good design practice to always disable all sync rules with Synchroniser.DisableAll() method before enabling any sync rules. This ensures that unnecessary synchronisation are not executed.
Use the checkboxes to allow users to select which the synchronisation to execute.
Enable each sync rule with the Syncrhoniser.EnableSyncRule method based on which checkbox is ticked.
SyncSendJobData, SyncGetNewJobs, SyncUpdateParts are sync rules created in BrightBuilder.
Use Form.ShowSyncDialog method to start the synhronisation. Refer to the Form Object methods for details of the ShowSyncDialog method.
Always initialise the form controls to its default values after synchronisation.
Link this expression to the Action-Click property of the Sync button.
Synchroniser.DisableAll()
//Create a connection to the server
Synchroniser.Connect()
//Execute the sync rule
Synchroniser.ExecuteSyncRule("syncToServer")
Synchroniser.Disconnect()
//Refresh form control
listview1.Refresh()
Note:
Synchroniser.ExecuteSyncRule("syncToServer") will not display a sync dialog box.
Synchroniser.DisableAll();
// Enable the sync rule
Synchroniser.EnableSyncRule("SyncRuleSendData", true);
// Make a background sync rule
Synchroniser.MakeBackgroundSyncRule("SyncRuleSendData", true);
// Call to synchronise in the next background sync session
Synchroniser.SynchroniseInBackground()
Note:
Synchroniser.SynchroniseInBackground() will signal the background sync thread in BrightForms to execute any enabled background sync rules.
This section of code may be located in a form's 'Action - Background Sync' property; reevaluating and containing the synchronisation logic within the background sync thread.
local.result = Synchroniser.GetLastSyncError();
IF local.result == -10519
{
Form.MessageBox("Update", "Update Available", MB_OK);
EXIT;
}
IF local.result <> 0
{
Form.MessageBox("Sync", "Error", MB_OK);
}
IF local.result == 0
{
Form.MessageBox("Sync", "Background Synchronisation Successful", MB_OK);
}
Note:
Synchroniser.GetLastSyncError() retrieves the last error code noted by the background sync.
Error code -10519 is the status code which denotes an application update, 0 is a successful synchronisation.
Synchroniser.DisableAll();
Synchroniser.EnableSyncRule("syncSendJobData", true);
Synchroniser.MakeBackgroundSyncRule("syncSendJobData", true);
Synchroniser.SetExecutionOrder("syncSendJobData", 1);
Synchroniser.EnableSyncRule("syncGetJobData", true);
Synchroniser.MakeBackgroundSyncRule("syncGetJobData", true);
Synchroniser.SetExecutionOrder("syncGetJobData", 2);
Synchroniser.SynchroniseInBackground();
Note:
Sets "syncSendJobData" to execute after "syncGetJobData", then calls for a sync using the background sync
Similarly may be used for a sync dialog synchronisation, in that case, Synchroniser.MakeBackgroundSyncRule() does not need to be called and Form.ShowSyncDialog(false) needs to be called instead of Synchroniser.SynchroniseInBackground().