private bool RefreshRepository() { lock (this.cache) { var alarmList = this.repository.Load(); if (alarmList == null) { return(false); } var alarms = alarmList.ToDictionary(x => x.Id); var deletedAlarmKeys = this.cache.Keys.Where(x => !alarms.ContainsKey(x)).ToArray(); foreach (var key in deletedAlarmKeys) { if (this.OnAlarmRemoval != null) { this.OnAlarmRemoval.Invoke(this, new AlarmEventArgs(this.cache[key])); } this.cache.Remove(key); } foreach (var alarm in alarms.Values) { IAlarm cachedAlarm = null; if (this.cache.TryGetValue(alarm.Id, out cachedAlarm)) { if (!this.valueComparer.Equals(cachedAlarm, alarm)) { cachedAlarm.Import(alarm); if (this.OnAlarmUpdate != null) { this.OnAlarmUpdate.Invoke(this, new AlarmEventArgs(cachedAlarm)); } } } else { cachedAlarm = alarm; this.cache.Add(alarm.Id, cachedAlarm); if (this.OnAlarmAdd != null) { this.OnAlarmAdd.Invoke(this, new AlarmEventArgs(cachedAlarm)); } } this.CheckAlarmStatus(cachedAlarm); } return(true); } }