Beispiel #1
0
 public void CopyTo(SensorMapping sensorMapping)
 {
     sensorMapping.Id = Id;
     sensorMapping.PlantsAreaId = PlantsAreaId;
     sensorMapping.MeasuringTimeout = MeasuringTimeout;
     sensorMapping.MeasurableParameterId = MeasurableParameterId;
     sensorMapping.Type = Type;
 }
Beispiel #2
0
        public Sensor RestoreSensor(SensorMapping sensorMapping, PlantsArea plantsArea)
        {
            try
            {
                MeasurableParameter mp =
                    plantsArea.Plant.MeasurableParameters.SingleOrDefault(
                        m => m != null && m.Id == sensorMapping.MeasurableParameterId);

                if (mp != null)
                {
                    ParameterEnum parameter;
                    bool parsed = Enum.TryParse(mp.MeasurableType, out parameter);

                    if (parsed)
                    {
                        switch (parameter)
                        {
                            case ParameterEnum.Nutrient:
                                return new NutrientSensor(sensorMapping.Id, plantsArea,
                                    new TimeSpan(0, 0, sensorMapping.MeasuringTimeout), mp as Nutrient);
                            case ParameterEnum.SoilPh:
                                return new SoilPhSensor(sensorMapping.Id, plantsArea,
                                    new TimeSpan(0, 0, sensorMapping.MeasuringTimeout), mp as SoilPh);
                            case ParameterEnum.Humidity:
                                return new HumiditySensor(sensorMapping.Id, plantsArea,
                                    new TimeSpan(0, 0, sensorMapping.MeasuringTimeout), mp as Humidity);
                            case ParameterEnum.Temperature:
                                return new TemperatureSensor(sensorMapping.Id, plantsArea,
                                    new TimeSpan(0, 0, sensorMapping.MeasuringTimeout), mp as Temperature);
                        }
                    }
                    //if custom sensor
                    return new CustomSensor(sensorMapping.Id, plantsArea,
                        new TimeSpan(0, 0, sensorMapping.MeasuringTimeout), mp as CustomParameter);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace, $"Sensor Id: {sensorMapping.Id}");
                return null;
            }
            return null;
        }