Exemplo n.º 1
0
        public async Task <IActionResult> Get(int deviceId)
        {
            var sensor = await _sensorService.Get(deviceId);

            if (sensor == null)
            {
                return(NotFound());
            }
            return(new ObjectResult(sensor));
        }
Exemplo n.º 2
0
        private async Task <Device> GetOrCreateSensor(int deviceId)
        {
            _logger.LogDebug("Find device with id {deviceId}", deviceId);
            var metadata = await _sensorService.Get(deviceId);

            if (metadata == null)
            {
                metadata = new DeviceMetadata {
                    DeviceId = deviceId
                };
                _logger.LogInformation("Saving device {deviceId}", deviceId);
                var result = await _sensorService.Add(metadata);

                if (!result)
                {
                    _logger.LogError("Failed saving device {deviceId}", deviceId);
                    throw new Exception("Unable to add sensor");
                }
                _logger.LogInformation("Device {deviceId} saved", deviceId);
            }
            var device = new Device(metadata);

            return(device);
        }