コード例 #1
0
        private static List <WeatherObject> parceForecastWeatherJsonString(string jsonContentString)
        {
            List <WeatherObject> forecast = new List <WeatherObject>();

            try {
                JObject obj = JObject.Parse(jsonContentString);

                JObject    cityJson = (JObject)obj["city"];
                CityObject city     = parceCity(cityJson);

                JArray weatherList = (Newtonsoft.Json.Linq.JArray)obj["list"];

                foreach (JObject weatherJson in weatherList)
                {
                    WeatherObject weatherObj = parceWeather(city, weatherJson);
                    weatherObj = parceForecastMainWeather(weatherObj, weatherJson);

                    forecast.Add(weatherObj);
                }

                return(forecast);
            }

            catch (JsonReaderException e) {
                System.Diagnostics.Debug.WriteLine("-- Error parce json: {0} --", e.Message);
            }

            return(null);
        }
コード例 #2
0
        private static WeatherObject parceForecastMainWeather(WeatherObject weather, JObject obj)
        {
            var weatherJson = obj;

            WeatherMainInfo mainInfo = new WeatherMainInfo();

            mainInfo.Pressure = (float)weatherJson["pressure"];
            mainInfo.Humidity = (float)weatherJson["humidity"];

            weatherJson = (JObject)obj["temp"];

            mainInfo.Temp     = (float)weatherJson["day"];
            mainInfo.Temp_min = (float)weatherJson["min"];
            mainInfo.Temp_max = (float)weatherJson["max"];

            DayInfo dayInfo = new DayInfo();

            dayInfo.Temp      = (float)weatherJson["day"];
            dayInfo.TempNight = (float)weatherJson["night"];
            dayInfo.TempEve   = (float)weatherJson["eve"];
            dayInfo.TempMorn  = (float)weatherJson["morn"];

            weather.MainInfo = mainInfo;
            weather.DayInfo  = dayInfo;

            return(parceWindWeather(weather, obj));
        }
コード例 #3
0
        protected void weatherEventHandler(WeatherObject weatherObject, WebException webExeptin)
        {
            if (webExeptin == null)
            {
                if (weatherObject != null)
                {
                    this.CurrentWeather = weatherObject;

                    if (this.DidUpdateWeaherEventHandler != null)
                    {
                        this.DidUpdateWeaherEventHandler(this.CurrentWeather);
                    }
                }


                else
                {
                    System.Diagnostics.Debug.WriteLine("-- ERROR: weather object is nil --");
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("-- ERROR: {0} --", webExeptin.Message);

                if (this.ErrorUpdateWeaherEventHandler != null)
                {
                    this.ErrorUpdateWeaherEventHandler(webExeptin);
                }
            }
        }
コード例 #4
0
        private static WeatherObject parceWindWeather(WeatherObject weather, JObject obj)
        {
            Wind windInfo = new Wind();

            windInfo.Speed = (float)obj["speed"];
            windInfo.Deg   = (float)obj["deg"];

            weather.MainInfo.Wind = windInfo;

            return(weather);
        }
コード例 #5
0
        private static WeatherObject parceWeather(CityObject city, JObject obj)
        {
            WeatherObject weather = new WeatherObject(city);

            var weatherJson = obj["weather"][0];

            weather.Id          = (int)weatherJson["id"];
            weather.Main        = (string)weatherJson["main"];
            weather.Description = (string)weatherJson["description"];
            weather.Icon        = (string)weatherJson["icon"];

            return(weather);
        }
コード例 #6
0
        protected void DidUpdateWeaherEventHandler(WeatherObject weatherObj)
        {
            if (DidEndUpadateWeather != null)
            {
                DidEndUpadateWeather();
            }

            float temperature = ConverterValueContext.convertTemperature(WeatherModel.CurrentWeather.MainInfo.Temp, this.TemperatureFormat);

            Temperature = string.Format("{0:0.#}", temperature);
            Main        = WeatherModel.CurrentWeather.Main;
            WindSpeed   = WeatherModel.CurrentWeather.MainInfo.Wind.Speed.ToString();
            Humidity    = WeatherModel.CurrentWeather.MainInfo.Humidity.ToString();
            City        = WeatherModel.CurrentWeather.City.Name;
        }
コード例 #7
0
        private static WeatherObject parceCurrentMainInfoWeather(WeatherObject weather, JObject obj)
        {
            var weatherJson = obj;

            WeatherMainInfo mainInfo = new WeatherMainInfo();

            mainInfo.Temp     = (float)weatherJson["temp"];
            mainInfo.Pressure = (float)weatherJson["pressure"];
            mainInfo.Humidity = (float)weatherJson["humidity"];
            mainInfo.Temp_min = (float)weatherJson["temp_min"];
            mainInfo.Temp_max = (float)weatherJson["temp_max"];

            weather.MainInfo = mainInfo;

            return(weather);
        }
コード例 #8
0
        private static WeatherObject parceCurrentWeatherJsonString(string jsonContentString)
        {
            try {
                JObject       obj     = JObject.Parse(jsonContentString);
                CityObject    city    = parceCity(obj);
                WeatherObject weather = parceWeather(city, obj);

                weather = parceCurrentMainInfoWeather(weather, (JObject)obj["main"]);
                weather = parceWindWeather(weather, (JObject)obj["wind"]);

                return(weather);
            }
            catch (JsonReaderException e) {
                System.Diagnostics.Debug.WriteLine("-- Error parce json: {0} --", e.Message);
            }

            return(null);
        }
コード例 #9
0
 public WatherCurrentModel(CityObject city) : base()
 {
     CurrentWeather = new WeatherObject(city);
 }