Example #1
0
        public Plant(Guid id, Temperature temperature, Humidity humidity, SoilPh soilPh,
            Nutrient nutrient, PlantNameEnum name)
        {
            Id = id;
            Name = name;

            Temperature = temperature;
            Humidity = humidity;
            SoilPh = soilPh;
            Nutrient = nutrient;

            MeasurableParameters = new List<MeasurableParameter>
            {
                Temperature,
                Humidity,
                SoilPh,
                Nutrient
            };
        }
Example #2
0
 public HumiditySensor(Guid id, PlantsArea plantsArea, TimeSpan measuringTimeout, Humidity humidity) 
     : base(id, plantsArea, measuringTimeout, humidity)
 {
     Function = new HumidityFunction(humidity);
 }
Example #3
0
 public HumidityFunction(Humidity humidity)
     : base(humidity)
 {
 }
Example #4
0
        private PlantsArea GetPlantsArea()
        {
            try
            {
                PlantNameEnum plantName = (PlantNameEnum) Enum.Parse(typeof (PlantNameEnum),
                    PlantNameBox.SelectionBoxItem.ToString());
                int number = Convert.ToInt32(Number.Text);

                int optimalT = Convert.ToInt32(OptimalTemperature.Text);
                int minT = Convert.ToInt32(MinTemperature.Text);
                int maxT = Convert.ToInt32(MaxTemperature.Text);
                Temperature temperature = new Temperature(Guid.NewGuid(), optimalT, minT, maxT);

                if (!temperature.HasValidParameters())
                {
                    throw new ApplicationException("Fields for Temperature are not valid - numeric values >= 0 and <= 100!");
                }

                int optimalH = Convert.ToInt32(OptimalHumidity.Text);
                int minH = Convert.ToInt32(MinHumidity.Text);
                int maxH = Convert.ToInt32(MaxHumidity.Text);
                Humidity humidity = new Humidity(Guid.NewGuid(), optimalH, minH, maxH);

                if (!humidity.HasValidParameters())
                {
                    throw new ApplicationException("Fields for Humidity are not valid - numeric values >= 0 and <= 100!");
                }

                int optimalS = Convert.ToInt32(OptimalSoilPh.Text);
                int minS = Convert.ToInt32(MinSoilPh.Text);
                int maxS = Convert.ToInt32(MaxSoilPh.Text);
                SoilPh soilPh = new SoilPh(Guid.NewGuid(), optimalS, minS, maxS);

                if (!soilPh.HasValidParameters())
                {
                    throw new ApplicationException("Fields for SoilPh are not valid - numeric values >= 0 and <= 100!");
                }

                int optimalN = Convert.ToInt32(OptimalNutrient.Text);
                int minN = Convert.ToInt32(MinNutrient.Text);
                int maxN = Convert.ToInt32(MaxNutrient.Text);
                Nutrient nutrient = new Nutrient(Guid.NewGuid(), optimalN, minN, maxN);

                if (!nutrient.HasValidParameters())
                {
                    throw new ApplicationException("Fields for Nutrient are not valid - numeric values >= 0 and <= 100!");
                }

                Plant plant = new Plant(Guid.NewGuid(), temperature, humidity, soilPh, nutrient, plantName);

                PlantsArea plantsArea = new PlantsArea(Guid.NewGuid(), default(Guid), plant, number);

                try
                {
                    TimeSpan temperatureTimeout = TimeSpan.Parse(TemperatureTimeout.Text);
                    TimeSpan humidityTimeout = TimeSpan.Parse(HumidityTimeout.Text);
                    TimeSpan soilPhTimeout = TimeSpan.Parse(SoilPhTimeout.Text);
                    TimeSpan nutrientTimeout = TimeSpan.Parse(NutrientTimeout.Text);

                    Sensor ts = new TemperatureSensor(Guid.NewGuid(), plantsArea, temperatureTimeout, temperature);
                    if (TemperatureCheckBox.IsChecked != null && !(bool) TemperatureCheckBox.IsChecked){ts.IsOffByUser = true;}

                    Sensor hs = new HumiditySensor(Guid.NewGuid(), plantsArea, humidityTimeout, humidity);
                    if (HumidityCheckBox.IsChecked != null && !(bool) HumidityCheckBox.IsChecked){hs.IsOffByUser = true;}

                    Sensor ss = new SoilPhSensor(Guid.NewGuid(), plantsArea, soilPhTimeout, soilPh);
                    if (SoilPhCheckBox.IsChecked != null && !(bool) SoilPhCheckBox.IsChecked){ss.IsOffByUser = true;}

                    Sensor ns = new NutrientSensor(Guid.NewGuid(), plantsArea, nutrientTimeout, nutrient);
                    if (NutrientCheckBox.IsChecked != null && !(bool) NutrientCheckBox.IsChecked){ns.IsOffByUser = true;}

                }
                catch (Exception)
                {
                    MessageBox.Show(@"Please, fill in all timeouts with TimeSpan values >= 0!");
                    return null;
                }

                plantsArea.ServicesSchedulesStates.AddServiceSchedule(new ServiceSchedule(Guid.NewGuid(), plantsArea.Id,
                    ServiceStateEnum.Nutrienting.ToString(), new TimeSpan(0, 0, 10), new TimeSpan(0, 1, 0),
                    new List<MeasurableParameter> {plantsArea.Plant.Nutrient, plantsArea.Plant.SoilPh}));

                plantsArea.ServicesSchedulesStates.AddServiceSchedule(new ServiceSchedule(Guid.NewGuid(), plantsArea.Id,
                    ServiceStateEnum.Watering.ToString(), new TimeSpan(0, 0, 10), new TimeSpan(0, 1, 0), 
                    new List<MeasurableParameter> { plantsArea.Plant.Humidity, plantsArea.Plant.Temperature }));
                
                return plantsArea;
            }
            catch (ApplicationException e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
            catch (FormatException e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
        
        }