Exemple #1
0
        public ReadSensorCommandResult Read(string sensorId)
        {
            ReadSensorCommand command = new ReadSensorCommand();

            command.SetSensorId(sensorId);

            return(Execute <ReadSensorCommand, ReadSensorCommandResult>(command));
        }
Exemple #2
0
        public async Task <ReadSensorCommandResult> Handle(ReadSensorCommand command)
        {
            ReadSensorCommandResult result = new ReadSensorCommandResult();

            ObjectId sensorId = new ObjectId();

            if (!ObjectId.TryParse(command.SensorId, out sensorId))
            {
                AddNotification(nameof(command.SensorId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                Sensor sensor = _sensorRepository.Get(sensorId);

                if (sensor == null && _sensorRepository.Valid)
                {
                    AddNotification(nameof(command.SensorId), ENotifications.NotFound);
                }

                if (Valid)
                {
                    decimal value = await _arduinoCommunicationService.Sensors.GetValue(new GetSensorValueQuery(sensor.PinPort, sensor.Type));

                    if (_arduinoCommunicationService.Sensors.Valid)
                    {
                        result = new ReadSensorCommandResult(HttpStatusCode.OK, value);
                    }
                }

                else
                {
                    result = new ReadSensorCommandResult(HttpStatusCode.BadRequest, Notifications);
                }
            }

            else
            {
                result = new ReadSensorCommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }