예제 #1
0
        public Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
        {
            GeneralCommandType commandType;

            if (Enum.TryParse(command.Name, true, out commandType))
            {
                switch (commandType)
                {
                case GeneralCommandType.VolumeDown:
                    return(_device.VolumeDown());

                case GeneralCommandType.VolumeUp:
                    return(_device.VolumeUp());

                case GeneralCommandType.Mute:
                    return(_device.Mute());

                case GeneralCommandType.Unmute:
                    return(_device.Unmute());

                case GeneralCommandType.ToggleMute:
                    return(_device.ToggleMute());

                case GeneralCommandType.SetVolume:
                {
                    string volumeArg;

                    if (command.Arguments.TryGetValue("Volume", out volumeArg))
                    {
                        int volume;

                        if (int.TryParse(volumeArg, NumberStyles.Any, _usCulture, out volume))
                        {
                            return(_device.SetVolume(volume));
                        }

                        throw new ArgumentException("Unsupported volume value supplied.");
                    }

                    throw new ArgumentException("Volume argument cannot be null");
                }

                default:
                    return(Task.FromResult(true));
                }
            }

            return(Task.FromResult(true));
        }