示例#1
0
 public void CopyTo(PlantMapping plantMapping)
 {
     plantMapping.Id = Id;
     plantMapping.TemperatureId = TemperatureId;
     plantMapping.HumidityId = HumidityId;
     plantMapping.SoilPhId = SoilPhId;
     plantMapping.NutrientId = NutrientId;
     plantMapping.Name = Name;
     plantMapping.CustomParametersIds = CustomParametersIds;
 }
示例#2
0
        public Plant RestorePlant(PlantMapping plantMapping)
        {
            try
            {
                MeasurableParameterMapping temperatureMapping =
                    _sqlMeasurableParameterMappingRepository.Get(plantMapping.TemperatureId);
                MeasurableParameterMapping soilPhMapping =
                    _sqlMeasurableParameterMappingRepository.Get(plantMapping.SoilPhId);
                MeasurableParameterMapping humidityMapping =
                    _sqlMeasurableParameterMappingRepository.Get(plantMapping.HumidityId);
                MeasurableParameterMapping nutrientMapping =
                    _sqlMeasurableParameterMappingRepository.Get(plantMapping.NutrientId);

                Temperature temperature = RestoreMeasurableParameter(temperatureMapping) as Temperature;
                Humidity humidity = RestoreMeasurableParameter(humidityMapping) as Humidity;
                SoilPh soilPh = RestoreMeasurableParameter(soilPhMapping) as SoilPh;
                Nutrient nutrient = RestoreMeasurableParameter(nutrientMapping) as Nutrient;

                PlantNameEnum name = (PlantNameEnum)Enum.Parse(typeof(PlantNameEnum), plantMapping.Name);
                Plant plant = new Plant(plantMapping.Id, temperature, humidity, soilPh, nutrient, name);

                //if custom sensor
                if (!string.IsNullOrEmpty(plantMapping.CustomParametersIds))
                {
                    string[] ids = plantMapping.CustomParametersIds.Split(',');
                    List<MeasurableParameterMapping> measurableParameterMappings =
                        ids.Select(id => _sqlMeasurableParameterMappingRepository.Get(Guid.Parse(id))).ToList();

                    List<MeasurableParameter> measurableParameters =
                        measurableParameterMappings.Select(RestoreMeasurableParameter)
                            .ToList();

                    plant.AddMeasurableParameters(measurableParameters);
                }
                return plant;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace, $"Plant Id: {plantMapping.Id}");
                return null;
            }
        }