private void LoadOldData() { CurrentConditionsWrapper myWrapper; using (IsolatedStorageFile myIso = IsolatedStorageFile.GetUserStoreForApplication()) { if (!myIso.FileExists("Seattle.txt")) { throw new FileNotFoundException(); } using (StreamReader myReader = new StreamReader(new IsolatedStorageFileStream("Seattle.txt", FileMode.Open, myIso))) { myWrapper = CurrentWeatherGetter.TranslateJson <CurrentConditionsWrapper>(myReader.ReadToEnd()); } } // remove any previous data if (myWrapper != null) { CurrentWeatherViewModel forecast = new CurrentWeatherViewModel(myWrapper); this.Forecasts.Remove(forecast); this.Forecasts.Add(forecast); } }
private void bw_DoWork(object sender, DoWorkEventArgs e) { object[] state = (object[])e.Argument; FrameworkElement list = (FrameworkElement)state[0]; Uri uri = (Uri)state[1]; CallType typeOf = (CallType)state[2]; ProgressBar myProgressBar = (ProgressBar)state[3]; CurrentWeatherGetter cwg = new CurrentWeatherGetter(list, typeOf, myProgressBar); cwg.TryGetWeather(uri); }
private void ParseAsForecast(Stream jsonStream) { ForecastWrapper myWrapper = CurrentWeatherGetter.TranslateJson <ForecastWrapper>(jsonStream); if (myWrapper == null) { return; } ObservableCollection <ForecastViewModel> newDataContext = new ObservableCollection <ForecastViewModel>(); List <TxtForecastDay> myForecasts = new List <TxtForecastDay>(); bool hasHitTomorrow = false; foreach (TxtForecastDay txtForecast in myWrapper.forecast.txt_forecast.forecastday) { // skip any forecasts for today if (!hasHitTomorrow) { if (DateTime.Now.AddDays(1).DayOfWeek.ToString().ToLower().Equals(txtForecast.title.ToLower())) { hasHitTomorrow = true; } } // e.g., [0,1] are [tomorrow,tomorrow_night] if (hasHitTomorrow) { myForecasts.Add(txtForecast); } } bool haveHitTomorrow = false; int count = -1; foreach (ForecastDay day in myWrapper.forecast.simpleforecast.forecastday) { if (haveHitTomorrow) { newDataContext.Add(new ForecastViewModel(day) { DayPrediction = myForecasts.ElementAt(count).fcttext, NightPrediction = myForecasts.ElementAt(count + 1).fcttext }); } else { haveHitTomorrow = true; } count++; } this.control.Dispatcher.BeginInvoke(delegate { control.DataContext = newDataContext; }); }
private void ParseAsCurrent(Stream jsonStream) { CurrentConditionsWrapper myWrapper = CurrentWeatherGetter.TranslateJson <CurrentConditionsWrapper>(jsonStream); if (myWrapper == null) { return; } CurrentWeatherViewModel myView = new CurrentWeatherViewModel(myWrapper); //ObservableCollection<CurrentWeatherViewModel> newDataContext = new ObservableCollection<CurrentWeatherViewModel>(); //newDataContext.Add(new CurrentWeatherViewModel(myWrapper)); this.control.Dispatcher.BeginInvoke(delegate { control.DataContext = myView; }); }
private void ParseAsCities(Stream jsonStream) { CityWrapper myWrapper = CurrentWeatherGetter.TranslateJson <CityWrapper>(jsonStream); if (myWrapper == null) { return; } ObservableCollection <City> myCities = new ObservableCollection <City>(); foreach (City c in myWrapper.RESULTS) { myCities.Add(c); } this.control.Dispatcher.BeginInvoke(delegate { control.DataContext = myCities; }); }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { myGetter = new CurrentWeatherGetter(CitiesListBox, CallType.AddCity, ProgressBar); AddCityTextBox.Focus(); }