private async void ScanForDevices() { if (IsBusy) { return; } IsBusy = true; ScanForDevicesCommand.RaiseCanExecuteChanged(); try { var devices = await HueEndpointsEnumerator.EnumerateDevices(); foreach (var deviceInfo in devices) { var existing = KnownDevices.FirstOrDefault(d => d.Id == deviceInfo.Id); if (existing == null) { KnownDevices.Add(new HueEndpointViewModel(deviceInfo)); } } } finally { IsBusy = false; ScanForDevicesCommand.RaiseCanExecuteChanged(); } }
private void ScanForDevices() { if (IsBusy) { return; } IsBusy = true; ScanForDevicesCommand.RaiseCanExecuteChanged(); try { discoverDevices.BeginDiscover(((DiscoveredSsdpDevice discoveredDevice, SsdpDevice device)deviceInfo) => { var existing = KnownDevices.FirstOrDefault(d => d.Host == deviceInfo.discoveredDevice.DescriptionLocation.Host); if (existing == null) { KnownDevices.Add(new DeviceViewModel(deviceInfo.discoveredDevice, deviceInfo.device)); } }); }
private async void OnScanForDevicesCommand() { if (!ScanningForDevices) { ScanningForDevices = true; ScanForDevicesCommand.RaiseCanExecuteChanged(); if (CrossBleAdapter.Current.Status == AdapterStatus.PoweredOn || CrossBleAdapter.Current.Status == AdapterStatus.Unsupported) { AvailableDevices.Clear(); foundDevices.Clear(); try { bleService.ScanForDevicesCommand(TimeSpan.FromSeconds(10), device => { if (device != null) { foundDevices.Add(device.Name, device); AvailableDevices.Add(device.Name); } }); await Task.Delay(TimeSpan.FromSeconds(10)); ScanningForDevices = false; ScanForDevicesCommand.RaiseCanExecuteChanged(); } catch (Exception e) { // Crashes.TrackError(e); ScanningForDevices = false; ScanForDevicesCommand.RaiseCanExecuteChanged(); } } else { await dialogService.DisplayAlertAsync("Bluetooth", "Please check your Bluetooth Settings", "Ok"); } } }