BikeInCity.Web.Biking.Decaux.GetCity C# (CSharp) Метод

GetCity() публичный статический Метод

Gets the data about Decaux working service. Some cities require postfixing the stationdetails url by the name of the city. .../stationdetails/valence/id ../stationndetaisl/id
public static GetCity ( String baseUrl, String stationDetailsPostfix ) : City
baseUrl String
stationDetailsPostfix String
Результат BikeInCity.Model.City
        public static City GetCity(String baseUrl, String stationDetailsPostfix)
        {
            XDocument xDoc = XDocument.Load(baseUrl + "service/carto");

            var stations = (from c in xDoc.Descendants("carto").Descendants("markers").Descendants("marker")
                            select new Station
                            {
                                Address = ((string)c.Attribute("address")).Replace("-","").ToLower(),
                                Id = (int)c.Attribute("number"),
                                Lat = (double)c.Attribute("lat"),
                                Lng = (double)c.Attribute("lng"),
                                //initialize Free to -1 - if the client obtains -1 it will show it orange - as we do not have the correct information
                                Free = -1,
                                //no info yet
                                IsUpdate = false
                            }).ToList();

            try
            {
                //update values for each station
                foreach (var station in stations)
                {
                    String url = baseUrl + "service/stationdetails/" + stationDetailsPostfix + station.Id;
                    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.Free = updateStation.Free;
                    station.Total = updateStation.Total;

                }
            }
            catch (Exception ex)
            {
                _log.Info("Decaux: - Error while getting information about station: " + ex);
            }

            City city = new City
            {
                Stations = stations,
                TimeStamp = DateTime.Now
            };

            return city;
        }

Usage Example

Пример #1
0
        public List <City> ProcessCity()
        {
            var city = Decaux.GetCity("http://www.valenbisi.es/", "valence/");

            city.Name = "Valencia";

            var cities = new List <City>();

            cities.Add(city);
            return(cities);
        }
All Usage Examples Of BikeInCity.Web.Biking.Decaux::GetCity
Decaux