Ejemplo n.º 1
0
        public List<City> ProcessCity()
        {
            String url = String.Format("http://dynamisch.citybikewien.at/citybike_xml.php");
            XDocument xDoc = XDocument.Load(url);

            var stations = (from station in xDoc.Descendants("station")
                            let free = Convert.ToInt32(station.Element("free_bikes").Value)
                            let freeboxes = Convert.ToInt32(station.Element("free_boxes").Value)
                            select new Station
                            {
                                Address = station.Element("name").Value,
                                Lat =  WebUtils.ToDoubleTolerate(station.Element("latitude").Value),
                                Lng = WebUtils.ToDoubleTolerate(station.Element("longitude").Value),
                                Free = free,
                                Total = free + freeboxes
                            }).ToList();

            String name = "Wien";
            City city = new City
            {
                Name = name,
                Stations = stations,
                TimeStamp = DateTime.Now
            };

            var cities = new List<City>();
            cities.Add(city);
            return cities;
        }
Ejemplo n.º 2
0
        private void UpdateCityStations(City city, ISession session)
        {
            City cityInDB;
            if (city.Id != 0)
            {
                cityInDB = session.Load<City>(city.Id);
            }
            else
            {
                cityInDB = session.Query<City>().Where(x => x.Name == city.Name).FirstOrDefault();
            }

            if (cityInDB == null)
            {
                _log.Error("City with ID: " + city.Id + " or name " + city.Name + " not found in DB");
                return;
            }

            var query = session.CreateQuery("delete Station where CityId = " + cityInDB.Id);
            var result = query.ExecuteUpdate();
            Console.Write(result);

            session.Refresh(cityInDB);

            foreach (var station in city.Stations)
            {
                station.City = cityInDB;
                session.Save(station);
            }

            cityInDB.Stations = city.Stations;
            session.Update(cityInDB);
            session.Flush();
        }
Ejemplo n.º 3
0
        public List<City> ProcessCity()
        {
            String rennesUrl = String.Format("https://profil.bixi.ca/data/bikeStations.xml");
            XDocument xDoc = XDocument.Load(rennesUrl);

            var stations = (from station in xDoc.Descendants("station")
                            let emptyDocks = Convert.ToInt32(station.Element("nbEmptyDocks").Value)
                            let free = Convert.ToInt32(station.Element("nbBikes").Value)
                            select new Station
                            {
                                Address = station.Element("name").Value,
                                Lat = WebUtils.ToDoubleTolerate(station.Element("lat").Value),
                                Lng = WebUtils.ToDoubleTolerate(station.Element("long").Value),
                                Free = free,
                                Total = emptyDocks + free
                            }).ToList();

            String name = "Montreal";
            City city = new City
            {
                Name = name,
                Stations = stations,
                TimeStamp = DateTime.Now
            };

            var cities = new List<City>();
            cities.Add(city);
            return cities;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="baseUrl"></param>
        /// <param name="stationDetailsPostfix"></param>
        /// <returns></returns>
        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;
        }
