Exemplo n.º 1
0
 public async Task<IEnumerable<City>> LoadCitiesAsync()
 {
     var folder = Folder();
     var files = await folder.GetFilesAsync();
     if (!files.Any(f => f.Name == SETTING_KEY))
     {
         var file = await folder.CreateFileAsync(SETTING_KEY);
         var cities = new City[]
         {
             new City()
             {
                  Name="Namur",
                  Country="Belgique"
             }
         };
         await FileIO.WriteTextAsync(file, JsonConvert.SerializeObject(cities));
         return cities;
     }
     else
     {
         //await files.First(f => f.Name == SETTING_KEY).DeleteAsync(StorageDeleteOption.PermanentDelete);
         var file = files.First(f => f.Name == SETTING_KEY);
         var json = await FileIO.ReadTextAsync(file);
         return JsonConvert.DeserializeObject<City[]>(json);
         //return new City[0];
     }
 }
Exemplo n.º 2
0
 public async Task<IEnumerable<WeatherForecast>> GetForecastByCityAsync(City city)
 {
     var fakeForecast = GetFakeForecast();
     int numberOfForecastsAlreadyLoopedThrough = 0;
     foreach (var forecast in fakeForecast)
     {
         forecast.City = city;
         forecast.Date = forecast.Date.AddDays(numberOfForecastsAlreadyLoopedThrough);
         numberOfForecastsAlreadyLoopedThrough++;
     }
     return fakeForecast;
 }
Exemplo n.º 3
0
 private static async Task<IEnumerable<City>> CreateDefaultFileOfCities(StorageFolder folder)
 {
     var file = await folder.CreateFileAsync(SETTING_KEY);
     var cities = new City[]
     {
             new City()
             {
                  Name="Namur",
                  Country="Belgique"
             }
     };
     await FileIO.WriteTextAsync(file, SerializeToJson(cities));
     return cities;
 }
Exemplo n.º 4
0
        public async void GetForecast(City city, FrameworkElement forecast)
        {
            WeatherService service = new WeatherService();
            var donnees = await service.GetForecastByCityAsync(city);

            List<WeatherForecast> listForecast = new List<WeatherForecast>();
            var i = 0;
            foreach (var fcast in donnees)
            {
                if (i < 5)
                    listForecast.Add(fcast);
                else break;

                i++;
            }

            
        }
Exemplo n.º 5
0
        public async Task AddCity(string ville, string pays)
        {
            //if (verificationVille(ville, pays))
            //{
                var folder = GetFolder();//Je prends le folder
                var files = await folder.GetFilesAsync();//J'y prends les références vers tous les fichiers
                var dataOfCities = await ReadFileOfCities(files);//Je lis les données du fichier de villes
                var fileOfCities = await folder.GetFileAsync(SETTING_KEY);//Je prends le fichier des villes

                var cities = dataOfCities.ToList();

                var city = new City()
                { Name = ville, Country = pays };

                cities.Add(city);

                await FileIO.WriteTextAsync(fileOfCities, SerializeToJson(cities.ToArray()));
          //  }
        }
Exemplo n.º 6
0
 public async Task<WeatherForecast> GetCurrentWeatherByCityAsync(City city)
 {
     return GetFakeForecast().First();
 }
Exemplo n.º 7
0
 private static string SerializeToJson(City[] cities)
 {
     return JsonConvert.SerializeObject(cities);
 }