public async Task <bool> AddBache(double latitude, double longitude, Stream photo) { try { var imageurl = await App.Authenticator.UploadImage(photo); var coffee = new Bache { Latitude = latitude, Longitude = longitude, PhotoUrl = imageurl, DateUtc = DateTime.UtcNow, }; await bacheTable.InsertAsync(coffee); await SyncBaches(); return(true); } catch { return(false); } }
/// <summary> /// Task for pushing receivied and parsed meters into the local sqlite database. /// </summary> /// <returns></returns> private async Task SyncReadQueue() { JsonMeterModel MeterToSync; while (IsR2Initialized && IsR2Listening) { SyncStatus = MeterSyncQueue.Count + " Meters in Update Queue"; if (MeterSyncQueue.Any()) { try { MeterToSync = MeterSyncQueue.Dequeue(); if (Meters.Where(meter => meter.MeterInfo.MeterId == MeterToSync.MeterId).Any()) { await RouteSyncTable.UpdateAsync(MeterToSync); } else { await RouteSyncTable.InsertAsync(MeterToSync); } } catch (Exception ex) { SyncStatus = ex.Message; } } } }
public async void AddItem(View view) { if (client == null || string.IsNullOrWhiteSpace(textNewToDo.Text)) { return; } // Create a new item var item = new ToDoItem { Text = textNewToDo.Text, Complete = false }; try { // Insert the new item into the local store. await todoTable.InsertAsync(item); #if OFFLINE_SYNC_ENABLED // Send changes to the mobile app backend. await SyncAsync(); #endif if (!item.Complete) { adapter.Add(item); } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } textNewToDo.Text = ""; }
public async Task AddNote(Notes notes) { // var table = _mobileServiceClient.GetTable<Notes>(); await SyncNotes(); await _notesTable.InsertAsync(notes); }
public async void AddBeacon(View view) { if (client == null || string.IsNullOrWhiteSpace(textNewToDo.Text)) { return; } // Create a new item var beacon = new Beacon { //Text = textNewToDo.Text //add collum = value //for each collumn //leave complete it is nessecary for the localdb Complete = false }; try { await beaconTable.InsertAsync(beacon); // insert the new item into the local database await SyncAsync(); // send changes to the mobile service if (!beacon.Complete) { adapter.Add(beacon); } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } textNewToDo.Text = ""; }
public async Task ReadAsync_RoundTripsDate_Generic() { string tableName = "NotSystemPropertyCreatedAtType"; ResetDatabase(tableName); var store = new MobileServiceSQLiteStore(TestDbName); store.DefineTable <NotSystemPropertyCreatedAtType>(); var hijack = new TestHttpHandler(); IMobileServiceClient service = await CreateClient(hijack, store); IMobileServiceSyncTable <NotSystemPropertyCreatedAtType> table = service.GetSyncTable <NotSystemPropertyCreatedAtType>(); DateTime theDate = new DateTime(2014, 3, 10, 0, 0, 0, DateTimeKind.Utc); var inserted = new NotSystemPropertyCreatedAtType() { CreatedAt = theDate }; await table.InsertAsync(inserted); Assert.AreEqual(inserted.CreatedAt.ToUniversalTime(), theDate); NotSystemPropertyCreatedAtType rehydrated = await table.LookupAsync(inserted.Id); Assert.AreEqual(rehydrated.CreatedAt.ToUniversalTime(), theDate); }
public async Task SaveAccountAsync(Account item) { try { using (var handle = Insights.TrackTime("TimeToSaveAccount")) { if (item.Id == null) { await _AccountTable.InsertAsync(item); } else { await _AccountTable.UpdateAsync(item); } } } catch (MobileServiceInvalidOperationException ex) { Insights.Report(ex, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex.Message); } catch (Exception ex2) { Insights.Report(ex2, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex2.Message); } }
public async void Add(T item) { await table.InsertAsync(item); itemCount++; NotifyItemInserted(ItemCount - 1); }
public async Task <bool> SaveUserAsync(User _user) { // if the email field is null, create a new user in azure await Initialize(); try { if (_user.email == null) { await UserTable.InsertAsync(_user); } // else, the user is updating their preferred default location else { await UserTable.UpdateAsync(_user); } await SyncUserAsync(); return(true); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(false); } }
public async Task PushAsync_DoesNotRunHandler_WhenTableTypeIsNotTable() { var hijack = new TestHttpHandler(); hijack.AddResponseContent("{\"id\":\"abc\",\"version\":\"Hey\"}"); bool invoked = false; var handler = new MobileServiceSyncHandlerMock(); handler.TableOperationAction = op => { invoked = true; throw new InvalidOperationException(); }; IMobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack); await service.SyncContext.InitializeAsync(new MobileServiceLocalStoreMock(), handler); IMobileServiceSyncTable table = service.GetSyncTable("someTable"); await table.InsertAsync(new JObject() { { "id", "abc" }, { "version", "Wow" } }); await(service.SyncContext as MobileServiceSyncContext).PushAsync(CancellationToken.None, (MobileServiceTableKind)1); Assert.IsFalse(invoked); }
public async Task PushAsync_InvokesHandler_WhenTableTypeIsTable() { var hijack = new TestHttpHandler(); hijack.Responses.Add(new HttpResponseMessage(HttpStatusCode.InternalServerError)); bool invoked = false; var handler = new MobileServiceSyncHandlerMock(); handler.TableOperationAction = op => { invoked = true; return(Task.FromResult(JObject.Parse("{\"id\":\"abc\",\"version\":\"Hey\"}"))); }; IMobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack); await service.SyncContext.InitializeAsync(new MobileServiceLocalStoreMock(), handler); IMobileServiceSyncTable table = service.GetSyncTable("someTable"); await table.InsertAsync(new JObject() { { "id", "abc" }, { "version", "Wow" } }); await(service.SyncContext as MobileServiceSyncContext).PushAsync(CancellationToken.None, MobileServiceTableKind.Table); Assert.IsTrue(invoked); }
public async Task PushAsync_FeatureHeaderPresentWhenRehydrated() { var hijack = new TestHttpHandler(); IMobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack); var store = new MobileServiceLocalStoreMock(); await service.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()); IMobileServiceSyncTable table = service.GetSyncTable("someTable"); JObject item1 = new JObject() { { "id", "abc" } }; await table.InsertAsync(item1); // create a new service to test that operations are loaded from store hijack = new TestHttpHandler(); hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}"); service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack); await service.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()); await service.SyncContext.PushAsync(); Assert.AreEqual(hijack.Requests[0].Headers.GetValues("X-ZUMO-FEATURES").First(), "TU,OL"); }
public async Task <int> InsertRecentContact(Contact requester, Contact respondent) { await SyncAsyncRecentContact(true); RecentContact recentContact = new RecentContact() { RequesterId = requester.Id, RequesterFirstName = requester.FirstName, RequesterLastName = requester.LastName, RequesterDepartment = requester.Department, RespondentId = respondent.Id, RespondentFirstName = respondent.FirstName, RespondentLastName = respondent.LastName, RespondentDepartment = respondent.Department, RequestedAt = DateTime.Now, RequesterFullName = requester.FirstName + ", " + requester.LastName, RespondentFullName = respondent.FirstName + ", " + respondent.LastName, RequestedAtString = DateTime.Now.ToString() }; await azureSyncTableRecentContact.InsertAsync(recentContact); await SyncAsyncRecentContact(); return(1); }
private async Task InsertTodoItem(TodoItem todoItem) { // This code inserts a new TodoItem into the database. After the operation completes // and the mobile app backend has assigned an id, the item is added to the CollectionView. try { await todoTable.InsertAsync(todoItem); items.Add(todoItem); } catch (System.Net.Http.HttpRequestException ex) { ContentDialog deleteFileDialog = new ContentDialog { FontSize = 10, Title = "Network Error", PrimaryButtonText = "Home" }; ContentDialogResult result = await deleteFileDialog.ShowAsync(); this.Frame.Navigate(typeof(ServerMenuPage)); } #if OFFLINE_SYNC_ENABLED await App.MobileService.SyncContext.PushAsync(); // offline sync #endif }
public async Task InsertAsync_Throws_IfItemAlreadyExistsInLocalStore() { ResetDatabase(TestTable); var store = new MobileServiceSQLiteStore(TestDbName); store.DefineTable(TestTable, new JObject() { { "id", String.Empty }, { "String", String.Empty } }); var hijack = new TestHttpHandler(); IMobileServiceClient service = await CreateClient(hijack, store); string pullResult = "[{\"id\":\"abc\",\"String\":\"Wow\"}]"; hijack.AddResponseContent(pullResult); hijack.AddResponseContent("[]"); IMobileServiceSyncTable table = service.GetSyncTable(TestTable); await table.PullAsync(null, null); var ex = await AssertEx.Throws <MobileServiceLocalStoreException>(() => table.InsertAsync(new JObject() { { "id", "abc" } })); Assert.AreEqual(ex.Message, "An insert operation on the item is already in the queue."); }
public async Task AddActivity(Activities activity) { //await Initialize await _activities.InsertAsync(activity); //await SyncActivties(); }
public async Task ReadAsync_RoundTripsDate() { string tableName = "itemWithDate"; ResetDatabase(tableName); var store = new MobileServiceSQLiteStore(TestDbName); store.DefineTable(tableName, new JObject() { { "id", String.Empty }, { "date", DateTime.Now } }); var hijack = new TestHttpHandler(); IMobileServiceClient service = await CreateClient(hijack, store); IMobileServiceSyncTable table = service.GetSyncTable(tableName); DateTime theDate = new DateTime(2014, 3, 10, 0, 0, 0, DateTimeKind.Utc); JObject inserted = await table.InsertAsync(new JObject() { { "date", theDate } }); Assert.AreEqual(inserted["date"].Value <DateTime>(), theDate); JObject rehydrated = await table.LookupAsync(inserted["id"].Value <string>()); Assert.AreEqual(rehydrated["date"].Value <DateTime>(), theDate); }
public async Task AddMeasurement(Measurements m) { //await Initialize await _measurements.InsertAsync(m); await SyncMeasurements(); }
public async Task <User> addUser(User user) { await Initialize(); try { await userTable.InsertAsync(user); await SyncTable(); User result = await userTable.LookupAsync(user.Id); user.UserId = result.UserId; } catch (Exception e) { await userTable.DeleteAsync(user); await userTable.PullAsync("allUsers", userTable.CreateQuery()); Debug.WriteLine("Couldn't add user:" + user, e); throw e; } UserHydrateLvl userHydratelvl = new UserHydrateLvl(user.UserId); await mobileService.GetTable <UserHydrateLvl>().InsertAsync(userHydratelvl); return(user); }
public async Task <Models.Product> SaveProductAsync(Models.Product item) { try { if (item.Id == null) { if ((await this.productTable.ToEnumerableAsync()).Any()) { int lastProductNumber = (await this.productTable.Select(c => int.Parse(c.ProductNumber.TrimStart('P'))).ToListAsync()).Max(); item.ProductNumber = $"P{lastProductNumber + 1}"; } else { item.ProductNumber = "P0001"; } await productTable.InsertAsync(item); } else { await productTable.UpdateAsync(item); } } catch (Exception e) { Debug.WriteLine("Save error: {0}", new[] { e.Message }); return(null); } this.messenger.Publish <ProductUpdatedMessage>(new ProductUpdatedMessage(this, item)); return(item); }
public async void AddBeacon(View view) { if (client == null) { return; } // Create a new item var beacon = new caapa.Beacon { //add collum = value //for each collumn //leave complete it is nessecary for the localdb //this may need to wait for the gui integration Complete = false }; try { await beaconTable.InsertAsync(beacon); // insert the new item into the local database await SyncAsync(); // send changes to the mobile service if (!beacon.Complete) { beaconadapter.Add(beacon); } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } }
public async Task <Models.Vendor> SaveVendorAsync(Models.Vendor item) { try { if (item.Id == null) { if ((await this.vendorTable.ToEnumerableAsync()).Any()) { int lastVendorNumber = (await this.vendorTable.Select(c => int.Parse(c.VendorNumber.TrimStart('V'))).ToListAsync()).Max(); item.VendorNumber = $"V{lastVendorNumber + 1}"; } else { item.VendorNumber = "V000001"; } await vendorTable.InsertAsync(item); } else { await vendorTable.UpdateAsync(item); } } catch (Exception e) { Debug.WriteLine("Save error: {0}", new[] { e.Message }); return(null); } this.messenger.Publish <VendorUpdatedMessage>(new VendorUpdatedMessage(this, item)); return(item); }
public async Task AddVehicleAsync(Vehicle vehicle) { try { Debug.WriteLine("Inserting vehicle..."); await vehicles.InsertAsync(vehicle); Debug.WriteLine("Adding vehicle to offline database..."); Items.Add(vehicle); Debug.WriteLine("Syncing offline database..."); await SyncAsync(); } catch { } }
public async Task AddUpdateItemAsync(FocaccePost focaccePost) { try { IMobileServiceSyncTable <FocaccePost> Focacciatable = client.GetSyncTable <FocaccePost>(); if (string.IsNullOrEmpty(focaccePost.Id)) { //e' un inserimento await Focacciatable.InsertAsync(focaccePost); } else { //è una modifica await Focacciatable.UpdateAsync(focaccePost); } //await PushModifiche(); } catch (Exception e) { throw; } }
//Add a new Facilitator public async Task AddFaci(Faci faci) { await Initialize(); await SyncSpeakers(); await table.InsertAsync(faci); }
public async Task ReadAsync_RoundTripsBytes() { const string tableName = "bytes_test_table"; ResetDatabase(tableName); var store = new MobileServiceSQLiteStore(TestDbName); store.DefineTable(tableName, new JObject { { "id", String.Empty }, { "data", new byte[0] } }); var hijack = new TestHttpHandler(); IMobileServiceClient service = await CreateClient(hijack, store); IMobileServiceSyncTable table = service.GetSyncTable(tableName); byte[] theData = { 0, 128, 255 }; JObject inserted = await table.InsertAsync(new JObject { { "data", theData } }); Assert.AreEquivalent(theData, inserted["data"].Value <byte[]>()); JObject rehydrated = await table.LookupAsync(inserted["id"].Value <string>()); Assert.AreEquivalent(theData, rehydrated["data"].Value <byte[]>()); }
public async Task <Booking> AddBooking(string clientName, int slot, DateTime picked, string pro, string email) { await Initialize(); Random rnd = new Random(); int Id = rnd.Next(1, 10000); var coffee = new Booking() { Id = Id.ToString(), BookingName = clientName, Date = picked, Slot = slot, Procedure = pro, Email = email }; await BookingsTable2.InsertAsync(coffee); await SyncBookings(); await DisplayAlert("Alert", "Booking is complete", "ok"); return(coffee); }
public async Task ReadAsync_RoundTripsBytes_Generic() { const string tableName = "BytesType"; ResetDatabase(tableName); var store = new MobileServiceSQLiteStore(TestDbName); store.DefineTable <BytesType>(); var hijack = new TestHttpHandler(); IMobileServiceClient service = await CreateClient(hijack, store); IMobileServiceSyncTable <BytesType> table = service.GetSyncTable <BytesType>(); byte[] theData = { 0, 128, 255 }; BytesType inserted = new BytesType { Data = theData }; await table.InsertAsync(inserted); Assert.AreEquivalent(inserted.Data, theData); BytesType rehydrated = await table.LookupAsync(inserted.Id); Assert.AreEquivalent(rehydrated.Data, theData); }
public async void AddItem(View view) { if (client == null || string.IsNullOrWhiteSpace(textNewToDo.Text)) { return; } // Create a new item var item = new ToDoItem { Text = textNewToDo.Text, Complete = false }; try { await toDoTable.InsertAsync(item); // insert the new item into the local database await SyncAsync(); // send changes to the mobile service if (!item.Complete) { adapter.Add(item); } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } textNewToDo.Text = ""; }
public async Task <BarberSchedule> AddSchedule(string service, string name, string phoneNumber, string email, string birthday, DateTime dateTime) { await Initialize(); DateTime inicioHorarioVerao = new DateTime(DateTime.Now.Year, 11, 4, 0, 0, 0); DateTime terminoHorarioVerao = new DateTime(DateTime.Now.Year + 1, 2, 16, 23, 59, 59); int depoisinicioHorarioDeVerao = DateTime.Compare(dateTime, inicioHorarioVerao); int antesTerminoHorarioDeVerao = DateTime.Compare(terminoHorarioVerao, dateTime); if (depoisinicioHorarioDeVerao > 0 && antesTerminoHorarioDeVerao > 0) { TimerZone = -2; } else { TimerZone = -3; } var schedule = new BarberSchedule { Service = service, Name = name, PhoneNumber = phoneNumber, Email = email, Birthday = birthday, DateTime = dateTime.AddHours(TimerZone) }; await scheduleTable.InsertAsync(schedule); await SyncSchedule(); return(schedule); }