Ejemplo n.º 6
0
        public List<City> ProcessCity()
        {
            //iformatprovide for the convert method
            IFormatProvider provider = CultureInfo.InvariantCulture.NumberFormat;

            XDocument xDoc = XDocument.Load("http://api.bike-stats.co.uk/service/rest/bikestats?format=[xml]");
            var stations = (from c in xDoc.Descendants("dockStationList").Descendants("dockStation")
                            select new Station
                            {
                                Address = (string)c.Element("name").Value,
                                Id = Convert.ToInt16(c.Attribute("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("emptySlots").Value, provider),
                                //already have some info
                                IsUpdate = true
                            }).ToList();

            //result = (from c in xDoc.Descendants("stations").Descendants("station")
            //          select new Station
            //          {
            //            Address = (string)c.Element("name").Value,
            //            Id = Convert.ToInt16(c.Element("id").Value, provider),
            //            Lat = Convert.ToDouble(c.Element("lat").Value, provider),
            //            Lng = Convert.ToDouble(c.Element("long").Value, provider),
            //            Free = Convert.ToInt16(c.Element("nb_bikes").Value, provider),
            //            Total = Convert.ToInt16(c.Element("nb_bikes").Value, provider) + Convert.ToInt16(c.Element("nb_empty_docks").Value, provider),
            //            //already have some info
            //            IsUpdate = true
            String name = "London";
            City city = new City
            {
                Name = name,
                Stations = stations,
                TimeStamp = DateTime.Now
            };

            var cities = new List<City>();
            cities.Add(city);
            return cities;
        }
Ejemplo n.º 7
0
        public List<City> ProcessCity()
        {
            Random r = new Random();
            var stations = WebUtils.ProcessManualCity(WebUtils.GetAppDataPath("brno_test.xml"));

            foreach (var station in stations)
            {
                station.Free = r.Next(10);
                station.Total = 10;
            }

            City city = new City
            {
                Stations = stations
            };

            city.Name = "Brno";

            var cities = new List<City>();
            cities.Add(city);
            return cities;
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        private City NewCity(string countryName, double lat, double lng, string name)
        {
            var country = _repository.Find<Country>(x => x.Name == countryName).FirstOrDefault();

            if (country == null)
            {
                country = new Country() { Name = countryName };
                _repository.Save<Country>(country);
            }

            City city = new City { Country = country, Lat = lat, Lng = lng, Name = name };
            return city;
        }
Ejemplo n.º 11
0
        public void UpdateCityStations(City city)
        {
            City cityInDB;
            if (city.Id != 0)
            {
                cityInDB = _repository.Load<City>(city.Id);
            }
            else
            {
                cityInDB = _repository.Find<City>(x => x.Name == city.Name).FirstOrDefault();
            }

            if (cityInDB == null)
            {
                _log.Error("City with ID: " + city.Id + " or name " + city.Name + " not found in DB");
                return;
            }

            var result = _repository.ExecuteUpdateQuery("delete Station where CityId = " + cityInDB.Id);
            Console.Write(result);

            _repository.Flush();

            _repository.Refresh<City>(cityInDB);

            foreach (var station in city.Stations)
            {
                station.City = cityInDB;
                _repository.Save(station);
            }

            cityInDB.Stations = city.Stations;
            _repository.Update(cityInDB);
            _repository.Flush();
        }
Ejemplo n.º 12
0
 public void SaveCity(City city)
 {
     _repository.Save<City>(city);
 }
Ejemplo n.º 13
0
        public static City GetCity(String baseUrl)
        {
            //iformatprovide for the convert method
            IFormatProvider provider = CultureInfo.InvariantCulture.NumberFormat;

            WebClient client = new WebClient();
            var xmlString = client.DownloadString(baseUrl + "localizaciones/localizaciones.php");

            //regex to find the KML data in the HTML
            Regex kmlRegex = new Regex("<Document>(.*)</Document>");

            //finds the DIV tag containing the address
            Regex addressTerm = new Regex("<div style=\"font:bold 11px verdana;color:#cf152c;margin-bottom:10px\">(?<match>[^<]*?)</div>");

            //finds the DIV tag containing to digits with information of free bikes and free places
            Regex freeTerm = new Regex("<div style=\"margin-left:5px;float:left;font:bold 11px verdana;color:green\">(?<free>\\d*)<br />(?<places>\\d*)<br /></div>");

            Match m = kmlRegex.Match(xmlString);

            String kmlData = m.Value;
            XDocument xDoc = XDocument.Parse(kmlData);

            char[] separator = { ',' };

            var test = (from c in xDoc.Descendants("Document").Descendants("Placemark")

                        let description = (string)c.Element("description").Value
                        let addressMatch = addressTerm.Match(description)
                        let address = addressMatch.Groups["match"].Value

                        let freeMatch = freeTerm.Match(description)
                        let free = freeMatch.Groups["free"].Value
                        let places = freeMatch.Groups["places"].Value

                        let coordinates = c.Element("Point").Element("coordinates").Value
                        let coordinatesarray = coordinates.Split(separator)

                        //here I am rather creating anonymous type, because the convert methods might cause exceptions
                        //which I do not know how to catch i LINQ
                        select new
                        {
                            free,
                            places,
                            address,
                            coordinatesarray
                        });

            //have to initialize the list(which is done automatically by LINQ in cases of other cities
            var stations = new List<Station>();

            foreach (var v in test)
            {
                try
                {
                    //prepare the values
                    double lat = Convert.ToDouble(v.coordinatesarray[1], provider);
                    double lng = Convert.ToDouble(v.coordinatesarray[0], provider);

                    int free = Convert.ToInt16(v.free, provider);
                    int total = free + Convert.ToInt16(v.places, provider);

                    //create new station and add to the result lit
                    stations.Add(new Station()
                    {
                        Lat = lat,
                        Lng = lng,
                        Address = v.address,
                        Free = free,
                        Total = total,
                        IsUpdate = true
                    });
                }
                //here catch the possible errors of conversions
                catch (Exception ex)
                {
                    _log.Info("Error while converting CityBike station" + ex);
                }
            }

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

            return city;
        }
Ejemplo n.º 14
0
 public BikeCityViewModel(City city)
 {
     _bikeCity = city;
 }
Ejemplo n.º 15
0
        private void SaveLocalCopy(City city)
        {
            //provde invariant culture for serialization
              Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

              using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
              {
            using (IsolatedStorageFileStream fs = isf.CreateFile("City.dat"))
            {
            XmlSerializer ser = new XmlSerializer(typeof(City));
              ser.Serialize(fs, city);
            }
              }
        }
Ejemplo n.º 16
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            //WP7Timer.Start();
              //WP7Timer.Time("Start");

              //provide invariant culture fo deserialization
              Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

              //try to get the situation which was previously saved
              City city = new City();
              try
              {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
              if (isf.FileExists("City.dat"))
              {
            XmlSerializer ser = new XmlSerializer(typeof(City));
            object obj = ser.Deserialize(isf.OpenFile("City.dat", System.IO.FileMode.Open)) as City;
            if (obj != null && obj is City)
            {
                city = obj as City;
                PhoneApplicationService.Current.State.Add("City", city);
            }
              }
            }
              }
              catch (Exception)
              {
            //TODO - what to do with exception in the Launching event??
              }
        }