예제 #1
0
        public async Task <decimal> Get(int id, MetricType type, decimal value)
        {
            _logger.LogDebug("Get sensor");
            var device = await _currentSensorValues.SetSensorData(id, type, value);

            if (device == null)
            {
                _logger.LogError("Faild to set measurement in cache");
            }

            _logger.LogDebug("Save to elastic");
            var client      = new Nest.ElasticClient(new Uri(_config.Value.MetricsDatabase));
            var now         = DateTime.Now;
            var measurement = new Measument
            {
                DeviceId  = id.ToString(),
                Type      = MetricType.Temperature,
                Position  = device.Metadata.Location,
                Timestamp = now,
                Value     = value
            };
            var elasticResult = await client.IndexAsync <Measument>(measurement, s => s.Index("measurement-2017"));

            if (!elasticResult.IsValid)
            {
                _logger.LogError("Failed to save measurement");
            }
            return(device.Metadata.Value ?? 10M);
        }