public void ScheduleForStop(GeoCoordinate location, Stop stop, ScheduleForStop_Callback callback) { string requestUrl = string.Format( "{0}/{1}/{2}.xml?key={3}&Version={4}", WebServiceUrlForLocation(location), "schedule-for-stop", stop.id, KEY, APIVERSION ); HttpWebRequest requestGetter = (HttpWebRequest)HttpWebRequest.Create(requestUrl); requestGetter.BeginGetResponse(delegate(IAsyncResult asyncResult) { XDocument xmlResponse = null; List <RouteSchedule> schedules = new List <RouteSchedule>(); try { xmlResponse = ValidateWebCallback(asyncResult); IDictionary <string, Route> routesMap = ParseAllRoutes(xmlResponse); schedules.AddRange(from schedule in xmlResponse.Descendants("stopRouteSchedule") select new RouteSchedule { route = routesMap[SafeGetValue(schedule.Element("routeId"))], directions = (from direction in schedule.Descendants("stopRouteDirectionSchedule") select new DirectionSchedule { tripHeadsign = SafeGetValue(direction.Element("tripHeadsign")), trips = (from trip in direction.Descendants("scheduleStopTime") select ParseScheduleStopTime(trip)).ToList <ScheduleStopTime>() }).ToList <DirectionSchedule>() }); } catch (WebserviceResponseException) { } catch (Exception ex) { Exception error = new WebserviceParsingException(requestUrl, xmlResponse.ToString(), ex); throw error; } callback(schedules); }, requestGetter); }
public void ScheduleForStop(GeoCoordinate location, Stop stop, ScheduleForStop_Callback callback) { string requestUrl = string.Format( "{0}/{1}/{2}.xml?key={3}&Version={4}", WebServiceUrlForLocation(location), "schedule-for-stop", stop.id, KEY, APIVERSION ); HttpWebRequest requestGetter = (HttpWebRequest)HttpWebRequest.Create(requestUrl); requestGetter.BeginGetResponse( new AsyncCallback(new GetScheduleForStopCompleted(requestUrl, callback).HttpWebRequest_Completed), requestGetter); }
public GetScheduleForStopCompleted(string requestUrl, ScheduleForStop_Callback callback) : base(requestUrl) { this.callback = callback; }