Esempio n. 1
0
        public async Task CreateMeasurement(string deviceUuid, float temperature, float humidity)
        {
            var device = await _deviceRepository.GetDevice(deviceUuid);

            if (device == null)
            {
                await _deviceRepository.CreateDevice(deviceUuid, "unknown device", true);
            }

            if (!_memoryCache.TryGetValue <List <Measurement> >(deviceUuid, out var measurements))
            {
                measurements = new List <Measurement>();
            }

            var measurement = new Measurement
            {
                DeviceUuid = deviceUuid, Humidity = humidity, Temperature = temperature, TimeStamp = DateTime.UtcNow
            };

            measurements.Add(measurement);
            if (measurements.Count > Threshold)
            {
                await _measurementRepository.CreateMeasurements(measurements);

                measurements.Clear();
            }

            _memoryCache.Set(deviceUuid, measurements);
        }