Esempio n. 1
0
        private async void GetWeatherNow(Settings.Settings set)
        {
            // WebRequest request = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=Syktyvkar&lang=en&units=metric&APPID=284736d7aa6652238e2598fa8ce6dd15");
            string     req1    = String.Format("http://api.openweathermap.org/data/2.5/weather?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set));
            string     req2    = String.Format("http://api.openweathermap.org/data/2.5/forecast?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set));
            WebRequest request = WebRequest.Create(req1);

            request.Method      = "POST";
            request.ContentType = "application/x-www-urlencoded";

            try
            {
                WebResponse response = await request.GetResponseAsync();

                string answer = "";

                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        answer = await sr.ReadToEndAsync();
                    }
                }
                response.Close();

                Weather.OpenWeatherNow OWN = JsonConvert.DeserializeObject <Weather.OpenWeatherNow>(answer);

                request  = WebRequest.Create(req2);
                response = await request.GetResponseAsync();

                answer = "";
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        answer = await sr.ReadToEndAsync();
                    }
                }
                response.Close();
                Weather.OpenWeatherFiveDays OWFD = JsonConvert.DeserializeObject <Weather.OpenWeatherFiveDays>(answer);

                SetWeatherParams(OWN, OWFD, set);
            }
            catch
            {
                if (set.General.Language == "English")
                {
                    SetWeatherParams("Сonnection problemю. No data", set);
                }
                else
                {
                    SetWeatherParams("Проблемы с подключением. Нет данных", set);
                }
            }
        }
Esempio n. 2
0
        private void SetWeatherParams(Weather.OpenWeatherNow OWN, Weather.OpenWeatherFiveDays OWFD, Settings.Settings set)
        {
            //OWN VALUES
            string tempValue     = "";
            string windValue     = "";
            string pressureValue = "";

            Settings.SettingsHelper.GetWeatherParams(set, ref tempValue, ref windValue, ref pressureValue);

            if (set.General.Language == "English")
            {
                if (set.Weather.MinMaxTemp)
                {
                    temp_label.Text = String.Format("{0}{3} (Min temp {1}{3}, Max temp {2}{3})", Math.Round(OWN.Main.Temp, 0), OWN.Main.TempMin, OWN.Main.TempMax, tempValue);
                }
                else
                {
                    temp_label.Text = String.Format("{0}{1}", Math.Round(OWN.Main.Temp, 0), tempValue);
                }

                wind_label.Text    = String.Format("{0}, speed: {1} {2}", OWN.Wind.DegStrEng, OWN.Wind.Speed, windValue);
                wind_label_1.Text  = "Wind speed, " + windValue;
                dateNow_label.Text = DateTime.Now.ToString("d MMM yyyy", new CultureInfo("en-US"));
            }
            else
            {
                if (set.Weather.MinMaxTemp)
                {
                    temp_label.Text = String.Format("{0}{3} (Мин. темп. {1}{3}, Макс. темп. {2}{3})", OWN.Main.Temp, OWN.Main.TempMin, OWN.Main.TempMax, tempValue);
                }
                else
                {
                    temp_label.Text = String.Format("{0}{1}", OWN.Main.Temp, tempValue);
                }
                wind_label.Text    = String.Format("{0}, скорость: {1} {2}", OWN.Wind.DegStrRu, OWN.Wind.Speed, windValue);
                wind_label_1.Text  = "Скорость ветра, " + windValue;
                dateNow_label.Text = DateTime.Now.ToString("D", new CultureInfo("ru-RU"));
            }

            city_label.Text        = OWN.Name;
            humidity_label.Text    = OWN.Main.Humidity.ToString() + "%";
            pressure_label.Text    = String.Format("{0} {1}", Math.Round(OWN.Main.Pressure, 0), pressureValue);
            description_label.Text = FirstUpper(OWN.Weather[0].Description);
            icon_pictureBox.Image  = OWN.Weather[0].IconPath;
            cloudiness_label.Text  = OWN.Clouds.All + "%";
            wind_pictureBox.Image  = OWN.Wind.Img;
            sunrise_label.Text     = OWN.Sys.SunriseLocal.ToString("t");
            sunset_label.Text      = OWN.Sys.SunsetLocal.ToString("t");

            //OWFD VALUES

            //time
            time1_label.Text = OWFD.List[1].Date.ToString("t");
            time2_label.Text = OWFD.List[2].Date.ToString("t");
            time3_label.Text = OWFD.List[3].Date.ToString("t");
            time4_label.Text = OWFD.List[4].Date.ToString("t");
            time5_label.Text = OWFD.List[5].Date.ToString("t");
            time6_label.Text = OWFD.List[6].Date.ToString("t");
            //icons
            icon1.Image = OWFD.List[1].Weather[0].IconPath;
            icon2.Image = OWFD.List[2].Weather[0].IconPath;
            icon3.Image = OWFD.List[3].Weather[0].IconPath;
            icon4.Image = OWFD.List[4].Weather[0].IconPath;
            icon5.Image = OWFD.List[5].Weather[0].IconPath;
            icon6.Image = OWFD.List[6].Weather[0].IconPath;
            //temp
            temp1.Text = Math.Round(OWFD.List[1].Main.Temp, 0) + tempValue;
            temp2.Text = Math.Round(OWFD.List[2].Main.Temp, 0) + tempValue;
            temp3.Text = Math.Round(OWFD.List[3].Main.Temp, 0) + tempValue;
            temp4.Text = Math.Round(OWFD.List[4].Main.Temp, 0) + tempValue;
            temp5.Text = Math.Round(OWFD.List[5].Main.Temp, 0) + tempValue;
            temp6.Text = Math.Round(OWFD.List[6].Main.Temp, 0) + tempValue;
            //wind
            wind1.Text = Math.Round(OWFD.List[1].Wind.Speed, 0).ToString();
            wind2.Text = Math.Round(OWFD.List[2].Wind.Speed, 0).ToString();
            wind3.Text = Math.Round(OWFD.List[3].Wind.Speed, 0).ToString();
            wind4.Text = Math.Round(OWFD.List[4].Wind.Speed, 0).ToString();
            wind5.Text = Math.Round(OWFD.List[5].Wind.Speed, 0).ToString();
            wind6.Text = Math.Round(OWFD.List[6].Wind.Speed, 0).ToString();
        }