public void GetStopsBySearch(string search, Action<IEnumerable<Model.Stop>> callback) { try { //var wc = new FastWebClient(); FastWebClient client = new FastWebClient(); client.DownloadStringCompleted += (s, e) => { string xml = e.Result; var stops = GetStops(xml); callback(stops); }; if (NetworkInterface.GetIsNetworkAvailable()) { client.DownloadStringAsync(new Uri("http://vasttrafik.se/External_Services/TravelPlanner.asmx/GetAllSuggestions?identifier=ID&searchString=" + search + "&count=20")); } else { callback(null); } } catch (Exception) { } }
public void GetNextTrips(string stop_id, Action<IEnumerable<Model.Trip>> callback) { FastWebClient client = new FastWebClient(); //WebClient nextTripClient = new WebClient(); client.DownloadStringCompleted += (s, e) => { XNamespace ns = "http://vasttrafik.se/"; string xmlStops = XElement.Parse(e.Result).Value; XElement realXml = XElement.Parse(xmlStops); var trips = from stop in realXml.Descendants("item") where stop.Element("destination") != null select new Model.Trip { Destination = stop.Element("destination").Value ?? "", NextTripMinutes = int.Parse(stop.Attribute("next_trip").Value), NextTripDateTime = DateTime.Parse(stop.Attribute("next_trip_planned_time").Value), LineForegroundColor = stop.Attribute("line_number_foreground_color").Value ?? "", LineBackgroundColor = stop.Attribute("line_number_background_color").Value ?? "", LineImage = stop.Attribute("line_image").Value ?? "", //NextTripImage = stop.Attribute("next_trip_image").Value ?? "", Line = stop.Attribute("line_number").Value ?? "" }; //if (TripLoadingComplete != null) { // TripLoadingComplete(this, new TripLoadingEventArgs(trips.OrderBy(x => x.NextTripMinutes))); // } callback(trips.OrderBy(x => x.NextTripMinutes)); }; if (NetworkInterface.GetIsNetworkAvailable()) { client.DownloadStringAsync(new Uri("http://vasttrafik.se/External_Services/NextTrip.asmx/GetForecast?identifier=ID&stopId=" + stop_id)); } else { callback(null); } }
public void GetStopsByLocation(double latitude, double longitude, Action<IEnumerable<Model.Stop>> callback) { WGS84Position coordinates = new WGS84Position(latitude, longitude); RT90Position rtPos = new RT90Position(coordinates, RT90Position.RT90Projection.rt90_2_5_gon_v); FastWebClient client = new FastWebClient(); client.DownloadStringCompleted += (s, e) => { string xml = e.Result; var stops = GetStops(xml); callback(stops); }; if (NetworkInterface.GetIsNetworkAvailable()) { client.DownloadStringAsync(new Uri("http://vasttrafik.se/External_Services/TravelPlanner.asmx/GetStopListBasedOnCoordinate?identifier=ID&xCoord=" + rtPos.Latitude + "&yCoord=" + rtPos.Longitude)); } else { callback(null); } }