/// <summary> /// Public constructor initializing the fields of the AbstractSensor class object. /// </summary> /// <param name="sensorType">Value for the field sensorType.</param> /// <param name="sensorState">Value for the field sensorState.</param> /// <param name="measurementInterval">Value for the field measurementInterval.</param> /// <param name="measuredValue">Value for the field measuredValue.</param> public AbstractSensor(string sensorType, string sensorState, int?measurementInterval, int?measuredValue) { UniqueIdentificator = UniqueSensorIdentifier.getInstance().CreateUniqueSensorIdentifier(); SensorType = sensorType; SensorState = null; MeasurementInterval = measurementInterval; MeasuredValue = 0; }
/// <summary> /// ReadMeasuringSensorsJson method reads measuring sensors from Json. /// </summary> /// <param name="path"> Specifies the path to the json file. </param> /// <returns> A list of objects of the AbstractSensor class. </returns> public List <AbstractSensor> ReadMeasuringSensorsJson(string path) { List <AbstractSensor> ListMeasuringSensor = new List <AbstractSensor>(); using (StreamReader sr = new StreamReader(path)) { string jsonString = File.ReadAllText(path); ReflectionJsonArrayMeasuringSensor reflectionJsonArrayMeasuringSensor = JsonConvert.DeserializeObject <ReflectionJsonArrayMeasuringSensor>(jsonString); UniqueSensorIdentifier uniqueSensorIdentifier = UniqueSensorIdentifier.getInstance(); for (int i = 0; i < reflectionJsonArrayMeasuringSensor.arrayMeasuringSensor.Length; i++) { ListMeasuringSensor.Add(new AbstractSensor(reflectionJsonArrayMeasuringSensor.arrayMeasuringSensor[i]._SensorType, null, reflectionJsonArrayMeasuringSensor.arrayMeasuringSensor[i].MeasurementInterval, null)); } } return(ListMeasuringSensor); }