示例#1
0
        public override IValidationResult IsValid(UpdateHumidifierTaskProcessorRequestVersionOne record)
        {
            var existingRelays  = _relayClient.GetRelays();
            var existingSensors = _sensorClient.GetSensors();
            var jobExists       = JobStateHelper.GetJobByName(record.JobName) != null;

            if (record?.RelayGpio != null && !existingRelays.Any(r => r.GpioPin == record.RelayGpio))
            {
                return(new ValidationResult
                {
                    Message = $"Could not find a relay with the gpio pin: {record.RelayGpio}",
                    StatusCode = System.Net.HttpStatusCode.NotFound
                });
            }

            if (record?.HumiditySensorGpio != null && !existingSensors.Any(r => r.GpioPin == record.HumiditySensorGpio))
            {
                return(new ValidationResult
                {
                    Message = $"Could not find a sensor with the gpio pin: {record.HumiditySensorGpio}",
                    StatusCode = System.Net.HttpStatusCode.NotFound
                });
            }

            if (!jobExists)
            {
                return(new ValidationResult
                {
                    Message = $"Could not find any jobs with the name: {record.JobName}",
                    StatusCode = System.Net.HttpStatusCode.NotFound
                });
            }

            return(null);
        }
示例#2
0
        public override IValidationResult IsValid(GetSensorReadingByGpioProcessorRequestVersionOne record)
        {
            var existingSensors = _sensorClient.GetSensors();

            if (existingSensors.FirstOrDefault(r => r.GpioPin == record?.GpioPin) != null)
            {
                return(null);
            }

            return(new ValidationResult
            {
                Message = $"Could not find a sensor with the gpio pin: {record.GpioPin}",
                StatusCode = System.Net.HttpStatusCode.NotFound
            });
        }
        public override IActionResult ProcessRequest(GetSensorsProcessorRequestVersionOne record)
        {
            var result = new GetSensorsProcessorResponseVersionOne
            {
                Errors = new List <string> {
                    "No sensors exist"
                },
                IsSuccess  = false,
                Sensors    = null,
                StatusCode = System.Net.HttpStatusCode.NotFound
            };

            var sensors = _sensorClient.GetSensors();

            if (sensors.Any())
            {
                result.Errors     = null;
                result.Sensors    = sensors;
                result.StatusCode = System.Net.HttpStatusCode.OK;
                result.IsSuccess  = true;
            }

            return(new ObjectResult(result));
        }