public List <AlarmEvent> ViewEvents(int UserLevel = 0) { List <AlarmEvent> result = new List <AlarmEvent>(); foreach (var alarmEvent in AlarmEvents.FindAll(x => x.MinUserLevelToRemove < UserLevel)) { result.Add(new AlarmEvent { AlarmID = alarmEvent.AlarmID, EndTime = new DateTime(alarmEvent.EndTime.Year, alarmEvent.EndTime.Month, alarmEvent.EndTime.Day, alarmEvent.EndTime.Hour, alarmEvent.EndTime.Minute, alarmEvent.EndTime.Second), StartTime = new DateTime(alarmEvent.StartTime.Year, alarmEvent.StartTime.Month, alarmEvent.StartTime.Day, alarmEvent.StartTime.Hour, alarmEvent.StartTime.Minute, alarmEvent.StartTime.Second), MinUserLevelToRemove = alarmEvent.MinUserLevelToRemove }); if (alarmEvent.EndTime != DateTime.MaxValue) { AlarmEvents.Remove(alarmEvent); } } return(result); }
public void ReconnectConnectToServer() { if (TestConnection() == false) { ProcessConnectionServer = Activator.GetObject(typeof(IProcessConnectionServer), "tcp://" + IP + ":" + Port + "/" + ConnectionString) as IProcessConnectionServer; AlarmEvents.ClearAlarmEvents(); } }
public void Alarm(int time_now, int Alarm_Time) { Console.WriteLine($"现在的时间是{time_now}"); AlarmEvents args = new AlarmEvents() { time_now = time_now, alrmTime = Alarm_Time }; ALARM(this, args); }
public void ConnectToServer(string ip, string port, string connectionstring) { IP = ip; Port = port; ConnectionString = connectionstring; ProcessConnectionServer = Activator.GetObject(typeof(IProcessConnectionServer), "tcp://" + IP + ":" + Port + "/" + ConnectionString) as IProcessConnectionServer; AlarmConfig.LoadAlarmsConfigFile(); AlarmEvents.ClearAlarmEvents(); }
public void RemoveEvent(AlarmEvent alarmEvent, int levelSecurity = 0) { if (alarmEvent.MinUserLevelToRemove > levelSecurity) { throw new ArgumentException(string.Format("Don't have permission to remove alarm {0}", alarmEvent.AlarmID)); } else { AlarmEvents.Remove(alarmEvent); } }
public void ReceiveVariableValues(Dictionary <int, double> variableValue) { if (TimeProvider == null) { throw new InvalidOperationException("AlarmManager has no assigment TimeProvider"); } foreach (Alarm alarm in Alarms) { double newValue; if (variableValue.TryGetValue(alarm.VariableID, out newValue)) { AlarmEvent alarmExist = AlarmEvents.FindLast(x => x.AlarmID == alarm.AlarmID); if (alarm.Sensor.Check(newValue)) { if (alarmExist == null) { var newEvent = new AlarmEvent { AlarmID = alarm.AlarmID, StartTime = TimeProvider.Now, EndTime = DateTime.MaxValue, }; AlarmEvents.Add(newEvent); } else if (alarmExist.EndTime != DateTime.MaxValue) { var newEvent = new AlarmEvent { AlarmID = alarm.AlarmID, StartTime = TimeProvider.Now, EndTime = DateTime.MaxValue, }; AlarmEvents.Add(newEvent); } } else if (alarmExist != null) { if (alarmExist.EndTime == DateTime.MaxValue) { alarmExist.EndTime = TimeProvider.Now; } } } } }
void clock_alarm(object sender, AlarmEvents args) { Console.WriteLine($"alarm alarm"); }
void clock_tick(object sender, AlarmEvents args) { Console.WriteLine($"tick tick"); }