private async void Button_Click_1(object sender, RoutedEventArgs e) { var client = DigitServiceBuilder.Get(); if (ResultsListView.SelectedItem is BluetoothLEDeviceDisplay selected) { bool claimed = false; try { claimed = await client.Device["12345"].ClaimAsync(); } catch (DigitServiceException exc) { await client.LogAsync($"Could not claim device: ${exc.Message}"); } if (claimed) { var opts = new DigitBLEOptions(); opts.StoreDeviceId(selected.Id); DigitId = selected.Id; var bleClient = new DigitBLEClient(opts); bool paired = false; try { paired = await bleClient.Pair(); } catch (DigitBLEExpcetion ex) { await client.LogAsync($"Pairing failed: {ex.Message}", 3); } var pairInformation = paired ? "(paired)" : ""; await client.LogAsync($"Selected device {selected.Id} as digit{pairInformation}."); var man = new BackgroundManager(); man.RegisterDeviceConnectionBackgroundTask(selected.Id); } } }
private async Task ConfigureTasks() { bool isInternetConnected = NetworkInterface.GetIsNetworkAvailable(); if (!isInternetConnected) { ContentDialog noWifiDialog = new ContentDialog { Title = "No Network connection", Content = "Check your connection and try again.", CloseButtonText = "Ok" }; ContentDialogResult result = await noWifiDialog.ShowAsync(); } else { var authenticationProvider = DigitServiceBuilder.AuthenticationProvider(); if (!await authenticationProvider.HasValidAccessToken()) { await authenticationProvider.AuthenticateUser(); } var client = DigitServiceBuilder.Get(); var man = new BackgroundManager(); if (await man.CheckAccess()) { man.RegisterPushChannel(); man.RegisterPushBackgroundTask(); man.RegisterAdvertisementWatcherTask(); man.RegisterGeolocationTasks(); man.RegisterTimeTriggerTask(); //man.RegisterActivityTriggerTask(); } else { await client.LogAsync("Background tasks disabled", 3); } } }