BikeInCity.Web.Biking.Rennes.ProcessCity C# (CSharp) Метод

ProcessCity() публичный Метод

public ProcessCity ( ) : List
Результат List
        public List<City> ProcessCity()
        {
            //iformatprovide for the convert method
            IFormatProvider provider = CultureInfo.InvariantCulture.NumberFormat;

            //Getting the RENNES_APP key from the configuration session
            string RENNES_KEY = ConfigurationManager.AppSettings["RENNES_KEY"];

            String rennesUrl = String.Format("http://data.keolis-rennes.com/xml/?version=1.0&key={0}&cmd=getstation", RENNES_KEY);
            XDocument xDoc = XDocument.Load(rennesUrl);
            String cityName = this.GetType().Name;

            var stations = (from c in xDoc.Descendants("opendata").Descendants("answer").Descendants("data").Descendants("station")
                            select new Station
                            {
                                Address = (string)c.Element("name").Value,
                                Id = Convert.ToInt16(c.Element("id").Value, provider),
                                Lat = Convert.ToDouble(c.Element("latitude").Value, provider),
                                Lng = Convert.ToDouble(c.Element("longitude").Value, provider),
                                Free = Convert.ToInt16(c.Element("bikesavailable").Value, provider),
                                Total = Convert.ToInt16(c.Element("bikesavailable").Value, provider) + Convert.ToInt16(c.Element("slotsavailable").Value, provider),
                                //already have some info
                                IsUpdate = true
                            }).ToList();

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

            var cities = new List<City>();
            cities.Add(city);
            return cities;
        }

Usage Example

Пример #1
0
 public void TestRennes()
 {
     Rennes target = new Rennes();
     var result = target.ProcessCity();
     Assert.AreEqual(result.Count, 1);
     TestUtils.TestCityResults(result);
 }