1
votes

I've gone through instructions In this documentation To implement offline sync on my Xamarin.Forms client But when I pull data using sync table, I don't get the data presently in the cloud, Instead when I Read data using the normal table, I actually receive data normally, I don't understand, Here is my code to get data Using SYncTable :

/// <summary>
    /// Initialize offline sync
    /// </summary>
    /// <returns></returns>
    public async Task InitializeAsync()
    {
        if(!_client.SyncContext.IsInitialized)
        {
            _store.DefineTable<T>();
            await _client.SyncContext.InitializeAsync(_store, new MobileServiceSyncHandler());
            await SyncOfflineCacheAsync();
        }
    }

    public async Task SyncOfflineCacheAsync()
    {
        try
        {
            Debug.WriteLine("SyncOfflineCacheAsync: Initializing...");
            await InitializeAsync();

            // Push the Operations Queue to the mobile backend
            Debug.WriteLine("SyncOfflineCacheAsync: Pushing Changes");
            await _client.SyncContext.PushAsync();

            // Pull each sync table
            Debug.WriteLine("SyncOfflineCacheAsync: Pulling tags table");
            _table = _client.GetSyncTable<T>();
            string queryName = $"incsync_{typeof(T).Name}";
            await _table.PullAsync(queryName, _table.CreateQuery());
        }
        catch (MobileServicePushFailedException e )
        {
            if (e.PushResult != null)
            {
                foreach (var error in e.PushResult.Errors)
                {
                    await ResolveConflictAsync(error);
                }
            }
        }
        catch(Exception e)
        {
            throw e ;
        }
    }

I get no data previously added online

But when I get data without offline sync, it functions well

        var data = await baseAzureMobileService.NormalTable.ReadAsync();
2
Try calling PullAsync with null in place of queryName, that will force it to fetch all the records instead of trying to do an incremental sync. - Eric Hedstrom
Thankyou it worked now - Damien Doumer

2 Answers

0
votes

Try calling PullAsync with null in place of queryName, that will force it to fetch all the records instead of trying to do an incremental sync.

0
votes

AFAIK, the Incremental Sync request would look like this:

Get https://{your-app-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'2017-11-03T06%3A56%3A44.4590000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true

For Incremental Sync, the updatedAt timestamp of the results returned from your latest pull operation would be stored in the __config table of your local SQLite db as follows:

Note: The format for the value under the id column equals deltaToken|{table-name}|{query-name}.

I would recommend you capture the network traces and check the synced records under your local table to narrow this issue. Since incremental sync has optimized the requests instead of retrieving all records each time, I would recommend you leverage this feature. If your data set is small or you do not care the bandwidth, you could just opt out of incremental sync.