protected override IList<City> GetCities()
        {
            var result = new List<City>();

            var doc = XDocument.Load("Assets/nextbike-cities.xml");
            foreach (var xctry in doc.Descendants("country"))
            {
                var countryName = (string)xctry.Attribute("country_name");
                var country = countryName ?? DomainNameToCountry((string)xctry.Attribute("domain"));
                var serviceName = (string)xctry.Attribute("name");
                foreach (var xcity in xctry.Descendants("city")/*.ToList()*/)
                {
                    var city = new City() {
                        CityName = (string)xcity.Attribute("name"),
                        Country = country,
                        ServiceName = serviceName,
                        UrlCityName = (string)xcity.Attribute("alias"),
                        UID = (string)xcity.Attribute("uid"),
                        Latitude = (double)xcity.Attribute("lat"),
                        Longitude = (double)xcity.Attribute("lng"),
                        Provider = Instance
                    };
                    if (string.IsNullOrEmpty(city.UrlCityName))
                        city.UrlCityName = city.CityName;
                    result.Add(city);
                }
            }
            return result;
        }
        protected override IList<City> GetCities()
        {
            var result = new List<City>();
            string dataJson = "";

            var csr = App.GetResourceStream(new Uri("Assets/PubliBike-services.zip", UriKind.Relative)).Stream;
            var uz = new UnZipper(csr);
            using (var fs = uz.GetFileStream(uz.FileNamesInZip.FirstOrDefault()))
            {
                var sr = new StreamReader(fs);
                dataJson = sr.ReadToEnd();
            }

            var allServices = dataJson.FromJson<List<AboProvider>>();
            foreach (var abo in allServices)
            {
                if (abo.Abo == null || abo.Abo.Terminals == null) continue;
                var serviceName = abo.Abo.Name;
                var grouppedTerminals = from term in abo.Abo.Terminals where !string.IsNullOrEmpty(term.City) group term by term.City into byCity select new { City = byCity.Key, Country = DomainNameToCountry(byCity.First().Country), Terminals = byCity.ToList() };
                foreach (var xcity in grouppedTerminals)
                {
                    // todo: find an existing city and append the service name; eg: "SwissPass, Bulle"
                    var city = (from c in result where string.Equals(c.CityName, xcity.City, StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault();
                    if (city == null)
                    {
                        city = new City()
                        {
                            CityName = xcity.City,
                            Country = DomainNameToCountry(xcity.Country),
                            ServiceName = serviceName,
                            UrlCityName = xcity.City,
                            Latitude = abo.Abo.Lat,
                            Longitude = abo.Abo.Lng,
                            //UID = (string)xcity.Attribute("uid"),
                            Provider = Instance
                        };
                        if (string.IsNullOrEmpty(city.UrlCityName))
                            city.UrlCityName = city.CityName;
                        result.Add(city);
                    }
                    else if (city.ServiceName.IndexOf(serviceName, StringComparison.InvariantCultureIgnoreCase) < 0)
                    {
                        city.ServiceName += ", " + serviceName;
                        if (!string.Equals(serviceName, "SwissPass", StringComparison.InvariantCultureIgnoreCase))
                        {
                            city.Latitude = abo.Abo.Lat;
                            city.Longitude = abo.Abo.Lng;
                        }
                    }
                }
            }
            return result;
        }
 public SystemConfigViewModel(IEventAggregator events, SystemConfig config, CityContextViewModel cityContext)
 {
     this.events = events;
     this.config = config;
     this.cityContext = cityContext;
     this.Cities = new List<City>();
     Cities.Add(new City() { CityName = " - automatic - " });
     Cities.AddRange(BikeServiceProvider.GetAllCities().OrderBy(c => c.Country + c.CityName));
     if (string.IsNullOrEmpty(config.City))
         selectedCity = Cities[0];
     else
         selectedCity = Cities.Where(c => config.City.Equals(c.UrlCityName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
 }
 public void SetCity(City newCity)
 {
     if (newCity == this.city)
         return;
     var saveCity = this.city;
     if (saveCity != null)
         ThreadPoolScheduler.Instance.Schedule(() => { SaveToDB(saveCity); });
     this.city = newCity;
     if (city != null)
     {
         if (city.Coordinate != null && !city.Coordinate.IsUnknown)
             IoC.Get<Bicikelj.Model.Analytics.IAnalyticsService>().SetLocation(city.Coordinate);
     }
     subCity.OnNext(this.city);
 }
        public void SaveToDB(City saveCity)
        {
            if (saveCity == null || string.IsNullOrEmpty(saveCity.UrlCityName) || saveCity.Favorites == null || saveCity.Stations == null)
                return;

            if (saveCity is CityNetwork)
            {
                foreach (var nCity in (saveCity as CityNetwork).Cities)
                    SaveToDB(nCity);
                return;
            }

            saveCity.Favorites.Apply(f =>
            {
                if (f != null)
                    f.City = saveCity.UrlCityName;
            });
            var cityJson = saveCity.ToJson();
            using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!myIsolatedStorage.DirectoryExists("Cities"))
                    myIsolatedStorage.CreateDirectory("Cities");
                var cityFile = "Cities\\" + saveCity.UrlCityName;

                using (var fileStream = new IsolatedStorageFileStream(cityFile, FileMode.Create, myIsolatedStorage))
                using (var writer = new StreamWriter(fileStream))
                {
                    writer.Write(cityJson);
                }
            }
        }
 public bool GetCityForStation(StationLocation station, out City scity)
 {
     scity = GetCityForStation(station);
     return scity != null;
 }