Example #1
0
        private async Task Execute(ICommand command, CancellationToken ct)
        {
            using var _ = await _gate.LockAsync(ct);

            switch (command)
            {
            case TurnOn on:
            case Toggle toggle when !_state.Value:
                await ScreenHelper.On(ct);

                _state.OnNext(true);
                break;

            case TurnOff off:
            case Toggle toggle:
                await ScreenHelper.Off(ct);

                _state.OnNext(false);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(command), $"Command '{command}' is not supported on Screen");
            }
        }
Example #2
0
 /// <inheritdoc />
 public IObservable <DeviceState> GetAndObserveState()
 => ScreenHelper
 .GetAndObserveState()
 .Select(state => new DeviceState(
             ComputerDeviceId.Screen,
             ImmutableDictionary <string, string> .Empty.Add("state", state == ScreenHelper.ScreenState.Off ? "off" : "on"), true));