예제 #1
0
        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);
        }
예제 #2
0
 public void ReconnectConnectToServer()
 {
     if (TestConnection() == false)
     {
         ProcessConnectionServer = Activator.GetObject(typeof(IProcessConnectionServer), "tcp://" + IP + ":" + Port + "/" + ConnectionString) as IProcessConnectionServer;
         AlarmEvents.ClearAlarmEvents();
     }
 }
예제 #3
0
    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);
    }
예제 #4
0
        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();
        }
예제 #5
0
 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);
     }
 }
예제 #6
0
 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;
                 }
             }
         }
     }
 }
예제 #7
0
 void clock_alarm(object sender, AlarmEvents args)
 {
     Console.WriteLine($"alarm alarm");
 }
예제 #8
0
 void clock_tick(object sender, AlarmEvents args)
 {
     Console.WriteLine($"tick tick");
 }