Esempio n. 1
0
        public static Result <SixteenDaysForecastResult> GetWeatherDaily(JObject response)
        {
            var error = GetServerErrorFromResponse(response);

            if (!String.IsNullOrEmpty(error))
            {
                return(new Result <SixteenDaysForecastResult>(null, false, error));
            }

            var weatherDailies = new List <SixteenDaysForecastResult>();

            var responseItems = JArray.Parse(response["list"].ToString());

            foreach (var item in responseItems)
            {
                var weatherDaily = new SixteenDaysForecastResult();
                if (response["city"] != null)
                {
                    weatherDaily.City    = Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(response["city"]["name"])));
                    weatherDaily.Country = Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(response["city"]["country"])));
                    weatherDaily.CityId  = Convert.ToInt32(response["city"]["id"]);
                }
                if (item["weather"] != null)
                {
                    weatherDaily.Title       = Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(item["weather"][0]["main"])));
                    weatherDaily.Description = Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(item["weather"][0]["description"])));
                    weatherDaily.Icon        = Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(item["weather"][0]["icon"])));
                }
                if (item["temp"] != null)
                {
                    weatherDaily.Temp        = Convert.ToDouble(item["temp"]["day"]);
                    weatherDaily.TempMax     = Convert.ToDouble(item["temp"]["max"]);
                    weatherDaily.TempMin     = Convert.ToDouble(item["temp"]["min"]);
                    weatherDaily.TempMorning = Convert.ToDouble(item["temp"]["morn"]);
                    weatherDaily.TempEvening = Convert.ToDouble(item["temp"]["eve"]);

                    weatherDaily.TempNight = Convert.ToDouble(item["temp"]["night"]);
                }

                weatherDaily.Humidity       = Convert.ToDouble(item["humidity"]);
                weatherDaily.WindSpeed      = Convert.ToDouble(item["speed"]);
                weatherDaily.Clouds         = Convert.ToDouble(item["clouds"]);
                weatherDaily.Pressure       = Convert.ToDouble(item["pressure"]);
                weatherDaily.Rain           = Convert.ToDouble(item["rain"]);
                weatherDaily.DateUnixFormat = Convert.ToInt32(item["dt"]);
                weatherDaily.Date           = TimeHelper.ToDateTime(Convert.ToInt32(item["dt"]));

                weatherDailies.Add(weatherDaily);
            }

            return(new Result <SixteenDaysForecastResult>(weatherDailies, true, TimeHelper.MessageSuccess));
        }
        public static Result<SixteenDaysForecastResult> GetWeatherDaily(JObject response)
        {
            var error = GetServerErrorFromResponse(response);
            if (!string.IsNullOrEmpty(error))
                return new Result<SixteenDaysForecastResult>(null, false, error);

            var weatherDailies = new List<SixteenDaysForecastResult>();

            var responseItems = JArray.Parse(response["list"].ToString());
            foreach (var item in responseItems)
            {
                var weatherDaily = new SixteenDaysForecastResult();
                if (response["city"] != null)
                {
                    weatherDaily.City =
                        Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(response["city"]["name"])));
                    weatherDaily.Country =
                        Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(response["city"]["country"])));
                    weatherDaily.CityId = Convert.ToInt32(response["city"]["id"]);
                }
                if (item["weather"] != null)
                {
                    weatherDaily.Title =
                        Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(item["weather"][0]["main"])));
                    weatherDaily.Description =
                        Encoding.UTF8.GetString(
                            Encoding.Default.GetBytes(Convert.ToString(item["weather"][0]["description"])));
                    weatherDaily.Icon =
                        Encoding.UTF8.GetString(Encoding.Default.GetBytes(Convert.ToString(item["weather"][0]["icon"])));
                }
                if (item["temp"] != null)
                {
                    weatherDaily.Temp = Convert.ToDouble(item["temp"]["day"]);
                    weatherDaily.TempMax = Convert.ToDouble(item["temp"]["max"]);
                    weatherDaily.TempMin = Convert.ToDouble(item["temp"]["min"]);
                    weatherDaily.TempMorning = Convert.ToDouble(item["temp"]["morn"]);
                    weatherDaily.TempEvening = Convert.ToDouble(item["temp"]["eve"]);

                    weatherDaily.TempNight = Convert.ToDouble(item["temp"]["night"]);
                }

                weatherDaily.Humidity = Convert.ToDouble(item["humidity"]);
                weatherDaily.WindSpeed = Convert.ToDouble(item["speed"]);
                weatherDaily.Clouds = Convert.ToDouble(item["clouds"]);
                weatherDaily.Pressure = Convert.ToDouble(item["pressure"]);
                weatherDaily.Rain = Convert.ToDouble(item["rain"]);
                weatherDaily.DateUnixFormat = Convert.ToInt32(item["dt"]);
                weatherDaily.Date = TimeHelper.ToDateTime(Convert.ToInt32(item["dt"]));

                weatherDailies.Add(weatherDaily);
            }

            return new Result<SixteenDaysForecastResult>(weatherDailies, true, TimeHelper.MessageSuccess);
        }