public MainPageViewModel() { if (App.Current.Properties.ContainsKey("defaultPrinter")) { string guidName = App.Current.Properties["defaultPrinter"].ToString(); _connectedDisposable = _centralManager.GetConnectedPeripherals().Subscribe(scanResult => { scanResult.ToList().ForEach( item => { if (!string.IsNullOrEmpty(item.Name) && item.Name == guidName) { Peripherals.Add(item); _centralManager.StopScan(); Device.BeginInvokeOnMainThread(async() => { await App.Current.MainPage.Navigation.PushAsync(new PrintPage(item)); SelectedPeripheral = null; }); _scanDisposable?.Dispose(); IsScanning = _centralManager.IsScanning; } }); _connectedDisposable?.Dispose(); }); if (_centralManager.IsScanning) { _centralManager.StopScan(); } if (_centralManager.Status == Shiny.AccessState.Available && !_centralManager.IsScanning) { _scanDisposable = _centralManager.ScanForUniquePeripherals().Subscribe(scanResult => { if (!string.IsNullOrEmpty(scanResult.Name) && !Peripherals.Contains(scanResult)) { Peripherals.Add(scanResult); Device.BeginInvokeOnMainThread(async() => { await App.Current.MainPage.Navigation.PushAsync(new PrintPage(scanResult)); SelectedPeripheral = null; }); } }); } } else { GetDeviceListCommand = new Command(GetDeviceList); SetAdapterCommand = new Command(async() => await SetAdapter()); CheckPermissionsCommand = new Command(async() => await CheckPermissions()); CheckPermissionsCommand.Execute(null); } }
public void AddPeripheral(IPeripheral peripheral) { if (Peripherals.Contains(peripheral)) { // public const string ExistingPeripheral = "Peripheral {0} already exists in {1} with Id {2}."; throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id)); } else { peripherals.Add(peripheral); //public const string AddedPeripheral = "Peripheral {0} with id {1} added successfully in computer with id {2}."; //Console.WriteLine(string.Format(Common.Constants.SuccessMessages.AddedComponent, peripheral.GetType(), peripheral.Id, this.Id)); } }
void GetDeviceList() { if (_centralManager.IsScanning) { _scanDisposable?.Dispose(); } else { if (_centralManager.Status == Shiny.AccessState.Available && !_centralManager.IsScanning) { _scanDisposable = _centralManager.ScanForUniquePeripherals().Subscribe(scanResult => { if (!string.IsNullOrEmpty(scanResult.Name) && !Peripherals.Contains(scanResult)) { Peripherals.Add(scanResult); } }); } } IsScanning = _centralManager.IsScanning; }
public bool Contains(IPeripheral peripheral) { return(Peripherals.Contains(peripheral)); }