public ManagedBeaconViewModel(IBeaconRangingManager beaconManager, INavigationService navigator) { this.scanner = beaconManager.CreateManagedScan(); this.navigator = navigator; this.SetRegion = navigator.NavigateCommand( "CreateBeacon", p => p .Set(nameof(BeaconRegion), this.region) .Set("IsRanging", true) ); }
public ManagedScanViewModel(IBeaconRangingManager ranging) { this.scanner = ranging.CreateManagedScan(); this.Start = ReactiveCommand.Create( () => this.scanner.Start(MyRegion, RxApp.MainThreadScheduler) ); this.Stop = ReactiveCommand.Create( () => this.scanner.Stop() ); }
public BeaconViewModel(IBeaconRangingManager ranging, IBeaconMonitoringManager monitoring) { this.Start = ReactiveCommand.Create(() => this.scan = ranging .WhenBeaconRanged(MyRegion) .Subscribe(beacon => { this.Beacons.Add(beacon); }) ); this.Stop = ReactiveCommand.Create(() => this.scan?.Dispose()); this.StartMonitor = ReactiveCommand.CreateFromTask( () => monitoring.StartMonitoring(MyRegion) ); this.StopMonitor = ReactiveCommand.CreateFromTask( () => monitoring.StopAllMonitoring() ); }
public RangingViewModel(INavigationService navigator, IDialogs dialogs, IBeaconRangingManager beaconManager) { this.dialogs = dialogs; this.beaconManager = beaconManager; this.WhenAnyValue(x => x.Uuid) .Select(x => !x.IsEmpty()) .ToPropertyEx(this, x => x.IsRegionSet); this.WhenAnyValue(x => x.Major) .Select(x => !x.IsEmpty()) .ToPropertyEx(this, x => x.IsMajorSet); this.WhenAnyValue(x => x.Minor) .Select(x => !x.IsEmpty()) .ToPropertyEx(this, x => x.IsMinorSet); this.SetRegion = navigator.NavigateCommand( "CreateBeacon", p => p .Set(nameof(BeaconRegion), this.region) .Set("IsRanging", true) ); this.ScanToggle = ReactiveCommand.Create(() => { if (this.scanner == null) { this.StartScan(); } else { this.StopScan(); } }); }
public ManagedScan(IBeaconRangingManager beaconManager) => this.beaconManager = beaconManager;
public CreateViewModel(INavigationService navigator, IDialogs dialogs, IBeaconRangingManager rangingManager, IBeaconMonitoringManager?monitorManager = null) { this.IsMonitoringSupported = monitorManager != null; this.EstimoteDefaults = ReactiveCommand.Create(() => { this.Identifier = "Estimote"; this.Uuid = "B9407F30-F5F8-466E-AFF9-25556B57FE6D"; }); this.WhenAnyValue(x => x.Major) .Select(x => !x.IsEmpty() && UInt16.TryParse(x, out _)) .ToPropertyEx(this, x => x.IsMajorSet); this.StartMonitoring = ReactiveCommand.CreateFromTask( async() => { var result = await monitorManager.RequestAccess(); if (result != AccessState.Available) { await dialogs.AlertAccess(result); } else { await monitorManager.StartMonitoring(this.GetBeaconRegion()); await navigator.GoBack(); } }, this.WhenAny( x => x.Identifier, x => x.Uuid, x => x.Major, x => x.Minor, x => x.NotifyOnEntry, x => x.NotifyOnExit, (idValue, uuidValue, majorValue, minorValue, entry, exit) => { if (monitorManager == null) { return(false); } var atLeast1Notification = entry.GetValue() || exit.GetValue(); if (!atLeast1Notification) { return(false); } return(this.IsValid()); } ) ); this.StartRanging = ReactiveCommand.CreateFromTask( async() => { var result = await rangingManager.RequestAccess(); if (result != AccessState.Available) { await dialogs.AlertAccess(result); } else { var region = this.GetBeaconRegion(); await navigator.GoBack(false, (nameof(BeaconRegion), region)); } }, this.WhenAny( x => x.Identifier, x => x.Uuid, x => x.Major, x => x.Minor, (idValue, uuidValue, majorValue, minorValue) => this.IsValid() ) ); }
public static ManagedScan CreateManagedScan(this IBeaconRangingManager manager) => new ManagedScan(manager);