public static async Task <bool> Toggle(this IManagedScan scan) { if (scan.IsScanning) { scan.Stop(); } else { await scan.Start().ConfigureAwait(false); } return(scan.IsScanning); }
public ManagedScanViewModel(IBleManager bleManager) { this.scanner = bleManager .CreateManagedScanner( RxApp.MainThreadScheduler, TimeSpan.FromSeconds(10) ) .DisposedBy(this.DeactivateWith); this.Toggle = ReactiveCommand.CreateFromTask(async() => this.IsBusy = await this.scanner.Toggle() ); }
public ManagedScanViewModel(IBleManager bleManager, INavigationService navigator) { this.scanner = bleManager .CreateManagedScanner(RxApp.MainThreadScheduler, TimeSpan.FromSeconds(10)) .DisposedBy(this.DeactivateWith); this.Toggle = ReactiveCommand.CreateFromTask(async() => this.IsBusy = await this.scanner.Toggle() ); this.WhenAnyValue(x => x.SelectedPeripheral) .Skip(1) .Where(x => x != null) .Subscribe(async x => { this.SelectedPeripheral = null; this.scanner.Stop(); await navigator.Navigate("ManagedPeripheral", ("Peripheral", x.Peripheral)); }); }