private void bSave_Click(object sender, EventArgs e) { if (_comm != null && _rule != null && tOutput.Text != "") { if (_action==null) _action = new Models.Action(); _action.CommunicatorId = _comm.Id; _action.Enabled = cEnabled.Checked; _action.OutputValue = tOutput.Text; _action.Communicator = _comm; _action.Rule = _rule; _action.RuleId = _rule.Id; //_action.Id var controller = new ActionController(); _action = controller.CreateAction(_action); if (_action.Id > 0) System.Windows.Forms.MessageBox.Show("Success!"); } }
private void bSaveAction_Click(object sender, EventArgs e) { var ruleSelected = _rule != null; var destinationSelected = add_cbCommunicatorDestination.SelectedItem != null; var outputEntered = add_tOutputValue.Text != ""; if (!(ruleSelected && destinationSelected && outputEntered)) { DebugOutput.Print("Unable to save - not all data has been entered!"); return; } _communicator = (Models.Communicator)add_cbCommunicatorDestination.SelectedItem; var newAction = new Models.Action() { Rule = _rule, RuleId = _rule.Id, Communicator =_communicator, CommunicatorId = _communicator.Id, OutputValue = add_tOutputValue.Text, Enabled = add_cActionEnabled.Checked }; var controller = new ActionController(); var action = controller.CreateAction(newAction); if (action != null) { DebugOutput.Print("Successfully created a new Action."); this.Close(); } }
private void modrules_bSetAction_Click(object sender, EventArgs e) { //Save the Rule as it stands. modrules_tSave.PerformClick(); var controller = new ActionController(); if (controller.RetrieveActionsForRule(_rule.Id).Any()) { //Get the actual Action. var action = controller.RetrieveActionsForRule(_rule.Id).FirstOrDefault(); _action = action; //Load the values required. modact_cEnabled.Checked = action.Enabled; modact_tValue.Text = action.OutputValue; modact_tRule.Text = _rule.ToString(); //Download the required communicator var commController = new CommunicatorController(); var comm = commController.GetAllCommunicators().FirstOrDefault(c => c.Id == action.CommunicatorId); if (comm != null) { _communicator = comm; _action.Communicator = comm; modact_tComm.Text = comm.ToString(); } else { modact_tComm.Text = ""; } //Actions exist. pTabPanel.SelectedTab = pModifyActions; } else { var db = new DataBoard(_communicator,_selectedDevice); db.GoToActionPage(_rule); db.ShowDialog(); _action = db.GetAction(); DebugOutput.Print("Changes made in the Data Manager are saved."); } }
private void UpdateStartLabels() { var comm_controller = new CommunicatorController(); var rule_controller = new RuleController(); var acti_controller = new ActionController(); try { //Update labels. add_lSource.Text = $"{comm_controller.CountCommunicatorsForDevice(_communicator.Device.Id)} Sources..."; add_lRules.Text = $"{rule_controller.RetrieveRulesForDevice(_selectedDevice.Id).Count()} Rules..."; } catch { //Update labels. add_lSource.Text = $"0 Sources..."; add_lRules.Text = $"0 Rules..."; } }
private void modact_bSave_Click(object sender, EventArgs e) { _action.Rule = _rule; _action.RuleId = _rule.Id; _action.Communicator = _communicator; _action.CommunicatorId = _communicator.Id; _action.OutputValue = modact_tValue.Text; _action.Enabled = modact_cEnabled.Checked; var controller = new ActionController(); var updated = controller.UpdateAction(_action); if (updated == null) { DebugOutput.Print("Update of the Action failed!"); } else { _action = updated; DebugOutput.Print("Action was updated successfully."); } }
/// <summary> /// When a Rule's critera have been met, this method is called to execute any /// and all Actions as per the Rule's settings. /// An Alarm is also raised from here. /// </summary> /// <param name="rule">The passed rule.</param> /// <param name="value">The value that passed the rule.</param> private void TakeAction(Rule rule, Value value) { //Handle any requirement to Alarm. if (rule.Alarm) { //Create accessor to the AlarmController class. var controller = new AlarmController(); //Create a new Alarm object as per the model. var alarm = new Alarm() { //Id = Guid.NewGuid(), Rule = rule, RuleId = rule.Id, Device = rule.Device, DeviceId = rule.DeviceId, Value = value, ValueId = value.Id, TimeStamp = value.EventTime, Accepted = false }; //Pass the alarm object to the AlarmController. controller.CreateAlarm(alarm); } var actionController = new ActionController(); var act = actionController.RetrieveActionsForRule(rule.Id).FirstOrDefault(); //Handle any Actions to be taken. if (act != null) { rule.Action = act; WriteData(rule,value); } }