public async void RefreshDevicesList() { NoBluetooth = false; BluetoothDisabled = false; NoDevicesPaired = false; Devices.Clear(); var result = await _commandRunner.Enqueue(new ListDevicesCommand()).AsTask(); if (result.Status != CommandStatus.Succeeded) { DiagnoseProblem(); return; } foreach (var deviceInfoViewModel in result.Devices.Select(t => new DeviceInfoViewModel(t))) { Devices.Add(deviceInfoViewModel); } SortAndUpdateDisplayedCollection(); if (Devices.Count == 0) { DiagnoseProblem(); } }
public async void Write() { var format = SelectedDisplayFormat.Model; if (format == BytesDisplayFormat.Auto) { format = BytesFormatting.DetectFormatAuto(BytesString); } Debug.Assert(format != BytesDisplayFormat.None); Debug.Assert(format != BytesDisplayFormat.Auto); var bytes = BytesFormatting.TryParse(BytesString, format); if (bytes == null) { return; } try { CanWrite = false; var result = await _commandRunner .Enqueue(new WriteBytesCommand(_characteristicInfo, bytes, WriteWithoutResponce) { BytesDisplayFormat = format }) .AsTask().ConfigureAwait(true); } finally { CanWrite = true; } }
public async void Enqueue_WhenCalledWithUiThreadCommand_ShouldExecuteOnUiThread() { var invoked = false; var customUiThreadInstance = new CommandRunner(action => { invoked = true; action(); return(Task.FromResult(0)); }); // Prepare var command = new TestCommand { RunOnUiThread = true }; // Execute customUiThreadInstance.Enqueue(command); // Wait await command.AsTask().ConfigureAwait(true); // Verify Assert.True(invoked); }
public async void Enqueue_WhenCalled_ShouldExecuteCommand() { var invoked = false; // Prepare var command = new TestCommand { ExecuteAction = () => invoked = true }; // Execute _instance.Enqueue(command); // Wait await command.AsTask().ConfigureAwait(true); // Verify Assert.True(invoked); }
public async void Disconnect() { await _commandRunner.Enqueue(new DisconnectDeviceCommand()).AsTask().ConfigureAwait(true); TryClose(); }