/// <summary>
 /// Returns the correct icon based on the Condition enum
 /// </summary>
 /// <param name="codeCond"></param>
 /// <returns></returns>
 public WriteableBitmap getIconByCondition(City.ConditionEnum codeCond)
 {
     if (codeCond.Equals(City.ConditionEnum.Cloud))
     {
         return getCloudyWeather();
     }
     else if (codeCond.Equals(City.ConditionEnum.Fair))
     {
         return getFairWeather();
     }
     else if (codeCond.Equals(City.ConditionEnum.Fog))
     {
         return getFoggyWeather();
     }
     else if (codeCond.Equals(City.ConditionEnum.Hail))
     {
         return getHailWeather();
     }
     else if (codeCond.Equals(City.ConditionEnum.Rain))
     {
         return getRainyWeather();
     }
     else if (codeCond.Equals(City.ConditionEnum.Snow))
     {
         return getSnowyWeather();
     }
     else if (codeCond.Equals(City.ConditionEnum.Storm))
     {
         return getStormWeather();
     }
     else
     {
         return getSunnyWeather();
     }
 }
 /// <summary>
 /// Saves the city object to local storage
 /// </summary>
 /// <param name="city"></param>
 public static void SaveCityToIsolatedStorage(City city)
 {
     // persist the data using isolated storage
     using (var store = IsolatedStorageFile.GetUserStoreForApplication())
     using (var stream = new IsolatedStorageFileStream("data.txt",
                                                     FileMode.Create,
                                                     FileAccess.Write,
                                                     store))
     {
         var serializer = new XmlSerializer(typeof(City));
         serializer.Serialize(stream, city);
     }
 }
        /// <summary>
        /// Loads the city from the state object
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            city = ApplicationStateHelper.LoadCityFromAppState();

            if (city != null)
            {
                cityTextBox.Text = city.Name;
            }
            else
            {
                city = new City();
            }
        }
        /// <summary>
        /// Loads the city from the state and populates the screen
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                city = ApplicationStateHelper.LoadCityFromAppState();

                if (city != null)
                {
                    cityTextBox.Text = city.Name;
                    conditionValue.Text = city.Condition;
                    temperatureValue.Text = city.Temperature;
                    conditionImage.Source = conditionIconHandler.getIconByCondition(city.getConditionEnum());
                }
            }
            catch (System.ArgumentNullException)
            {
                MessageBox.Show(Utils.GetMessage("UnableToRetrieveWeather"));
            }

            base.OnNavigatedTo(e);
        }
 /// <summary>
 /// Saves the state of the app by storing the city object
 /// </summary>
 /// <param name="city"></param>
 public static void SaveCityToAppState(City city)
 {
     PhoneApplicationService.Current.State[City.KEY] = city;
 }