private void alarm_cbPeriod_SelectedIndexChanged(object sender, EventArgs e) { var hours = Convert.ToInt32(alarm_cbPeriod.SelectedItem); var controller = new AlarmController(); var alarmList = controller.GetAllAlarms(hours); alarm_lbAlarms.Items.Clear(); if (alarmList != null && alarmList.Any()) { alarm_lbAlarms.Items.AddRange(alarmList.OrderByDescending(a => a.TimeStamp).ToArray()); } }
private void alarm_Acknowledge_Click(object sender, EventArgs e) { //Submit an acknowledgment request to the controller. var controller = new AlarmController(); controller.Acknowledge((Alarm)alarm_lbAlarms.SelectedItem); //Update the alarm object in the list. alarm_lbAlarms.SelectedItem = controller.LastAlarm; }
/// <summary> /// Method to update the header label with a count of active alarms from /// within the last 24 hours. /// </summary> private void UpdateActiveAlarms(object threadable) { var controller = new AlarmController(); while (true) { /* * Updates to the Alarm Count are handled within TRY/CATCH because there is potential * for external changes that may cut/slow the data flow/connection. */ try { //Only counts alarms that have been active for longer than 24 hours. var liveCount = controller.GetAllAlarms(24).Count(a => !a.Accepted); //_activeAlarmCount = controller.GetAllAlarms(24).Count(a => !a.Accepted); _activeAlarmCount = controller.GetActiveAlarmCount(); //Sleep for X seconds System.Threading.Thread.Sleep(1000); } catch (Exception e) { DebugOutput.Print("Alarm Updating Error - ", e.Message); } } }
/// <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); } }