| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.WindowsAzure.MobileServices;
- using Microsoft.WindowsAzure.MobileServices.Sync;
- using Microsoft.WindowsAzure.MobileServices.SQLiteStore;
- using DevDaysSpeakers.Model;
- using System.Diagnostics;
- namespace DevDaysSpeakers.ViewModel
- {
- public class AzureStore
- {
- static AzureStore current;
- public static AzureStore Current
- {
- get
- {
- if (current == null)
- current = new AzureStore();
- return current;
- }
- }
- MobileServiceClient MobileService { get; set; }
- IMobileServiceSyncTable<Speaker> speakerTable;
- public async Task Initialize()
- {
- if (MobileService != null)
- return;
- MobileService = new MobileServiceClient("https://montemagnospeakers.azurewebsites.net");
- var store = new MobileServiceSQLiteStore("speakers.db");
- store.DefineTable<Speaker>();
- await MobileService.SyncContext.InitializeAsync(store);
- speakerTable = MobileService.GetSyncTable<Speaker>();
- }
- public async Task<List<Speaker>> GetSpeakers()
- {
- await Initialize();
- try
- {
- await speakerTable.PullAsync("allSpeakers", speakerTable.CreateQuery());
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex);
- }
- return await speakerTable.ToListAsync();
- }
- }
- }
|