private void ParseMuniRoute(NextbusRoute routeData) { if (routeData.Title.Contains("-")) Title = routeData.Title.Split(new char[] { '-' }, 2)[1]; if (new string[] { "59, 60, 61" }.Any(routeData.Tag.Contains)) { // Cable Car lines IconText = "CC"; Color = _routeColorDictionary["CC"]; } else if (routeData.Tag.Contains("_OWL")) { // OWL Lines Color = _routeColorDictionary["OWL"]; IconText = routeData.Tag.Replace("_", ""); Title = routeData.Title; } else { IconText = routeData.Tag; if (_routeColorDictionary.ContainsKey(IconText)) Color = _routeColorDictionary[IconText]; else if (IconText.EndsWith("X")) Color = _routeColorDictionary["X"]; else if (IconText.EndsWith("R")) Color = _routeColorDictionary["R"]; else Color = _routeColorDictionary["Local"]; } }
/// <summary> /// Gets a list of routes for a given agency /// </summary> /// <param name="agencyTag">Agency tag identifier, e.g. sf-muni</param> /// <returns>A list of <see cref="NextbusRoute"/></returns> public async Task<List<NextbusRoute>> RouteListAsync(string agencyTag) { List<NextbusRoute> response = new List<NextbusRoute>(); try { XmlDocument doc = await ExecuteNextbusCommandAsync("routeList", new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("a", agencyTag) }); var routes = doc.SelectNodes("body/route"); foreach (var routeNode in routes) { NextbusRoute route = new NextbusRoute(); route.Tag = GetAttributeValue("tag", routeNode.Attributes); route.Title = GetAttributeValue("title", routeNode.Attributes); response.Add(route); } } catch (Exception ex) { RaiseError(DataEngineType.Nextbus, ex.Message); throw ex; } return response; }
/// <summary> /// Gets detailed information about a route. /// </summary> /// <param name="agencyTag">Agency tag identifier, e.g. sf-muni</param> /// <param name="routeTag">Route tag identifier, e.g. N</param> /// <returns>Detailed route information including stops, their location and the path information.</returns> public async Task<NextbusRoute> RouteConfigAsync(string agencyTag, string routeTag) { try { XmlDocument doc = await ExecuteNextbusCommandAsync("routeConfig", new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("a", agencyTag), new KeyValuePair<string, string>("r", routeTag) }); var routeNodes = doc.SelectNodes("body/route"); NextbusRoute route = new NextbusRoute(); if (routeNodes.Count > 0) { var routeNode = routeNodes.First(); /// Parse base route info route.Tag = GetAttributeValue("tag", routeNode.Attributes); route.Title = GetAttributeValue("title", routeNode.Attributes); route.Color = GetAttributeValue("color", routeNode.Attributes); route.OppositeColor = GetAttributeValue("oppositeColor", routeNode.Attributes); route.MinimumCoordinates = new GeoCoordinate() { Latitude = Double.Parse(GetAttributeValue("latMin", routeNode.Attributes)), Longitude = Double.Parse(GetAttributeValue("lonMin", routeNode.Attributes)) }; route.MaximumCoordinates = new GeoCoordinate() { Latitude = Double.Parse(GetAttributeValue("latMax", routeNode.Attributes)), Longitude = Double.Parse(GetAttributeValue("lonMax", routeNode.Attributes)) }; /// Parse stops List<NextbusStop> detailedStops = new List<NextbusStop>(); var stopNodes = routeNode.SelectNodes("stop"); foreach (var stopNode in stopNodes) { detailedStops.Add(new NextbusStop() { Tag = GetAttributeValue("tag", stopNode.Attributes), Title = GetAttributeValue("tag", stopNode.Attributes), Coordinates = new GeoCoordinate() { Latitude = Double.Parse(GetAttributeValue("lat", stopNode.Attributes)), Longitude = Double.Parse(GetAttributeValue("lon", stopNode.Attributes)) }, StopId = Int32.Parse(GetAttributeValue("stopId", stopNode.Attributes)) }); } route.Stops = detailedStops; /// Parse directions List<NextbusDirection> directions = new List<NextbusDirection>(); var directionNodes = routeNode.SelectNodes("direction"); foreach (var directionNode in directionNodes) { NextbusDirection direction = new NextbusDirection() { Tag = GetAttributeValue("tag", directionNode.Attributes), Title = GetAttributeValue("title", directionNode.Attributes), Name = GetAttributeValue("name", directionNode.Attributes), UseForUI = Boolean.Parse(GetAttributeValue("useForUI", directionNode.Attributes)), Stops = new List<NextbusStop>() { } }; List<NextbusStop> inlineStops = new List<NextbusStop>(); foreach (var inlineStopNode in directionNode.SelectNodes("stop")) { inlineStops.Add(new NextbusStop() { Tag = GetAttributeValue("tag", inlineStopNode.Attributes) }); } direction.Stops = inlineStops; directions.Add(direction); } route.Directions = directions; /// Parse Paths List<List<GeoCoordinate>> paths = new List<List<GeoCoordinate>>(); foreach (var pathGroupNode in routeNode.SelectNodes("path")) { List<GeoCoordinate> path = new List<GeoCoordinate>(); foreach (var pointNode in pathGroupNode.SelectNodes("point")) { path.Add(new GeoCoordinate() { Latitude = Double.Parse(GetAttributeValue("lat", pointNode.Attributes)), Longitude = Double.Parse(GetAttributeValue("lon", pointNode.Attributes)) }); } paths.Add(path); } route.Paths = paths; } return route; } catch (Exception ex) { RaiseError(DataEngineType.Nextbus, ex.Message); throw ex; } }
public RouteItemViewModel(NextbusRoute routeData, string agencyId) : base(routeData?.Tag, routeData?.Title) { if (agencyId == AgencyItemViewModel.SFMuniId) ParseMuniRoute(routeData); }