protected ServiceSystem(string measurableType, double parameterValue, PlantsArea plantsArea, TimeSpan serviceTimeSpan) { PlantsArea = plantsArea; MeasurableType = measurableType; ParameterValue = parameterValue; ServiceTimeSpan = serviceTimeSpan; }
public MongoPlantsArea(PlantsArea area) { objId = area.Id.ToString(); userId = area.UserId.ToString(); name = $"{area.Plant.Name} area"; numberOfSensors = area.Sensors.Count; dateTime = DateTime.Now; }
public void AddPlantsArea(PlantsArea area) { if (Areas == null) { Areas = new List<PlantsArea>(); } Areas.Add(area); Areas = Areas //.OrderBy(p => p.Plant.Name) .ToList(); }
public bool RemovePlantsArea(PlantsArea area) { if (Areas != null) { if (Areas.All(s => s.Id != area.Id)) { return false; } return Areas.Remove(area); } return false; }
public bool SaveSensor(PlantsArea area, Sensor sensor, ServiceSchedule serviceSchedule) { try { MeasurableParameterMapping measurableParameterMapping = _dbMapper.GetMeasurableParameterMapping(sensor.MeasurableParameter); if (!(_sqlMeasurableParameterMappingRepository.Save(measurableParameterMapping, measurableParameterMapping.Id) && area.Plant.AddMeasurableParameter(sensor.MeasurableParameter))) { return false; } if (!area.AddSensor(sensor)) { return false; } SensorMapping sensorMapping = _dbMapper.GetSensorMapping(sensor); if (!(_sqlSensorMappingRepository.Save(sensorMapping, sensorMapping.Id) && _sensorsCollection.AddSensor(sensor))) { return false; } if (serviceSchedule != null) { if (!SaveServiceSchedule(area, serviceSchedule)) { return false; } } //if custom sensor if (sensor.IsCustom) { PlantMapping plantMapping = _dbMapper.GetPlantMapping(area.Plant); if (!_sqlPlantMappingRepository.Save(plantMapping, plantMapping.Id)) { return false; } } return true; } catch (Exception e) { MessageBox.Show(e.StackTrace); return false; } }
public bool SaveServiceSchedule(PlantsArea area, ServiceSchedule serviceSchedule) { try { ServiceScheduleMapping serviceScheduleMapping = _dbMapper.GetServiceScheduleMapping(serviceSchedule); if (serviceScheduleMapping != null) { if (_sqlServiceScheduleMappingRepository.Save(serviceScheduleMapping, serviceScheduleMapping.Id)) { return true; } } return false; } catch (Exception e) { MessageBox.Show(e.StackTrace); return false; } }
public bool RemoveSensor(PlantsArea area, Sensor sensor, ServiceSchedule serviceSchedule) { try { if (_sqlSensorMappingRepository.Delete(sensor.Id) && _sensorsCollection.RemoveSensor(sensor) && area.RemoveSensor(sensor)) { //if custom sensor ServiceState serviceState = area.PlantServicesStates.ServicesStates.FirstOrDefault( s => s.IsFor(sensor.MeasurableType)); if (serviceState != null) { if (area.PlantServicesStates.RemoveServiceState(serviceState)) { if (area.Plant.RemoveMeasurableParameter(sensor.MeasurableParameter)) { PlantMapping plantMapping = _dbMapper.GetPlantMapping(area.Plant); if (_sqlPlantMappingRepository.Save(plantMapping, plantMapping.Id)) { if (_sqlMeasurableParameterMappingRepository.Delete(sensor.MeasurableParameter.Id)) { if (serviceSchedule != null) { return _sqlServiceScheduleMappingRepository.Delete(serviceSchedule.Id); } serviceSchedule = area.ServicesSchedulesStates.ServicesSchedules.SingleOrDefault ( s => s.ServiceName == serviceState.ServiceName); if (serviceSchedule != null) { return _sqlServiceScheduleMappingRepository.Delete(serviceSchedule.Id); } } } } } } } return false; } catch (Exception e) { MessageBox.Show(e.StackTrace); return false; } }
public ServiceSystem GetServiceSystem(string measurableType, double parameterValue, PlantsArea plantsArea, TimeSpan servicingSpan) { ParameterEnum parameter; bool parsed = Enum.TryParse(measurableType, out parameter); if (parsed) { switch (parameter) { case ParameterEnum.Temperature: return new TemperatureSystem(ParameterEnum.Temperature.ToString(), parameterValue, plantsArea, servicingSpan); case ParameterEnum.Humidity: return new WaterSystem(ParameterEnum.Humidity.ToString(), parameterValue, plantsArea, servicingSpan); case ParameterEnum.Nutrient: return new NutrientSystem(ParameterEnum.Nutrient.ToString(), parameterValue, plantsArea, servicingSpan); case ParameterEnum.SoilPh: return new NutrientSystem(ParameterEnum.SoilPh.ToString(), parameterValue, plantsArea, servicingSpan); } } return new CustomSystem(measurableType, parameterValue, plantsArea, servicingSpan); }
public bool AddPlantsArea(PlantsArea plantsArea) { try { //IPlantMappingRepository plantMappingRepository = new PlantMappingRepository(); //IPlantsAreaMappingRepository plantsAreaMappingRepository = new PlantsAreaMappingRepository(); //IMeasurableParameterMappingRepository measurableParameterMappingRepository = // new MeasurableParameterMappingRepository(); //ISensorMappingRepository sensorMappingRepository = new SensorMappingRepository(); Temperature temperature = plantsArea.Plant.Temperature; MeasurableParameterMapping measurableParameterMapping = _dbMapper.GetMeasurableParameterMapping(temperature); if ( !_sqlMeasurableParameterMappingRepository.Save(measurableParameterMapping, measurableParameterMapping.Id)) { return false; } Humidity humidity = plantsArea.Plant.Humidity; measurableParameterMapping = _dbMapper.GetMeasurableParameterMapping(humidity); if ( !_sqlMeasurableParameterMappingRepository.Save(measurableParameterMapping, measurableParameterMapping.Id)) { return false; } SoilPh soilPh = plantsArea.Plant.SoilPh; measurableParameterMapping = _dbMapper.GetMeasurableParameterMapping(soilPh); if ( !_sqlMeasurableParameterMappingRepository.Save(measurableParameterMapping, measurableParameterMapping.Id)) { return false; } Nutrient nutrient = plantsArea.Plant.Nutrient; measurableParameterMapping = _dbMapper.GetMeasurableParameterMapping(nutrient); if ( !_sqlMeasurableParameterMappingRepository.Save(measurableParameterMapping, measurableParameterMapping.Id)) { return false; } Plant plant = plantsArea.Plant; PlantMapping plantMapping = _dbMapper.GetPlantMapping(plant); if (!_sqlPlantMappingRepository.Save(plantMapping, plantMapping.Id)) { return false; } PlantsAreaMapping plantsAreaMapping = _dbMapper.GetPlantsAreaMapping(plantsArea); if (!_sqlPlantsAreaMappingRepository.Save(plantsAreaMapping, plantsAreaMapping.Id)) { return false; } if ((from sensor in plantsArea.Sensors let sensorMapping = _dbMapper.GetSensorMapping(sensor) where !(_sqlSensorMappingRepository.Save(sensorMapping, sensorMapping.Id) && _sensorsCollection.AddSensor(sensor)) select sensor).Any()) { return false; } if (plantsArea.ServicesSchedulesStates.ServicesSchedules .Select(serviceSchedule => _dbMapper.GetServiceScheduleMapping(serviceSchedule)) .Any(serviceScheduleMapping => !_sqlServiceScheduleMappingRepository.Save(serviceScheduleMapping, serviceScheduleMapping.Id))) { return false; } _plantsAreas.AddPlantsArea(plantsArea); return true; } catch (Exception e) { MessageBox.Show(e.StackTrace); return false; } }
private bool RemovePlantsArea(PlantsArea plantsArea) { plantsArea.Sensors.ForEach(sensor => _mongoDbAccessor.DeleteMongoSensor(new MongoSensor(sensor))); _mongoDbAccessor.DeleteMongoPlantsArea(new MongoPlantsArea(plantsArea)); _mongoDbAccessor.AddMongoNotification(new MongoNotification(plantsArea.Id.ToString(), $"{plantsArea} removed", _user.Id.ToString())); if (_mySqlDbDataModifier.RemovePlantsArea(plantsArea)) { SetPlantsGrid(1); MessageBox.Show($"{plantsArea} area removed"); return true; } return false; }
public DataGrid CreateServiceSystemsDataGrid(PlantsArea area) { DataGrid dataGrid = new DataGrid { Margin = new Thickness(20, 10, 0, 0), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, CanUserAddRows = false, CanUserResizeColumns = false, AutoGenerateColumns = false, ColumnWidth = DataGridLength.Auto }; DataGridTextColumn columnServiceName = new DataGridTextColumn { Header = "Service", Binding = new Binding("ServiceName") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, IsReadOnly = true }; DataGridTextColumn columnIsOn = new DataGridTextColumn { Header = "On", Binding = new Binding("IsOn") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, CellStyle = new Style { TargetType = typeof (DataGridCell), Triggers = { new DataTrigger { Binding = new Binding("IsOn") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, Value = PlantingLib.Properties.Resources.IsScheduledSign, Setters = { new Setter(Control.BackgroundProperty, (SolidColorBrush)MainWindow.ResourceDictionary["ServiceBackground"]) } } } }, IsReadOnly = true }; DataGridTextColumn columnIsScheduled = new DataGridTextColumn { Header = "Scheduled", Binding = new Binding("IsScheduled") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, CellStyle = new Style { TargetType = typeof (DataGridCell), Triggers = { new DataTrigger { Binding = new Binding("IsScheduled") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, Value = PlantingLib.Properties.Resources.IsScheduledSign, Setters = { new Setter(Control.BackgroundProperty, (SolidColorBrush)MainWindow.ResourceDictionary["ScheduleBackground"]) } } } }, IsReadOnly = true }; dataGrid.Columns.Add(columnServiceName); dataGrid.Columns.Add(columnIsOn); dataGrid.Columns.Add(columnIsScheduled); dataGrid.ItemsSource = area.PlantServicesStates.ServicesStates; return dataGrid; }
private Border CreateFullPlantAreaPanel(PlantsArea area, int marginLeft, int marginTop) { DataGridsBuilder dataGridsBuilder = new DataGridsBuilder(); FrameworkElementFactoriesBuilder frameworkElementFactoriesBuilder = new FrameworkElementFactoriesBuilder(); StackPanel plantAreaSensorsPanel = new StackPanel { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Orientation = Orientation.Horizontal, Width = 1330, Height = 300, CanVerticallyScroll = true, CanHorizontallyScroll = true, }; plantAreaSensorsPanel.Children.Add(new Label { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Content = area.ToString() }); BindingList<DataGridSensorView> dataGridSensorViews = new BindingList<DataGridSensorView>( area.Sensors.OrderBy(s => s.IsCustom).ToList().ConvertAll(s => new DataGridSensorView(s))) { AllowNew = true, AllowEdit = true, AllowRemove = true }; BindingList<DataGridServiceScheduleView> dataGridServiceScheduleViews = new BindingList<DataGridServiceScheduleView>( area.ServicesSchedulesStates.ServicesSchedules.ToList() .ConvertAll(s => new DataGridServiceScheduleView(s))) { RaiseListChangedEvents = true, AllowNew = true, AllowRemove = true, AllowEdit = true }; FrameworkElementFactory removeSensorButtonTemplate = frameworkElementFactoriesBuilder.CreateRemoveSensorButtonTemplate(area, dataGridSensorViews, dataGridServiceScheduleViews, RemoveSensor); FrameworkElementFactory sensorSaveButtonTemplate = frameworkElementFactoriesBuilder.CreateSensorSaveButtonTemplate(area, dataGridSensorViews, dataGridServiceScheduleViews, SaveSensor); FrameworkElementFactory onOffSensorButtonTemplate = frameworkElementFactoriesBuilder.CreateOnOffSensorButtonTemplate(); DataGrid sensorViewsDataGrid = dataGridsBuilder.CreateSensorsDataGrid(area, dataGridSensorViews, removeSensorButtonTemplate, sensorSaveButtonTemplate, onOffSensorButtonTemplate); DataGrid serviceStatesDataGrid = dataGridsBuilder.CreateServiceSystemsDataGrid(area); FrameworkElementFactory serviceScheduleSaveButtonTemplate = frameworkElementFactoriesBuilder.CreateServiceScheduleSaveButtonTemplate(area, dataGridServiceScheduleViews, SaveServiceSchedule); FrameworkElementFactory onOffServiceScheduleButtonTemplate = frameworkElementFactoriesBuilder.CreateOnOffServiceScheduleButtonTemplate(); DataGrid serviceSchedulesDataGrid = dataGridsBuilder.CreateServicesSchedulesDataGrid(area, dataGridServiceScheduleViews, serviceScheduleSaveButtonTemplate, onOffServiceScheduleButtonTemplate); Button removePlantsAreaButton = frameworkElementFactoriesBuilder.CreateRemovePlantsAreaButton(RemovePlantsArea, area); plantAreaSensorsPanel.Children.Add(sensorViewsDataGrid); plantAreaSensorsPanel.Children.Add(serviceStatesDataGrid); plantAreaSensorsPanel.Children.Add(serviceSchedulesDataGrid); StackPanel plantAreaChartsPanel = new StackPanel { Orientation = Orientation.Vertical, Visibility = Visibility.Collapsed }; ChartDescriptor chartDescriptor = new ChartDescriptor(area.Id, area.Plant.MeasurableParameters.First().MeasurableType, 30, DateTime.Now.Subtract(new TimeSpan(0, 0, 30)), DateTime.Now); PlantAreaChartsPanelBuilder plantAreaChartsPanelBuilder = new PlantAreaChartsPanelBuilder(area.Plant.MeasurableParameters, frameworkElementFactoriesBuilder, plantAreaChartsPanel, chartDescriptor); plantAreaChartsPanelBuilder.RebuildChartsPanel(); Menu menu = new Menu(); DbMeasuringMessagesRetriever dbMeasuringMessagesRetriever = new DbMeasuringMessagesRetriever(new MySqlMeasuringMessageMappingRepository(), _observer.MessagesDictionary); PlantAreaMenuBuilder plantAreaMenuBuilder = new PlantAreaMenuBuilder(plantAreaSensorsPanel, plantAreaChartsPanel, menu, frameworkElementFactoriesBuilder, dbMeasuringMessagesRetriever, chartDescriptor); plantAreaMenuBuilder.RebuildMenu(); DockPanel plantAreaFullPanel = new DockPanel(); plantAreaFullPanel.Children.Add(menu); plantAreaFullPanel.Children.Add(removePlantsAreaButton); plantAreaFullPanel.Children.Add(plantAreaSensorsPanel); plantAreaFullPanel.Children.Add(plantAreaChartsPanel); ScrollViewer scrollViewer = new ScrollViewer { Height = plantAreaSensorsPanel.Height, CanContentScroll = true, Content = plantAreaFullPanel, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; Border border = new Border { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, BorderBrush = Brushes.Black, Background = (LinearGradientBrush)ResourceDictionary["PlantsAreaBackground"], BorderThickness = new Thickness(2), Width = plantAreaSensorsPanel.Width, Height = plantAreaSensorsPanel.Height, Margin = new Thickness(marginLeft, marginTop, 0, 0), Child = scrollViewer }; return border; }
public CustomSensor(Guid id, PlantsArea plantsArea, TimeSpan measuringTimeout, CustomParameter customParameter) : base(id, plantsArea, measuringTimeout, customParameter) { IsCustom = true; Function = new CustomParameterFunction(customParameter); }
public Button CreateRemovePlantsAreaButton(Func<PlantsArea, bool> removePlantsArea, PlantsArea area) { Button removePlantsAreaButton = new Button { Margin = new Thickness(0, -2, 0, 0), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = "X", Width = 21, Height = 21 }; removePlantsAreaButton.Click += (sender, args) => { MessageBoxResult result = System.Windows.MessageBox.Show("All plant's area data will be lost. Delete?", "Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { removePlantsArea(area); } }; return removePlantsAreaButton; }
public TemperatureSensor(Guid id, PlantsArea plantsArea, TimeSpan measuringTimeout, Temperature temperature) : base(id, plantsArea, measuringTimeout, temperature) { Function = new TemperatureFunction(temperature); }
public FrameworkElementFactory CreateServiceScheduleSaveButtonTemplate(PlantsArea area, BindingList<DataGridServiceScheduleView> dataGridServiceScheduleViews, Func<PlantsArea, ServiceSchedule, bool> saveServiceSchedule) { FrameworkElementFactory buttonTemplate = new FrameworkElementFactory(typeof (Button)); buttonTemplate.SetValue(ContentControl.ContentProperty, "Save"); buttonTemplate.AddHandler( ButtonBase.ClickEvent, new RoutedEventHandler((o, e) => { DataGridServiceScheduleView dataGridServiceScheduleView = ((FrameworkElement) o).DataContext as DataGridServiceScheduleView; if (dataGridServiceScheduleView != null) { ServiceSchedule serviceSchedule = area.ServicesSchedulesStates.ServicesSchedules.FirstOrDefault( s => s.ServiceName.ToString() == dataGridServiceScheduleView.ServiceName); TimeSpan servicingSpan; TimeSpan servicingPauseSpan; try { servicingSpan = TimeSpan.Parse(dataGridServiceScheduleView.ServicingSpan); servicingPauseSpan = TimeSpan.Parse(dataGridServiceScheduleView.ServicingPauseSpan); } catch (Exception) { MessageBox.Show($"'{dataGridServiceScheduleView.ServiceName}': wrong schedule data"); return; } if (serviceSchedule != null) { serviceSchedule.ServicingSpan = servicingSpan; serviceSchedule.ServicingPauseSpan = servicingPauseSpan; } else { MeasurableParameter measurableParameter = area.Plant.MeasurableParameters.SingleOrDefault( p => p.MeasurableType == dataGridServiceScheduleView.Parameters); serviceSchedule = new ServiceSchedule(Guid.NewGuid(), area.Id, dataGridServiceScheduleView.ServiceName, servicingSpan, servicingPauseSpan, new List<MeasurableParameter> {measurableParameter}); } saveServiceSchedule(area, serviceSchedule); MessageBox.Show($"'{dataGridServiceScheduleView.ServiceName}': schedule data saved"); dataGridServiceScheduleView.IsModified = false.ToString(); } }) ); return buttonTemplate; }
public FrameworkElementFactory CreateSensorSaveButtonTemplate(PlantsArea area, BindingList<DataGridSensorView> dataGridSensorViews, BindingList<DataGridServiceScheduleView> dataGridServiceScheduleViews, Func<PlantsArea, Sensor, ServiceSchedule, bool> saveSensor) { FrameworkElementFactory buttonTemplate = new FrameworkElementFactory(typeof (Button)); buttonTemplate.SetValue(ContentControl.ContentProperty, "Save"); buttonTemplate.AddHandler( ButtonBase.ClickEvent, new RoutedEventHandler((o, e) => { DataGridSensorView dataGridSensorView = ((FrameworkElement) o).DataContext as DataGridSensorView; if (dataGridSensorView != null) { try { ServiceState serviceState; ServiceSchedule serviceSchedule; if (dataGridSensorView.Sensor != null) { if (!dataGridSensorView.Sensor.MeasurableParameter.HasValidParameters()) { throw new Exception(); } if (dataGridSensorView.MeasurableIsModified) { string oldMeasurable = dataGridSensorView.Sensor.MeasurableType; dataGridSensorView.Sensor.MeasurableParameter.MeasurableType = dataGridSensorView.Measurable; serviceState = dataGridSensorView.Sensor.PlantsArea .PlantServicesStates.GetServiceState(state => state.IsFor(oldMeasurable)); if (serviceState != null) { serviceSchedule = dataGridSensorView.Sensor.PlantsArea .ServicesSchedulesStates.GetServiceSchedule( schedule => schedule.IsFor(serviceState.ServiceName)); serviceState.ServiceName = dataGridSensorView.Measurable; if (serviceSchedule != null) { serviceSchedule.ServiceName = serviceState.ServiceName; } saveSensor(area, dataGridSensorView.Sensor, serviceSchedule); dataGridSensorView.MeasurableIsModified = false; dataGridSensorView.IsModified = false.ToString(); MessageBox.Show( $"Sensor with measurable '{dataGridSensorView.Measurable}' updated"); OnRefreshControls(); return; } } saveSensor(area, dataGridSensorView.Sensor, null); dataGridSensorView.IsModified = false.ToString(); MessageBox.Show($"'{dataGridSensorView.Measurable}': sensor data saved"); return; } if (dataGridSensorViews.Count(s => s.Measurable == dataGridSensorView.Measurable) != 1) { MessageBox.Show( $"Sensor with measurable '{dataGridSensorView.Measurable}' already exists"); return; } CustomParameter customParameter = new CustomParameter(Guid.NewGuid(), Convert.ToInt32(dataGridSensorView.Optimal), Convert.ToInt32(dataGridSensorView.Min), Convert.ToInt32(dataGridSensorView.Max), dataGridSensorView.Measurable); CustomSensor sensor = new CustomSensor(Guid.NewGuid(), area, TimeSpan.Parse(dataGridSensorView.Timeout), customParameter); dataGridSensorView.Sensor = sensor; serviceState = new ServiceState(sensor.MeasurableType, true); area.PlantServicesStates.AddServiceState(serviceState); serviceSchedule = new ServiceSchedule(Guid.NewGuid(), area.Id, serviceState.ServiceName, new TimeSpan(0, 0, 10), new TimeSpan(0, 1, 0), new List<MeasurableParameter> {sensor.MeasurableParameter}); area.ServicesSchedulesStates.AddServiceSchedule(serviceSchedule); dataGridServiceScheduleViews.Add(new DataGridServiceScheduleView(serviceSchedule)); saveSensor(area, sensor, serviceSchedule); dataGridSensorView.IsModified = false.ToString(); MessageBox.Show($"'{dataGridSensorView.Measurable}': sensor data saved"); OnRefreshControls(); } catch (Exception) { MessageBox.Show($"'{dataGridSensorView.Measurable}': wrong sensor data"); } } }) ); return buttonTemplate; }
public FrameworkElementFactory CreateRemoveSensorButtonTemplate(PlantsArea area, BindingList<DataGridSensorView> dataGridSensorViews, BindingList<DataGridServiceScheduleView> dataGridServiceScheduleViews, Func<PlantsArea, Sensor, ServiceSchedule, bool> removeSensor) { FrameworkElementFactory buttonTemplate = new FrameworkElementFactory(typeof (Button)); buttonTemplate.SetValue(ContentControl.ContentProperty, "X"); buttonTemplate.AddHandler( ButtonBase.ClickEvent, new RoutedEventHandler((o, e) => { DataGridSensorView dataGridSensorView = ((FrameworkElement) o).DataContext as DataGridSensorView; if (dataGridSensorView != null) { if (dataGridSensorViews.Count(s => s.Measurable == dataGridSensorView.Measurable) == 0) { MessageBox.Show( $"'{dataGridSensorView.Measurable}': sensor with such measurable does not exist"); return; } ServiceState serviceState = area.PlantServicesStates.ServicesStates.SingleOrDefault( state => state.IsFor(dataGridSensorView.Measurable)); if (serviceState != null) { DataGridServiceScheduleView dataGridServiceScheduleView = dataGridServiceScheduleViews.SingleOrDefault( s => s.ServiceName == serviceState.ServiceName); ServiceSchedule serviceSchedule = area.ServicesSchedulesStates.ServicesSchedules.SingleOrDefault( schedule => schedule.ServiceName == serviceState.ServiceName); removeSensor(area, dataGridSensorView.Sensor, serviceSchedule); dataGridSensorViews.Remove(dataGridSensorView); dataGridServiceScheduleViews.Remove(dataGridServiceScheduleView); } } OnRefreshControls(); }) ); return buttonTemplate; }
public bool RemovePlantsArea(PlantsArea plantsArea) { try { if (_sqlPlantsAreaMappingRepository.Delete(plantsArea.Id) && _sqlPlantMappingRepository.Delete(plantsArea.Plant.Id)) { if (plantsArea.ServicesSchedulesStates.ServicesSchedules .Any(servicesSchedule => !_sqlServiceScheduleMappingRepository .Delete(servicesSchedule.Id))) { return false; } plantsArea.ServicesSchedulesStates.ServicesSchedules.Clear(); if (plantsArea.Sensors.Any(sensor => //del. by cascade //!(sqlSensorMappingRepository // .Delete(sensor.Id) !_sqlMeasurableParameterMappingRepository .Delete(sensor.MeasurableParameter.Id))) { return false; } plantsArea.Sensors.ToList().ForEach(s => _sensorsCollection.RemoveSensor(s)); plantsArea.Sensors.Clear(); return _plantsAreas.RemovePlantsArea(plantsArea); } return false; } catch (Exception e) { MessageBox.Show(e.StackTrace); return false; } }
private bool SaveSensor(PlantsArea area, Sensor sensor, ServiceSchedule serviceSchedule) { if (_mySqlDbDataModifier.SaveSensor(area, sensor, serviceSchedule)) { _mongoDbAccessor.SaveMongoSensor(new MongoSensor(sensor)); _mongoDbAccessor.SaveMongoPlantsArea(new MongoPlantsArea(sensor.PlantsArea)); _mongoDbAccessor.AddMongoNotification(new MongoNotification(sensor.PlantsAreaId.ToString(), $"{sensor.MeasurableType} sensor added/updated", _user.Id.ToString())); return true; } return false; }
public NutrientSensor(Guid id, PlantsArea plantsArea, TimeSpan measuringTimeout, Nutrient nutrient) : base(id, plantsArea, measuringTimeout, nutrient) { Function = new NutrientFunction(nutrient); }
public DataGrid CreateServicesSchedulesDataGrid(PlantsArea area, BindingList<DataGridServiceScheduleView> serviceScheduleViews, FrameworkElementFactory serviceScheduleSaveButtonTemplate, FrameworkElementFactory onOffSensorButtonTemplate) { DataGrid dataGrid = new DataGrid { Margin = new Thickness(20, 10, 0, 0), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, CanUserAddRows = false, CanUserDeleteRows = false, CanUserResizeColumns = false, AutoGenerateColumns = false, ColumnWidth = DataGridLength.Auto }; DataGridTextColumn serviceName = new DataGridTextColumn { Header = "Service", Binding = new Binding("ServiceName") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, IsReadOnly = true }; DataGridTextColumn parameters = new DataGridTextColumn { Header = "Parameters", Binding = new Binding("Parameters") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, IsReadOnly = true }; DataGridTextColumn servicingSpan = new DataGridTextColumn { Header = "Duration", Binding = new Binding("ServicingSpan") { UpdateSourceTrigger = UpdateSourceTrigger.LostFocus, Mode = BindingMode.TwoWay, NotifyOnValidationError = true, ValidatesOnExceptions = true, } }; DataGridTextColumn servicingPauseSpan = new DataGridTextColumn { Header = "Pause", Binding = new Binding("ServicingPauseSpan") { UpdateSourceTrigger = UpdateSourceTrigger.LostFocus, Mode = BindingMode.TwoWay, NotifyOnValidationError = true, ValidatesOnExceptions = true, } }; DataGridTemplateColumn save = new DataGridTemplateColumn { Header = "Save", CellTemplate = new DataTemplate { VisualTree = serviceScheduleSaveButtonTemplate }, CellStyle = new Style(typeof(Button)) { TargetType = typeof(DataGridCell), Triggers = { new DataTrigger { Binding = new Binding("IsModified") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, Value = false.ToString(), Setters = { new Setter(UIElement.IsEnabledProperty, false) } }, new DataTrigger { Binding = new Binding("IsModified") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, Value = true.ToString(), Setters = { new Setter(UIElement.IsEnabledProperty, true) } } } } }; DataGridTemplateColumn onOff = new DataGridTemplateColumn { Header = "On", CellTemplate = new DataTemplate { VisualTree = onOffSensorButtonTemplate } }; dataGrid.Columns.Clear(); dataGrid.Columns.Add(serviceName); dataGrid.Columns.Add(parameters); dataGrid.Columns.Add(servicingSpan); dataGrid.Columns.Add(servicingPauseSpan); dataGrid.Columns.Add(save); dataGrid.Columns.Add(onOff); dataGrid.RowStyle = new Style { TargetType = typeof (DataGridRow), Triggers = { new DataTrigger { Binding = new Binding("IsOn") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, Value = false.ToString(), Setters = { new Setter(Control.BackgroundProperty, (SolidColorBrush)MainWindow.ResourceDictionary["SensorOrScheduleIsOff"]), } }, new DataTrigger { Binding = new Binding("IsOn") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }, Value = true.ToString(), Setters = { new Setter(Control.BackgroundProperty, (SolidColorBrush)MainWindow.ResourceDictionary["Main"]), } } } }; dataGrid.ItemsSource = serviceScheduleViews; return dataGrid; }
public WaterSystem(string measurableType, double parameterValue, PlantsArea plantsArea, TimeSpan serviceTimeSpan) : base(measurableType, parameterValue, plantsArea, serviceTimeSpan) { }
public PlantsArea RestorePlantArea(PlantsAreaMapping plantsAreaMapping) { try { PlantMapping plantMapping = _sqlPlantMappingRepository.Get(plantsAreaMapping.PlantId); Plant plant = RestorePlant(plantMapping); PlantsArea area = new PlantsArea(plantsAreaMapping.Id, plantsAreaMapping.UserId, plant, plantsAreaMapping.Number); List<ServiceScheduleMapping> serviceScheduleMappings = _sqlServiceScheduleMappingRepository.GetAll(s => s.PlantsAreaId == area.Id); if (serviceScheduleMappings.Count != 0) { serviceScheduleMappings.ToList() .ForEach(s => area.ServicesSchedulesStates.AddServiceSchedule(RestoreServiceSchedule(s, area.Plant.MeasurableParameters))); } return area; } catch (Exception e) { MessageBox.Show(e.StackTrace, $"PlantsArea Id: {plantsAreaMapping.Id}"); return null; } }
private bool SaveServiceSchedule(PlantsArea area, ServiceSchedule serviceSchedule) { return _mySqlDbDataModifier.SaveServiceSchedule(area, serviceSchedule); }
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; }
private bool RemoveSensor(PlantsArea area, Sensor sensor, ServiceSchedule serviceSchedule) { _mongoDbAccessor.DeleteMongoSensor(new MongoSensor(sensor)); _mongoDbAccessor.AddMongoNotification(new MongoNotification(sensor.PlantsAreaId.ToString(), $"{sensor.MeasurableType} sensor removed", _user.Id.ToString())); if (_mySqlDbDataModifier.RemoveSensor(area, sensor, serviceSchedule)) { MessageBox.Show($"'{sensor.MeasurableType}': sensor removed"); _mongoDbAccessor.SaveMongoPlantsArea(new MongoPlantsArea(area)); return true; } return false; }
public PlantsAreaMapping GetPlantsAreaMapping(PlantsArea plantsArea) { return new PlantsAreaMapping(plantsArea.Id, plantsArea.Plant.Id, plantsArea.Number, plantsArea.UserId); }
public PlantsAreaEventArgs(PlantsArea plantsArea) { PlantsArea = plantsArea; }
public HumiditySensor(Guid id, PlantsArea plantsArea, TimeSpan measuringTimeout, Humidity humidity) : base(id, plantsArea, measuringTimeout, humidity) { Function = new HumidityFunction(humidity); }