// Removes, updates, and adds alarms private void RefreshAlarms(ICollection <Alarm> alarms) { // Show that several concurrent alarms exist AlarmGrid.Visibility = Visibility.Visible; NoAlarmPnl.Visibility = Visibility.Hidden; InfoCenterCtrl.Visibility = Visibility.Hidden; InfoCenterCtrl.Stop(); MultiAlarmGrid.Visibility = alarms.Count > 1 ? Visibility.Visible : Visibility.Collapsed; // Remove finished alarms, refresh existing alarms, show new alarms var removeIds = mAlarmId2Ctrl.Keys.Except(alarms.Select(a => a.Id)).ToList(); int numberOfRemovedAlarms = RemoveAlarms(removeIds); UpdateAlarms(alarms); var newAlarms = AddAlarms(alarms); // Ensure that an alarm is shown if (newAlarms.Count == 0 && numberOfRemovedAlarms > 0) { ShowNextAlarm(); } #region Turn screen on, bring window to front, play sound if (newAlarms.Count > 0) { // Turn on screen try { if (mPublicDisplayControl != null) { mPublicDisplayControl.TurnOn(); } else { // Stop turning off screen if (mTurnScreenOffTimer != null) { mTurnScreenOffTimer.Stop(); } ScreenPower.TurnOn(this); } } catch (Exception ex) { Log.GetInstance().LogError("Error in turning on screen.", ex); } // Bring the AIC window to front ShowAndActivate(); // Play a sound if (!Starting) { try { mSoundHelper.Alarm = newAlarms.Last(); if (AicSettings.Global.PlayAlarmSound && !AicSettings.Global.PlayAnnouncement) { mSoundHelper.PlayAlarmSound(); } else if (AicSettings.Global.PlayAnnouncement) { mSoundHelper.PlaySequence(AicSettings.Global.PlayAlarmSound, AicSettings.Global.AnnouncementIntervals); } } catch (Exception ex) { Log.GetInstance().LogError("Could not play sound.", ex); } } } #endregion }