Exemplo n.º 1
0
        private void poller_ActiveAlertsChanged(object sender, AlertsEventArgs e)
        {
            lock (_alertsMultipleLocker)
            {
                _alertsMultiple[sender as IAlertsSourcePoller] = e.Alerts;

                UpdateActiveAlerts();
            }
        }
Exemplo n.º 2
0
        private void WriteAlerts(AlertsEventArgs alertsEventArgs, bool isStarted)
        {
            foreach (string area in alertsEventArgs.Alerts.Where(area2 => !string.IsNullOrEmpty(area2)))
            {
                _writer.Write(area);
            }

            _writer.Write(string.Empty);

            _writer.Write(isStarted);
            _writer.Write(alertsEventArgs.DateTime.ToBinary());
        }
Exemplo n.º 3
0
 public void WriteAlertsStarted(AlertsEventArgs alertsEventArgs)
 {
     WriteAlerts(alertsEventArgs, true);
 }
Exemplo n.º 4
0
 public void WriteAlertsEnded(AlertsEventArgs alertsEventArgs)
 {
     WriteAlerts(alertsEventArgs, false);
 }
Exemplo n.º 5
0
        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;
            }
        }