- Add NuGet Package WindowsAzure.MobileService.SQLiteStore
Search for „WindowsAzure.MobileService“ - Change Reference from „SQLite for … (Windows 8.1)“ to „SQLite for Universal App Platform“
- Insert usings for
- Microsoft.WindowsAzure.MobileServices.SQLiteStore
- Microsoft.WindowsAzure.MobileServices.Sync
- Change the „GetTable“-Function to „GetSyncTable“-Function
- Add „await InitLocalStoreAsync()“-Function in „OnNavigatedTo“-Function
- Add „await SyncAsync()“-Function after „InsertAsync“-Function
- Add „await SyncAsync()“-Function after „UpdateAsync“-Function
- Add „await SyncAsync()“-Function after „DeleteAsync“-Function
- Add „await SyncAsync()“-Function before „Refresh“-Function
- Add following Code:
private async Task RefreshItemsAsync() { MobileServiceInvalidOperationException exception = null; try { items = await todoTable.where(...).ToCollectionAsync(); } catch(MobileServiceInvalidOperationException e) { exception = e; } if(exception != null) { await new MessageDialog(...).ShowAsync(); } else { ListItems.ItemsSource = items; this.ButtonSave.IsEnabled = true; } } private async Task InitLocalStoreAsync() { if(!App.MobileService.SyncContext.IsInitialized) { var store = new MobileServiceSQLiteStore("localstore.db"); store.DefineTable<TodoItem>(); await App.MobileService.SyncContext.InitializeAsync(store); } await SyncAsync(); } private async Task SyncAsync() { string errorString = null; try { await App.MobileService.SyncContext.PushAsync(); await todoTable.PullAsync("todoItems", todoTable.CreateQuery()); } catch(MobileServicePushFailedException ex) { errorString = "Errors: " + ex.PushResult.Errors.Count + " " + ex.Message; } catch(Exception ex) { errorString = "Error: " + ex.Message; } if(errorString != null) { MessagebDialog d = new MessageDialog(errorString); await d.ShowAsync(); } }