Synchroniser Examples

Example 1. Handling multiple sync rules.

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:

Example 2. Creating a connection and executing a sync rule.

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:

Example 3. Enabling and executing a background sync rule.

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:

Example 4. Check status code after a background sync

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:

Example 5. Setting the order of execution for sync rules

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: