Пример #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="currentWeather"></param>
        public async static void SaveWeatherInfo(Weather currentWeather)
        {
            var file =
                await ApplicationData.Current.LocalFolder.CreateFileAsync(StorageHelper.weatherStorageId,CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteTextAsync(file, StorageHelper.SerializeObject(currentWeather));            
        }
Пример #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public async static Task<Weather> GetWeatherInfo()
 {
     Weather lastWeather = new Weather();            
     try
     {
         var file = await  ApplicationData.Current.LocalFolder.GetFileAsync(StorageHelper.weatherStorageId);
         string base64String = await FileIO.ReadTextAsync(file);
         lastWeather = StorageHelper.DeserializeObject(base64String, typeof(Weather)) as Weather;
         return lastWeather;
     }
     catch (Exception ex)
     {
         return new Weather();
     }
 }
Пример #3
0
 /// <summary>
 /// Obtiene el clima que se guardo en almacenamiento aislado
 /// </summary>
 /// <returns></returns>
 public static Weather GetWeatherInfo()
 {
     Weather lastWeather = new Weather();
     using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
     {
         if(isf.FileExists(StorageHelper.weatherStorageId))
         {
             using (var stream = isf.OpenFile(StorageHelper.weatherStorageId,System.IO.FileMode.Open))
             {
                 DataContractSerializer serializer = new DataContractSerializer(typeof(Weather));
                 lastWeather = serializer.ReadObject(stream) as Weather;
                 stream.Close();
             }
         }
     }
     return lastWeather;
 }
Пример #4
0
        /// <summary>
        /// Ayuda a serializar y guardar los datos del clima en almacenamiento local
        /// </summary>
        /// <param name="weather"></param>
        public static void SaveWeatherInfo(Weather weather)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(Weather));

            using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isf.FileExists(StorageHelper.weatherStorageId))
                {
                    isf.DeleteFile(StorageHelper.weatherStorageId);
                }

                using (var stream = isf.CreateFile(StorageHelper.weatherStorageId))
                {
                    serializer.WriteObject(stream, weather);
                    stream.Close();
                }

            }
        }