public Alarm Acknowledge(Alarm alarm) { alarm.Accepted = true; LastAlarm = _repo.UpdateAlarm(alarm); return LastAlarm; }
/// <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); } }
/// <summary> /// Creates a new Alarm object on the database. /// </summary> /// <param name="alarm"></param> public void CreateAlarm(Alarm alarm) { //Ensure the Alarm object is not null. if (alarm == null) return; _repo.CreateAlarm(alarm); }