private static void CallAlarm(Alarm alarm) { _clientSemaphore.Enqueue(); Debug.Log(_debugChannel, "Calling alarm " + alarm.Name); foreach(ServerInstance client in _clients.Keys) { IXPFile file = new IXPFile(); file.NetworkFunction = _clients[client]; file.PutInfo("alarm_id", "" + alarm.ID); file.PutInfo("name", "" + alarm.Name); client.Send(Encoding.UTF8.GetBytes(file.XML)); } _clientSemaphore.Dequeue(); }
private static void AlarmDbConnector_AlarmModified(Alarm alarm) { _alarmSemaphore.Enqueue(); Alarm tmp = null; if((tmp = _alarms.FirstOrDefault(a => a.ID == alarm.ID)) != null) { if (!alarm.Enabled) { _alarms.Remove(tmp); Debug.Log(_debugChannel, "Disabled alarm " + alarm.Name); } else { tmp.Name = alarm.Name; tmp.Hours = alarm.Hours; tmp.Minutes = alarm.Minutes; tmp.Seconds = alarm.Seconds; tmp.Mon = alarm.Mon; tmp.Tue = alarm.Tue; tmp.Wed = alarm.Wed; tmp.Thu = alarm.Thu; tmp.Fri = alarm.Fri; tmp.Sat = alarm.Sat; tmp.Sun = alarm.Sun; Debug.Log(_debugChannel, "Updated alarm " + alarm.Name); } } else { if (alarm.Enabled) { _alarms.Add(alarm); Debug.Log(_debugChannel, "Enabled alarm " + alarm.Name); } } _alarmSemaphore.Dequeue(); }
private static void AlarmDbConnector_AlarmAdded(Alarm alarm) { _alarmSemaphore.Enqueue(); if (alarm.Enabled) { _alarms.Add(alarm); Debug.Log(_debugChannel, "Added alarm " + alarm.Name); } _alarmSemaphore.Dequeue(); }
private static void AlarmDbConnector_AlarmDeleted(Alarm alarm) { _alarmSemaphore.Enqueue(); Alarm tmp = null; if ((tmp = _alarms.FirstOrDefault(a => a.ID == alarm.ID)) != null) { _alarms.Remove(tmp); Debug.Log(_debugChannel, "Removed alarm " + tmp.Name); } _alarmSemaphore.Dequeue(); }
public static Alarm GetAlarm(int alarm_id) { Alarm alarm = new Alarm(-1, "", -1, -1, -1, false, false, false, false, false, false, false, false); _semaphore.Enqueue(); _connection.Open(); try { MySqlCommand cmd = new MySqlCommand("SELECT ID, Name, Hours, Minutes, Seconds, Mon, Tue, Wed, Thu, Fri, Sat, Sun, Enabled FROM alarms WHERE ID=" + alarm_id + "", _connection); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32("ID"); string name = reader.GetString("Name"); int hours = reader.GetInt32("Hours"); int minutes = reader.GetInt32("Minutes"); int seconds = reader.GetInt32("Seconds"); bool mon = reader.GetInt16("Mon") == 1; bool tue = reader.GetInt16("Tue") == 1; bool wed = reader.GetInt16("Wed") == 1; bool thu = reader.GetInt16("Thu") == 1; bool fri = reader.GetInt16("Fri") == 1; bool sat = reader.GetInt16("Sat") == 1; bool sun = reader.GetInt16("Sun") == 1; bool enabled = reader.GetInt16("Enabled") == 1; alarm = new Alarm(id, name, hours, minutes, seconds, mon, tue, wed, thu, fri, sat, sun, enabled); } reader.Close(); reader.Dispose(); } catch(Exception e) { Debug.Log(_debugChannel, "Could not fetch alarm: " + e.Message); alarm = new Alarm(-1, "", -1, -1, -1, false, false, false, false, false, false, false, false); } _connection.Close(); _semaphore.Dequeue(); return alarm; }