private void _disconnectionTimer_Tick(object sender, EventArgs e) { _disconnectionTimer.Enabled = false; _disconnectionNotificationShowed = true; if (true == _userCityConfigs.ShowConnectionNotifications) { NotificationWindowsManager.ShowNotification(TimeSpan.FromSeconds(-1), "אזהרה " + DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy"), "החיבור אבד. מתחבר למקור מידע...", NotificationType.Warning); } }
private void _alerts_Connected(object sender, EventArgs e) { if (InvokeRequired) { InvokeAsync(() => _alerts_Connected(sender, e)); return; } _alertUpdateTimer.Enabled = false; _disconnectionTimer.Enabled = false; if (!_alertActivated && _disconnectionNotificationShowed) { if (true == _userCityConfigs.ShowConnectionNotifications) { NotificationWindowsManager.ShowNotification(TimeSpan.FromSeconds(5), "מידע " + DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy"), "מחובר למקור מידע.", NotificationType.Info); } } _disconnectionNotificationShowed = false; _wasConnectedBefore = true; }
private void _alerts_ActiveAlertsChanged(object sender, AlertsEventArgs e) { if (InvokeRequired) { InvokeAsync(() => _alerts_ActiveAlertsChanged(sender, e)); return; } AreaConfiguration[] currentAreaConfigs = e.Alerts.Where(area => _areaConfigs.ContainsKey(area)) .Select(area => _areaConfigs[area]) .ToArray(); List <string> unknownAreas; if (true == _userCityConfigs.ShowAlertsFromUnknownAreas) { unknownAreas = e.Alerts.Where(area => !_areaConfigs.ContainsKey(area)).ToList(); } else { unknownAreas = _emptyList; } if (currentAreaConfigs.Any(areaConfig => areaConfig.SoundAlerts)) { if (!_playing) { _soundPlayer.PlayLooping(); _playing = true; } } else { if (_playing) { _soundPlayer.Stop(); _playing = false; } } if (currentAreaConfigs.Any(areaConfig => areaConfig.DisplayAlerts) || unknownAreas.Count > 0) // _userCityConfigs.ShowAlertsFromUnknownAreas checked before to create unknownAreas. { //string alertsText = string.Join("\r\n", // e.Alerts.Select(alert => new // { // Id = alert.Id, // Cities = alert.Cities.Where(city => _cityConfigs.ContainsKey(city) && _cityConfigs[city].DisplayAlerts) // .OrderByDescending(city => _cityConfigs[city].SoundAlerts).ToList() // }) // .Where(alert => alert.Cities.Any(city => _cityConfigs.ContainsKey(city) && _cityConfigs[city].DisplayAlerts)) // .OrderByDescending(alert => alert.Cities.Any(city => _cityConfigs[city].SoundAlerts)) // .Select(alert => alert.Id + "\r\n" + string.Join(", ", alert.Cities) + "\r\n")); string alertsText = string.Join("\r\n", e.Alerts.Select(area => new { Id = area, Cities = Cities.GetCitiesById(area) .Where(city => _cityConfigs.ContainsKey(city) && _cityConfigs[city].DisplayAlerts) .OrderByDescending(city => _cityConfigs[city].SoundAlerts).ToList() }) .Where(alert => alert.Cities.Any(city => _cityConfigs.ContainsKey(city) && _cityConfigs[city].DisplayAlerts)) .OrderByDescending(alert => alert.Cities.Any(city => _cityConfigs[city].SoundAlerts)) .Concat(unknownAreas.Select(area => new { Id = area, Cities = _emptyList })) .Select(alert => "*** " + alert.Id + " ***" + ((alert.Cities.Count > 0) ? (" : " + string.Join(", ", alert.Cities) + "\r\n") : ""))); if (!string.IsNullOrWhiteSpace(alertsText)) { _alertActivated = true; NotificationWindowsManager.ShowNotification(TimeSpan.FromSeconds(-1), "אזעקות פעילות " + e.DateTime.ToLocalTime().ToString("HH:mm:ss dd/MM/yyyy"), alertsText, NotificationType.Critical); _lastNoAlerts = false; } else { _alertActivated = false; if (!_lastNoAlerts) { NotificationWindowsManager.ShowNotification(TimeSpan.FromSeconds(5), "מידע " + e.DateTime.ToLocalTime().ToString("HH:mm:ss dd/MM/yyyy"), "אין אזעקות רלוונטיות כרגע", NotificationType.Info); } _lastNoAlerts = true; } } else { _alertActivated = false; if (!_lastNoAlerts) { NotificationWindowsManager.ShowNotification(TimeSpan.FromSeconds(5), "מידע " + e.DateTime.ToLocalTime().ToString("HH:mm:ss dd/MM/yyyy"), "אין אזעקות רלוונטיות כרגע", NotificationType.Info); } _lastNoAlerts = true; } }