public List<City> ProcessCity() { String[] cityParts = { "69381", "69382", "69383", "69384", "69385", "69386", "69387", "69388", "69389", "69266", "69034", "69256" }; City city = new City(); city.Name = "Lyon"; city.Stations = new List<Station>(); foreach (var cityPart in cityParts) { String jsonCity = new WebClient().DownloadString("http://www.velov.grandlyon.com/velovmap/zhp/inc/StationsParArrondissement.php?arrondissement="+cityPart); JavaScriptSerializer ser = new JavaScriptSerializer(); var cityObj = ser.DeserializeObject(jsonCity); var members = (Dictionary<String, Object>)cityObj; var membersCollection = (Object[])members["markers"]; foreach (Dictionary<String, Object> marker in membersCollection) { try { Station station = new Station(); station.Id = Convert.ToInt32(marker["numStation"]); //the update part can be commented out var url = "http://www.velov.grandlyon.com/velovmap/zhp/inc/DispoStationsParId.php?id=" + station.Id + "&noCache=true"; XDocument stationDoc = XDocument.Load(url); var updateStation = (from c in stationDoc.Descendants("station") select new Station { Free = (int)c.Element("available"), Total = (int)c.Element("total"), Ticket = (int)c.Element("ticket") }).First(); station.Lat = Convert.ToDouble(marker["x"], CultureInfo.InvariantCulture.NumberFormat); station.Lng = Convert.ToDouble(marker["y"], CultureInfo.InvariantCulture.NumberFormat); station.Address = (String)marker["nomStation"]; station.Free = updateStation.Free; station.Total = updateStation.Total; city.Stations.Add(station); } catch (Exception ex) { _log.Info("Error inside the Lyon handler, continouing the execution for the rest of the stations", ex); } } } var cities = new List<City>(); cities.Add(city); return cities; }
public List<City> ProcessCity() { //iformatprovide for the convert method IFormatProvider provider = CultureInfo.InvariantCulture.NumberFormat; var stations = new List<Station>(); WebClient client = new WebClient(); var xmlString = client.DownloadString("http://denver.bcycle.com/"); string regexString = @"var point = new google.maps.LatLng\((?<lat>.*), (?<lng>.*)\);" + @".*\n.*kioskpoints.push\(point\);" + ".*\n.*var marker = new createMarker\\(point, \"<div class='location'><strong>.*</strong><br />(?<adr>.*)<br />.*</div>" + "<div class='avail'>Bikes available: <strong>(?<bikes>.*)</strong><br />Docks available: <strong>(?<docks>.*)</strong></div>"; //finds Regex pointRegex = new Regex(regexString); MatchCollection pointMatches = pointRegex.Matches(xmlString); foreach (Match match in pointMatches) { double latitude = Double.Parse(match.Groups["lat"].Value, provider); double longitude = Double.Parse(match.Groups["lng"].Value, provider); int bikes = Int16.Parse(match.Groups["bikes"].Value, provider); int docks = Int16.Parse(match.Groups["docks"].Value, provider); String adress = match.Groups["adr"].Value; Station station = new Station { Lat = latitude, Lng = longitude, Free = bikes, Address = adress, Total = bikes + docks, IsUpdate = true }; stations.Add(station); } String name = "Denver"; City city = new City { Name = name, Stations = stations, TimeStamp = DateTime.Now }; var cities = new List<City>(); cities.Add(city); return cities; }
public BikeStationViewModel(Station station) { Station = station; }