public async Task <JToken> ReadAsync(string query) { if (!await InitializeAsync()) { throw new MobileServiceInvalidOperationException("Unable to read data. Initialization failed.", null, null); } return(await _syncTable.ReadAsync(query)); }
public async Task <IEnumerable <Event> > ReadEventsItemsAsync() { await InitializeAsync(); await SynchronizeAsync(); return(await _eventItemTable.ReadAsync()); }
public async Task <IEnumerable <Notes> > GetNotes() { // var table = _mobileServiceClient.GetTable<Notes>(); await SyncNotes(); return(await _notesTable.ReadAsync()); }
public async Task <IEnumerable <ThinkingOfYou> > GetThinkingOfYouAsync() { //throw new NotImplementedException (); await InitializeAsync(); return(await thinkingOfYouTable.ReadAsync()); }
public async Task <IEnumerable <SurveyQuestion> > GetQuestionsAsync() { await InitializeAsync(); // throw new NotImplementedException (); return(await questionsTable.ReadAsync()); }
public async Task <IEnumerable <City> > GetAll() { await InitializeAsync(); var cities = await _cityTable.ReadAsync(); return(cities); }
public async Task <IEnumerable <T> > GetItemsFromLocalDatabaseAsync <T>() where T : EntityData { IMobileServiceSyncTable <T> table = null; await Initialize <T>(); table = _localDataTableDictionary?.FirstOrDefault(x => x.Key == typeof(T)).Value as IMobileServiceSyncTable <T>; return(await table?.ReadAsync()); }
//change to get all public async Task <ObservableCollection <TItemTable> > GetItemsAsync(bool syncAllItems = false, bool dataMark = true) { if (syncAllItems) { await this.SyncAsync(dataMark); } IEnumerable <TItemTable> items = await mainTable.ReadAsync(); return(new ObservableCollection <TItemTable>(items)); }
public async Task <IEnumerable <Quiz> > GetAllQuiz() { await Initialize(); await SyncQuiz(); var data = await quizTable.ReadAsync(); // .OrderBy(c => c.myClass) // .ToEnumerableAsync(); //this op is on the local database return(data); }
public async Task InitializeAsync() { if (_mobileService != null) { return; } // Inicialización de SQLite local (cache offline) var store = new MobileServiceSQLiteStore("cursoxamarin.db"); store.DefineTable <City>(); _mobileService = new MobileServiceClient(GlobalSettings.CityMobileServiceEndpoint); _cityTable = _mobileService.GetSyncTable <City>(); await _mobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()); if (CrossConnectivity.Current.IsConnected) { try { var cities = await _cityTable.ReadAsync(); var citiesList = new List <City>(cities); //subimos las imagenes offline al blob foreach (var city in citiesList.Where(city => city.OfflineImage != null)) { city.Image = await BlobService.GetInstance().UploadPhotoAsync(city.OfflineImage); city.OfflineImage = null; await _cityTable.UpdateAsync(city); } // Subir cambios a la base de datos remota await _mobileService.SyncContext.PushAsync(); await _cityTable.PullAsync( "allCities", _cityTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine("Exception: {0}", ex.Message); } } }
public async Task <IEnumerable <TodoItem> > GetTodoItemsAsync() { try { return(await todoTable.ReadAsync()); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"INVALID {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"ERROR {0}", e.Message); } return(null); }
public async Task <IEnumerable <Usuario> > ObterUsuarioAsync(string nome, string senha) { try { var query = from n in usuarios where n.Nome == nome && n.Senha == senha select n; var consulta = await usuarios.ReadAsync(query); return(consulta); } catch (Exception ex) { throw ex; } }
public async Task <List <Monkey> > GetMonkeysAsync() { try { var monkeys = await monkeyTable.ReadAsync(); return(monkeys.ToList()); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"INVALID {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"ERROR {0}", e.Message); } return(null); }
//public async Task AddForm(Form form) //{ // if (!IsInitialized) // throw new Exception("Needs to be initialized first"); // if (form == null) // { // form = new Form // { // description = "Sample Form for testin that was added manually", // id = "999-test", // name = "Sample Form", // sections = new List<Section> // { // new Section // { // fields = new List<Field> // { // new Field // { // id = 0, // max = 10000, // min = 0 // } // } // }, // new Section // { // fields = new List<Field> // { // new Field // { // id = 1, // max = 10000, // min = 0 // } // } // } // }, // status = Controls.FormStatus.NotStarted // }; // } // try // { // //await _formTable.InsertAsync(form); // await _MobileService.SyncContext.PushAsync(); // } // catch (Exception e) // { // var t = e; // throw; // } //} public async Task <List <Form> > GetForms() { throw new NotImplementedException(); if (!IsInitialized) { throw new Exception("Needs to be initialized first"); } try { var ret = await _formTable.ReadAsync(); return(ret.ToList()); } catch (Exception e) { var t = e; throw; } }
private async Task SyncAsync() { try { await PushReadsToCloud(); SyncStatus = "Pulling..."; await RouteSyncTable.PullAsync("PullQuery", RouteSyncTable.CreateQuery()); SyncStatus = "Syncronized"; ReadEndpoints = 0; TotalEndpoints = 0; BadLocEndpoints = 0; } catch (Exception e) { SyncStatus = "Error Syncronizing: " + e.Message; } finally { IEnumerable <JsonMeterModel> SyncMeters = await RouteSyncTable.ReadAsync(); foreach (JsonMeterModel model in SyncMeters) { Meters.Add(new MeterModel() { MeterInfo = model, Location = new Geopoint(new BasicGeoposition() { Latitude = model.Latitude, Longitude = model.Longitude }), ReadUpdated = false }); if (Meters.Count == 20) { break; } //await Task.Delay(1); } } }
public async Task <List <Client> > GetClientsList() { try { //Need to get the Addresses first await SyncAddresses(); //Now sync the clients await SyncClients(); var jtoken = await _clientSyncTable.ReadAsync(string.Empty); var clientList = jtoken.ToObject <List <Client> >(); foreach (var client in clientList) { if (!string.IsNullOrWhiteSpace(client.BillingAddressId)) { var address = await GetAddress(client.BillingAddressId); if (address != null) { client.BillingAddress = address; } } } return(clientList); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); string errorMsg = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; Device.BeginInvokeOnMainThread(async() => await Application.Current.MainPage.DisplayAlert("Error Occured", errorMsg, "OK")); } return(new List <Client>()); }
public async Task <List <Job> > GetClientJobs(string clientId) { //Now sync the clients await SyncClientJobs(); var jtoken = await _jobSyncTable.ReadAsync(string.Empty); var jobsList = jtoken.ToObject <List <Job> >(); var clientJobsList = jobsList.Where(x => x.ClientId == clientId); foreach (var job in clientJobsList) { if (!string.IsNullOrWhiteSpace(job.SiteAddressId)) { var address = await GetAddress(job.SiteAddressId); if (address != null) { job.SiteAddress = address; } } } return(clientJobsList.ToList()); }
public async Task <IEnumerable <ImageReference> > GetImages(string categoryId) { var fileHelper = DependencyService.Get <IFileHelper>(); return(await _imageReferenceTable.ReadAsync(_imageReferenceTable.CreateQuery().Where(r => r.CategoryId == categoryId))); }
public async Task Insert_ThenPush_ThenPull_ThenRead_ThenUpdate_ThenRefresh_ThenDelete_ThenLookup_ThenPush_ThenPurge_ThenRead() { ResetDatabase(TestTable); var hijack = new TestHttpHandler(); hijack.AddResponseContent("{\"id\":\"b\",\"String\":\"Hey\"}"); // insert response hijack.AddResponseContent("[{\"id\":\"b\",\"String\":\"Hey\"},{\"id\":\"a\",\"String\":\"World\"}]"); // pull response hijack.AddResponseContent("[]"); // pull last page IMobileServiceClient service = await CreateTodoClient(hijack); IMobileServiceSyncTable <ToDoWithStringId> table = service.GetSyncTable <ToDoWithStringId>(); // first insert an item await table.InsertAsync(new ToDoWithStringId() { Id = "b", String = "Hey" }); // then push it to server await service.SyncContext.PushAsync(); // then pull changes from server await table.PullAsync(null, null); // order the records by id so we can assert them predictably IList <ToDoWithStringId> items = await table.OrderBy(i => i.Id).ToListAsync(); // we should have 2 records Assert.Equal(2, items.Count); // according to ordering a id comes first Assert.Equal("a", items[0].Id); Assert.Equal("World", items[0].String); // then comes b record Assert.Equal("b", items[1].Id); Assert.Equal("Hey", items[1].String); // we made 2 requests, one for push and two for pull Assert.Equal(3, hijack.Requests.Count); // recreating the client from state in the store service = await CreateTodoClient(hijack); table = service.GetSyncTable <ToDoWithStringId>(); // update the second record items[1].String = "Hello"; await table.UpdateAsync(items[1]); // create an empty record with same id as modified record var second = new ToDoWithStringId() { Id = items[1].Id }; // refresh the empty record await table.RefreshAsync(second); // make sure it is same as modified record now Assert.Equal(second.String, items[1].String); // now delete the record await table.DeleteAsync(second); // now try to get the deleted record ToDoWithStringId deleted = await table.LookupAsync(second.Id); // this should be null Assert.Null(deleted); // try to get the non-deleted record ToDoWithStringId first = await table.LookupAsync(items[0].Id); // this should still be there; Assert.NotNull(first); // make sure it is same as Assert.Equal(first.String, items[0].String); // recreating the client from state in the store service = await CreateTodoClient(hijack); table = service.GetSyncTable <ToDoWithStringId>(); await service.SyncContext.PushAsync(); // now purge the remaining records await table.PurgeAsync(); // now read one last time IEnumerable <ToDoWithStringId> remaining = await table.ReadAsync(); // There shouldn't be anything remaining Assert.Empty(remaining); }
public async Task <IEnumerable <Receipt> > GetReceiptsAsync() { await Initialize(); return(await reiciptsTable.ReadAsync()); }
public async Task <IEnumerable <PollQuestion> > GetQuestionsAsync() { await InitializeAsync(); return(await questionsTable.ReadAsync()); }
public async Task <IEnumerable <Idea> > GetIdeasAsync() => await _table.ReadAsync();
public Task <IEnumerable <Category> > GetCategoriesAsync() { return(_categoryTable.ReadAsync(_categoryTable.CreateQuery())); }