public void StopsForRoute(GeoCoordinate location, Route route, StopsForRoute_Callback callback) { string requestUrl = string.Format( "{0}/{1}/{2}.xml?key={3}&Version={4}", WebServiceUrlForLocation(location), "stops-for-route", route.id, KEY, APIVERSION ); directionCache.DownloadStringAsync(new Uri(requestUrl), new GetDirectionsForRouteCompleted(requestUrl, route.id, directionCache, callback).HttpCache_Completed); }
public GetDirectionsForRouteCompleted(string requestUrl, string routeId, HttpCache directionCache, StopsForRoute_Callback callback) : base(requestUrl) { this.callback = callback; this.routeId = routeId; this.directionCache = directionCache; }
public void StopsForRoute(GeoCoordinate location, Route route, StopsForRoute_Callback callback) { string requestUrl = string.Format( "{0}/{1}/{2}.xml?key={3}&Version={4}", WebServiceUrlForLocation(location), "stops-for-route", route.id, KEY, APIVERSION ); HttpWebRequest requestGetter = (HttpWebRequest)HttpWebRequest.Create(requestUrl); requestGetter.BeginGetResponse(delegate(IAsyncResult asyncResult) { XDocument xmlResponse = null; List <RouteStops> routeStops = new List <RouteStops>(); try { xmlResponse = ValidateWebCallback(asyncResult); IDictionary <string, Route> routesMap = ParseAllRoutes(xmlResponse); // parse all the stops, using previously parsed Route objects IList <Stop> stops = (from stop in xmlResponse.Descendants("stop") select ParseStop(stop, (from routeId in stop.Element("routeIds").Descendants("string") select routesMap[SafeGetValue(routeId)] ).ToList <Route>() )).ToList <Stop>(); IDictionary <string, Stop> stopsMap = new Dictionary <string, Stop>(); foreach (Stop s in stops) { stopsMap.Add(s.id, s); } // and put it all together routeStops.AddRange(from stopGroup in xmlResponse.Descendants("stopGroup") where SafeGetValue(stopGroup.Element("name").Element("type")) == "destination" select new RouteStops { name = SafeGetValue(stopGroup.Descendants("names").First().Element("string")), encodedPolylines = (from poly in stopGroup.Descendants("encodedPolyline") select new PolyLine { pointsString = SafeGetValue(poly.Element("points")), length = SafeGetValue(poly.Element("length")) }).ToList <PolyLine>(), stops = (from stopId in stopGroup.Descendants("stopIds").First().Descendants("string") select stopsMap[SafeGetValue(stopId)]).ToList <Stop>(), route = routesMap[route.id] }); } catch (WebserviceResponseException) { } catch (Exception ex) { Exception error = new WebserviceParsingException(requestUrl, xmlResponse.ToString(), ex); throw error; } callback(routeStops); }, requestGetter); }