0
votes

I have had nothing but issues with getting this offline sync client running. Now it isn't pulling anything and I cannot for the life of me figure out why! Here is my sync code on the client:

    private async Task InitLocalStoreAsync()
     {
        if (!App.MobileService.SyncContext.IsInitialized)
        {
            var store = new MobileServiceSQLiteStore("localstore.db");
            store.DefineTable<clist>();
            await App.MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
        }

        await SyncAsync();
        await RefreshNcards();

    }
    private async Task SyncAsync()
    {
        String errorString = null;
        PullOptions pageSize = new PullOptions { MaxPageSize =1000 };

        try
        {
            await LocalCards.PullAsync("clist", LocalCards.CreateQuery(),pullOptions:pageSize); // first param is query ID, used for incremental sync
        }

        catch (Exception ex)
        {
            errorString = "It look's like we weren't able to make sure your cards were updated. No worries, next time you start the app we will try again. This won't impact your experience.";

            //    errorString = "Pull failed: " + ex.Message +
            //      "\n\nIf you are still in an offline scenario, " +
            //      "you can try your Pull again when connected with your Mobile Serice.";
        }

        if (errorString != null)
        {
            MessageDialog d = new MessageDialog(errorString);
            await d.ShowAsync();
        }
    }

This code pauses for a few seconds than moves on with no errors thrown. Here is my class:

    class clist : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler PropertyChanged;
    [JsonProperty(PropertyName ="id")]
    public string id { get; set; }

    [JsonProperty(PropertyName = "_createdAt")]
    public DateTime _createdAt { get; set; }

    [JsonProperty(PropertyName = "_updatedAt")]
    public DateTime _updatedAt { get; set; }

    [JsonProperty(PropertyName = "_version")]
    public DateTime _version { get; set; }
    public bool _deleted { get; set; }
    [JsonProperty(PropertyName = "Nid")]
    public string Nid { get; set; }

    [JsonProperty(PropertyName = "Nname")]
    public string Nname { get; set; }

    [JsonProperty(PropertyName = "Nset")]
    public string Nset { get; set; }

    public void RaisePropertyChanged(string name)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }
}

Just in case its helpful here are the log streams I get when I run logging in the Azure Portal.

2016-04-13 04:36:05 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=d9ceb9a8-433f-4a23-a4ab-3caf984cb8e8 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522131849 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 914 1625 11874 2016-04-13 04:36:26 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=159b6aa0-df2e-46a8-8a24-d0a0086acdaf 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522152216 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 584 1626 20039 2016-04-13 04:36:46 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=e7c12e75-54a8-4be3-9e66-7399635657f6 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522164231 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 584 1625 20065 2016-04-13 04:37:06 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=c78b53c1-15d8-491b-8c6b-22d8239fd920 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522184449 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 584 1625 20027 2016-04-13 04:37:26 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=a5e45861-bedd-4162-bc88-373306825e85 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522204509 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 584 1625 20052 2016-04-13 04:37:46 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=90f17ac1-2516-4bf8-ba9b-470fa1bf7748 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522224587 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 584 1625 20023 2016-04-13 04:38:06 ~1MAGICHUB POST /dev/api/events/wwwroot/longpoll X-ARR-LOG-ID=f715514e-f0aa-4299-950a-88b1884d89bf 443 - 172.103.28.93 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/46.0.2486.0+Safari/537.36+Edge/13.10586 ARRAffinity=6910fd768a90c2d11e23085af4d93c48a8cc9617be87c545bc1e82b0186ea1da;+__RequestVerificationToken=ded78fdc-d9b2-49ad-bb5b-3a791b4a6886;+ai_user=3MLsg|2016-04-13T03:47:20.208Z;+ai_session=R6FJD|1460519240333|1460522244667 https://magichub.scm.azurewebsites.net/dev/wwwroot/tables/clist.js magichub.scm.azurewebsites.net 200 0 0 584 1625 20056 2016-04-13 04:38:13 MAGICHUB GET /tables/clist $filter=(updatedAt%20ge%20datetimeoffset'1970-01-01T00%3A00%3A00.0000000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=1000&__includeDeleted=true&$filter=(updatedAt%20ge%20datetimeoffset'1970-01-01T00%3A00%3A00.0000000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=1000&__includeDeleted=true&X-ARR-LOG-ID=c6b2681c-2dbe-4452-8c49-367343c36655 443 - 172.103.28.93 ZUMO/2.0+(lang=Managed;+os=Windows+Store;+os_version=--;+arch=X64;+version=2.0.31125.0) - - magichub.azurewebsites.net 200 0 0 695 1286 93

I am completely stumped as to why this is not working and would be stoked if anyone could help me narrow down the culprit and get this working!

1

1 Answers

2
votes

There are a couple of errors in your model.

The system properties need to be called createdAt, updatedAt - these don't have underscores any more. The version field should be a string - not a DateTime. The Id field should be capitalized.

You are relying on PullAsync performing the cache push for you. You should really be explicit about that and do PushAsync().

You didn't provide the definition of LocalCards, but make sure it is an instance of IMobileServiceSyncTable<clist> - obtained by client.GetSyncTable<clist>().