예제 #1
0
        internal static List <CityWeather> GetWeatherObject(string weatherString, RequestType type)
        {
            List <CityWeather> returnCityWeathers = new List <CityWeather>();

            try
            {
                switch (type)
                {
                case RequestType.MultipleCity:
                    GroupCityWeather group = JsonConvert.DeserializeObject <GroupCityWeather>(weatherString);
                    returnCityWeathers = group.CityList.ToList();
                    // return group;
                    break;

                case RequestType.SingleCity:
                default:
                    CityWeather cityWeather = JsonConvert.DeserializeObject <CityWeather>(weatherString);
                    //return cityWeather;
                    returnCityWeathers.Clear();
                    returnCityWeathers.Add(cityWeather);
                    break;
                }
                return(returnCityWeathers);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
예제 #2
0
        //void UpdateWeather(object cityWeather)
        //{
        //    this.Dispatcher.BeginInvoke((Action)(() =>
        //    {
        //        UpdateWeather((List<CityWeather>)cityWeather);
        //    }));

        //}

        private void UpdateWeather(List <CityWeather> cityWeather)
        {
            Console.WriteLine("here");

            CityWeather city = cityWeather[0];

            // city name
            txtCityName.Text = city.name + (city.sys.country.Trim().Length > 0 ? String.Format(", {0}", city.sys.country.Trim()) : "");

            StringBuilder weatherInfo = new StringBuilder();

            for (int i = 0; i < city.weather.Length; i++)
            {// weather info
                weatherInfo.Append(city.weather[i].main);
                if ((i + 1) < city.weather.Length)
                {
                    weatherInfo.Append(", ");
                }
            }
            txtCityWeather.Text = weatherInfo.ToString();

            // city temperature
            txtCityTemp.Text = String.Format("{0:N2}", city.main.temp);

            txtCityTempS.Content = AppSetting.GetTempSymbol();

            txtCityPressure.Text = String.Format("{0:N2} hPa", city.main.pressure);

            txtCityHumidity.Text = String.Format("{0:N2}%", city.main.humidity);

            txtCityWind.Text = city.wind.deg.ToString() + "," + String.Format("{0:N2} m/s", city.wind.speed);

            txtCityUpdateTime.Text = city.updateTime.ToLongTimeString();
        }