Offline Sync is a Nuget Package which can be used to keep client and server side Databases in sync with no data loss and tuned to configure all possible scenarios.
Diagrammatical representation of a typical project using Offline Sync
- Note:
- Currently only SQLite DB is supported on the client side and SQLServer DB on the server side. Future implementation would include other databases too.
Please refer the following table to know the frameworks we support and tested so far.
Frameworks | Version |
---|---|
WPF | 1.0.0 |
UWP | 1.0.0 |
Xamarin native | 1.0.0 |
Xamarin forms | 1.0.0 |
There are two dll's you need to add to your project. One in the client side and the other in the server side application and whichever table you are trying to sync you need to do the following in the client side application.
Diagrammatical heirarchy representation of tables in a typical project using Offline Sync
Offline Sync suppports any of the below mentioned types of Sync.
-
Client to Sever sync will Sync the server table records to match with the client table records.
-
Note:
- Discards the client changes if there are any.
- Client to Server and Hard Delete is same as the Client to Server but hard deletes the Client records upon successful Sync.
-
Server to client will Sync the client table records with that of server table records.
-
Note:
- Discards the server changes if there are any. Use Case: Any Metadata tables(like Dropdown options etc..) in an application.
-
TwoWay Sync will sync both client and server depending upon the autosync/priority configured in the project.
-
Note:
- Here we resolve the conflicts if there are any based on the priority provided and then keep both client and server in Sync with the other
These are a few terms that you would come across while you use the offline sync in your project.
- AutoSync
- Priority
- VersionID
- TransactionID
- IsSynced
- SyncCreatedAt (client/server)
- SyncModifiedAt (client/server)
When the sync type is Twoway Sync the priority value for a table will be setup before we do a sync. These values could be any of these 3.
- Server
- The record on the server side will be considered over the client side record.
- Client
- The record on the client side will be considered over the server side record.
- LastUpdated
- Lastupdated priority means the record which was recently updated will be considered.
When in conflict the priority value will be crucial in making the changes.
This column value for a record in a tables holds a unique id for that record.
This column value for a record in a table says if the record is synced or not at that point of time.
This column value for a record in a table holds the timestamp of the record created at.
This column value for a record in a table holds the timestamp of the record modified at last time.
Following steps illustrate the configuration and usage of offline sync in a project.
In the client project install this nuget package, please follow below steps.
Note: Examples below isllustrate using offlinesync to sync one table on client side with that of a respective one on the server side.
Step 1
Adding Global Configurations on the client side:
- In the client application add the following lines which adds global configuration (API URL, Client DB Path, Auth Token, Client DB Type)
SyncGlobalConfig.DBPath = @"SyncDB.db"; SyncGlobalConfig.Token = ""; SyncGlobalConfig.APIUrl = @"http://localhost:64115/API/"; SyncGlobalConfig.APIUrl = ClientDBType.SQLite;
For reference Enum ClientDBType.cs
is as follows:
public enum ClientDBType { SQLite = 0 }
Step 2
Add Device ID
new DeviceIDUtility().InitializeDeviceID();
Step 3
Add Settings for each of the tables you want to sync as follows.
SyncSettingsUtility syncSettings = new SyncSettingsUtility(); syncSettings.Add( new SQLiteSyncSettingsModel { AutoSync = true, ClientTableName = typeof(tblTestClient).Name, Priority = OveridePriority.LastUpdated, SyncType = SyncType.SyncClientToServer, ServerAssemblyName = "User.APIApp", ServerTableName = "tblTestModelServer" } );
Step 4
Call SyncAsync
new SyncUtility<tblTestACTS>().StartSyncAsync();
Please install the nuget package on the server application and follow below steps to enable offlinesync successfully.
- add connnection string in the web.config check the below example.
Contributions are always welcome! Please read the contribution guidelines here.
- Support for .net core
We have a dedicated telegram channel for the support. You may reach us there. We will follow up as and when we are free.
Click this link to join the channel.