Exemple #1
0
        public void GetForecastForCityAsync(CityWeather cityWeather)
        {
            string link = string.Format("http://api.openweathermap.org/data/2.5/forecast?units=metric&id={0}&APPID={1}", cityWeather.CityID.ToString(), OpenWeatherKey);

            if (forecastClient.IsBusy)
            {
                return;
            }
            forecastClient.OpenReadCompleted += forecastClient_OpenReadCompleted;
            forecastClient.OpenReadAsync(new Uri(link), cityWeather);
        }
Exemple #2
0
 void mapControl1_SelectionChanged(object sender, MapSelectionChangedEventArgs e) {
     IList<object> selection = e.Selection;
     if(selection == null || selection.Count != 1)
         return;
     CityWeather cityWeatherInfo = selection[0] as CityWeather;
     this.actualWeatherInfo = cityWeatherInfo;
     if(cityWeatherInfo != null) {
         if(cityWeatherInfo.Forecast == null) {
             OpenWeatherMapService.GetForecastForCityAsync(cityWeatherInfo);
             cityWeatherInfo.ForecastUpdated += cityWeatherInfo_ForecastUpdated;
         } else
             cityWeatherInfo_ForecastUpdated(cityWeatherInfo, null);
     }
 }
Exemple #3
0
 void forecastClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         forecastClient.OpenReadCompleted -= forecastClient_OpenReadCompleted;
         Stream      stream          = e.Result;
         CityWeather cityWeatherInfo = (CityWeather)e.UserState;
         Task.Factory.StartNew(() => {
             lock (forecastLocker) {
                 ForecastInfo forecast = ReadForecast(stream);
                 cityWeatherInfo.SetForecast(forecast);
             }
         });
     }
 }
Exemple #4
0
        void weatherClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            WebClient weatherClient = sender as WebClient;

            weatherClient.OpenReadCompleted -= weatherClient_OpenReadCompleted;

            if (e.Cancelled || e.Error != null)
            {
                return;
            }

            Stream stream = e.Result;

            Task.Factory.StartNew(() => {
                DataContractJsonSerializer dc     = new DataContractJsonSerializer(typeof(WorldWeatherInfo));
                WorldWeatherInfo worldWeatherInfo = (WorldWeatherInfo)dc.ReadObject(stream);
                List <CityWeather> citiesWeather  = new List <CityWeather>();
                foreach (CityCurrentWeatherInfo weatherInfo in worldWeatherInfo.list)
                {
                    CityWeather cityWeather = new CityWeather(weatherInfo);
                    if (cityWeather.City == "Los Angeles")
                    {
                        LosAngelesWeather = cityWeather;
                    }
                    if (cityWeather.WeatherDescriptions != null && cityWeather.WeatherDescriptions.Count > 0)
                    {
                        cityWeather.WeatherIconPath = OpenWeatherIconPathPrefix + cityWeather.WeatherDescriptions[0].IconName + ".png";
                    }

                    string cityWithId = string.Format("{0};{1}", cityWeather.City, cityWeather.CityID);
                    if (capitalNames.Contains(cityWeather.City) || capitalNames.Contains(cityWithId))
                    {
                        citiesWeather.Add(cityWeather);
                    }
                }
                weatherInCities = citiesWeather;
                RaiseReadComplete();
            });
        }
Exemple #5
0
 public void GetForecastForCityAsync(CityWeather cityWeather) {
     string link = "http://api.openweathermap.org/data/2.5/forecast?units=metric&id=" + cityWeather.CityID.ToString();
     if (forecastClient.IsBusy)
         return;
     forecastClient.OpenReadCompleted += forecastClient_OpenReadCompleted;
     forecastClient.OpenReadAsync(new Uri(link), cityWeather);
 }
Exemple #6
0
        void weatherClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {
            WebClient weatherClient = sender as WebClient;
            weatherClient.OpenReadCompleted -= weatherClient_OpenReadCompleted;

            if(e.Cancelled || e.Error != null)
                return;

            Stream stream = e.Result;
            Task.Factory.StartNew(() => {
                DataContractJsonSerializer dc = new DataContractJsonSerializer(typeof(WorldWeatherInfo));
                WorldWeatherInfo worldWeatherInfo = (WorldWeatherInfo)dc.ReadObject(stream);
                List<CityWeather> citiesWeather = new List<CityWeather>();
                foreach(CityCurrentWeatherInfo weatherInfo in worldWeatherInfo.list) {
                    CityWeather cityWeather = new CityWeather(weatherInfo);
                    if(cityWeather.City == "Los Angeles")
                        LosAngelesWeather = cityWeather;
                    if(cityWeather.WeatherDescriptions != null && cityWeather.WeatherDescriptions.Count > 0)
                        cityWeather.WeatherIconPath = OpenWeatherIconPathPrefix + cityWeather.WeatherDescriptions[0].IconName + ".png";

                    string cityWithId = string.Format("{0};{1}", cityWeather.City, cityWeather.CityID);
                    if(capitalNames.Contains(cityWeather.City) || capitalNames.Contains(cityWithId))
                        citiesWeather.Add(cityWeather);
                }
                weatherInCities = citiesWeather;
                RaiseReadComplete();
            });
        }
Exemple #7
0
 void LoadWeatherPicture(CityWeather cityWeatherInfo) {
     this.chartControl1.Series[0].DataSource = cityWeatherInfo.Forecast;
     lbCity.Text = cityWeatherInfo.City;
     lbTemperature.Text = cityWeatherInfo.Weather.GetTemperatureString(actualMeasureUnits);
     peWeatherIcon.LoadAsync(cityWeatherInfo.WeatherIconPath);
 }