示例#1
0
        public async Task <SocketResponse> ProcessCommandAsync(SocketCommand command)
        {
            await _semaphore.WaitAsync();

            try
            {
                switch (command.Type)
                {
                case SocketCommandType.PIN_OFF:
                    _gpioService.Write((int)command.Parameters[0], Windows.Devices.Gpio.GpioPinValue.Low);
                    return(new SocketResponse(SocketResponseType.OK));

                case SocketCommandType.PIN_ON:
                    _gpioService.Write((int)command.Parameters[0], Windows.Devices.Gpio.GpioPinValue.High);
                    return(new SocketResponse(SocketResponseType.OK));

                case SocketCommandType.PLAY:
                    return(_radioService.Play((RadioStation)command.Parameters[0]));

                case SocketCommandType.STOP:
                    return(_radioService.Stop());

                case SocketCommandType.VOLUME_UP:
                    return(_radioService.VolumeUp());

                case SocketCommandType.VOLUME_DOWN:
                    return(_radioService.VolumeDown());

                case SocketCommandType.GET_RADIO_STATIONS:
                    return(_radioService.GetStations());

                case SocketCommandType.GET_ALARM:
                    return(_alarmService.GetAlarm());

                case SocketCommandType.SET_ALARM:
                    return(_alarmService.SetAlarm((Alarm)command.Parameters[0]));

                default:
                    return(new SocketResponse(SocketResponseType.BAD_REQUEST));
                }
            }
            catch (Exception ex)
            {
                return(new SocketResponse(SocketResponseType.ERROR, ex.ToString()));
            }
            finally
            {
                _semaphore.Release();
            }
        }