public async Task <ActionResult> UpdateSensorsValues() { //ICollection<{SensorIdICB}> IEnumerable <string> supportedSensors = this.DBService.GetRegisteredSensorTypes(); //IEnumerable<string> supportedSensors = await this.APIService.ListSupportedSensorTypesFromAPI(); why the hell from api //IDictionary<{SensorIdICB}, {MeasurementReadIn}> IDictionary <string, APIMeasure> currentSensorsMeasures = new Dictionary <string, APIMeasure>(); foreach (string SensorIdICB in supportedSensors) { APIMeasure measurementICB = await this.APIService.GetCurrentSensorValueFromAPI(SensorIdICB); DateTime convertedDate = Convert.ToDateTime(measurementICB.TimeStamp); DateTime checkDate = convertedDate.AddSeconds(10.0); if (checkDate < DateTime.Now) { measurementICB.Value = "Sensor offline"; } //IDictionary<{SensorIdICB}, {MeasurementReadIn}> currentSensorsMeasures.Add(SensorIdICB, measurementICB); } IEnumerable <LastValue> allSensorsLastValues = this.DBService.GetAllSensorsLastValues(); if (allSensorsLastValues.Count() != 0) { ICollection <History> measurements = new List <History>(); foreach (LastValue lastValue in allSensorsLastValues) { APIMeasure currentMeasure = currentSensorsMeasures[lastValue.SensorIdICB]; if (currentMeasure.Value != lastValue.Value) { History measurement = new History { SensorId = lastValue.SensorId, From = lastValue.From, To = DateTime.Now, Value = currentMeasure.Value }; measurements.Add(measurement); } } this.DBService.AddNewMeasurementsToDb(measurements); } return(this.View()); }
public virtual async Task <APIMeasure> GetCurrentSensorValueFromAPI(string SensorIdICB) { Guard.WhenArgument(SensorIdICB, "SensorIdICB in APIService.GetCurrentSensorValueFromAPI").IsNull().Throw(); string url = string.Format("{0}{1}", coreURL, SensorIdICB); string jsonString = await this.GetJson(url); APIMeasure sensorCurrentValue = JsonConvert.DeserializeObject <APIMeasure>(jsonString); return(sensorCurrentValue); }