private static TooltipData CreateToolTip(StopData arrivalData) { TooltipData tipData = new TooltipData { Icon = ToolTipIcon.Info }; if (arrivalData.Routes.Count == 0) { tipData.Title = "No Routes"; return tipData; } RouteData routeData = arrivalData.Routes.First(); tipData.Title = "Route: " + routeData.RouteId + " - " + routeData.DestinationName; StringBuilder tip = new StringBuilder(); if (routeData.Trips.Count == 0) { tip.AppendLine("No Trips"); return tipData; } foreach (TripData trip in routeData.Trips) { tip.AppendLine("ETA: " + trip.ETA.TotalMinutes + " m."); } tip.AppendLine("Updated at: " + DateTime.Now.ToString("HH:mm:ss")); tipData.Content = tip.ToString(); return tipData; }
private static TooltipData CreateToolTip(StopData arrivalData) { TooltipData tipData = new TooltipData { Icon = ToolTipIcon.Info }; if (arrivalData.Routes.Count == 0) { tipData.Title = "No Routes"; return(tipData); } RouteData routeData = arrivalData.Routes.First(); tipData.Title = "Route: " + routeData.RouteId + " - " + routeData.DestinationName; StringBuilder tip = new StringBuilder(); if (routeData.Trips.Count == 0) { tip.AppendLine("No Trips"); return(tipData); } foreach (TripData trip in routeData.Trips) { tip.AppendLine("ETA: " + trip.ETA.TotalMinutes + " m."); } tip.AppendLine("Updated at: " + DateTime.Now.ToString("HH:mm:ss")); tipData.Content = tip.ToString(); return(tipData); }
public StopData RequestDataForStopAndRouteNumber(string stopNumber, string routeNumber) { StopData data = new StopData(); XmlDocument doc = new XmlDocument(); string url = string.Format(_rttUrl, stopNumber, _random.NextDouble()); doc.Load(url); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("jp", "urn:connexionz-co-nz:jp"); XmlNode routeNode = doc.SelectSingleNode(string.Format("//jp:Route[@RouteNo={0}]", routeNumber), nsmgr); // if no routes, return now. if (routeNode == null) { return(data); } XmlNode destinationNode = routeNode.SelectSingleNode("//jp:Destination", nsmgr); RouteData routeData = new RouteData() { RouteId = routeNode.Attributes["RouteNo"].Value, DestinationName = destinationNode.Attributes["Name"].Value }; data.Routes.Add(routeData); XmlNodeList trips = destinationNode.SelectNodes("//jp:Trip", nsmgr); if (trips != null) { foreach (XmlNode trip in trips) { routeData.Trips.Add(new TripData() { TripId = trip.Attributes["TripNo"].Value, ETA = TimeSpan.FromMinutes(uint.Parse(trip.Attributes["ETA"].Value)) }); } } return(data); }
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; } } } } }
public StopData RequestDataForStopAndRouteNumber(string stopNumber, string routeNumber) { StopData data = new StopData(); XmlDocument doc = new XmlDocument(); string url = string.Format(_rttUrl, stopNumber, _random.NextDouble()); doc.Load(url); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("jp", "urn:connexionz-co-nz:jp"); XmlNode routeNode = doc.SelectSingleNode(string.Format("//jp:Route[@RouteNo={0}]", routeNumber), nsmgr); // if no routes, return now. if (routeNode == null) { return data; } XmlNode destinationNode = routeNode.SelectSingleNode("//jp:Destination", nsmgr); RouteData routeData = new RouteData() { RouteId = routeNode.Attributes["RouteNo"].Value, DestinationName = destinationNode.Attributes["Name"].Value }; data.Routes.Add(routeData); XmlNodeList trips = destinationNode.SelectNodes("//jp:Trip", nsmgr); if (trips != null) { foreach (XmlNode trip in trips) { routeData.Trips.Add(new TripData() { TripId = trip.Attributes["TripNo"].Value, ETA = TimeSpan.FromMinutes(uint.Parse(trip.Attributes["ETA"].Value)) }); } } return data; }