Ejemplo n.º 1
0
        private void RequestUpdate()
        {
            TooltipData data = new TooltipData();
            StopData    eta  = null;

            try {
                eta = _backend.RequestDataForStopAndRouteNumber(ConfigSettings.Default.StopNumber,
                                                                ConfigSettings.Default.RouteNumber);
                data = CreateToolTip(eta);
            } catch (Exception e) {
                data.Icon    = ToolTipIcon.Error;
                data.Title   = "Error Loading";
                data.Content = e.Message;
            }

            _notify.BalloonTipIcon  = data.Icon;
            _notify.BalloonTipTitle = data.Title;
            _notify.BalloonTipText  = data.Content;

            if (eta != null && eta.Routes.Count > 0)
            {
                RouteData routeData = eta.Routes.First();
                if (routeData.Trips.Count > 0)
                {
                    TripData nextTrip = routeData.Trips.OrderBy(z => z.ETA).FirstOrDefault();
                    if (nextTrip != null)
                    {
                        if (ConfigSettings.Default.EnableAlerts &&
                            (DateTime.Now.TimeOfDay >= TimeSpan.FromSeconds(ConfigSettings.Default.AlertStart)) &&
                            (DateTime.Now.TimeOfDay <= TimeSpan.FromSeconds(ConfigSettings.Default.AlertEnd)) &&
                            nextTrip.ETA.TotalMinutes <= ConfigSettings.Default.AlertWhenETA &&
                            nextTrip.ETA != _lastETA)
                        {
                            _notify.ShowBalloonTip(10);
                            _lastETA = nextTrip.ETA;
                        }
                    }
                }
            }
        }