예제 #1
0
        //        Прогноз на день
        private async void ForecastDay()
        {
            //            String url = $"http://dataservice.accuweather.com/forecasts/v1/daily/1day/{geoKey}?apikey=9pbmpNTkGYJTGy8sKGDxiIy8ADvYjqIl&language=ru-ru&details=true&metric=true";
            string url = $"http://dataservice.accuweather.com/forecasts/v1/daily/1day/{geoKey}?apikey=9pbmpNTkGYJTGy8sKGDxiIy8ADvYjqIl&language={Classes.Language.nameLanguage}&details=true&metric=true";
            //LabelErrors.Content = geoKey;
            //Основной запрос
            WebRequest request = WebRequest.Create(url);

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

            WebResponse response = await request.GetResponseAsync();

            string answer = string.Empty;


            using (Stream s = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(s))
                {
                    answer = await reader.ReadToEndAsync();
                }

                response.Close();

                TextBoxAnswer.Text = answer;

                AccuWeather.AccuWeather aW = JsonConvert.DeserializeObject <AccuWeather.AccuWeather>(answer);

                DailyWeather.Rootobject dW = JsonConvert.DeserializeObject <DailyWeather.Rootobject>(answer);



                //Вывод даты и дня недели
                //LabelDT.Content = (Classes.DateTimeConverting.dayOfWeek(dW.DailyForecasts[0].EpochDate) + ", " + Classes.DateTimeConverting.dayOfMonth(dW.DailyForecasts[0].EpochDate)).ToUpper();
                DateTimeConverting myDateTime = new DateTimeConverting(dW.DailyForecasts[0].EpochDate);
                LabelDT.Content = (myDateTime.dayOfWeek + ", " + myDateTime.dayOfMonth).ToUpper();

                LabelHeadingPage.Content = Properties.Resources.LabelHeadingPageDailyForecast;

                LabelDateTime.Content = myDateTime.dm;

                string v   = "pack://application:,,,/My Weather;component/Images/Icons/" + aW.DailyForecasts[0].Day.iconFile;
                Uri    uri = new Uri(v, UriKind.Absolute);
                try
                {
                    ImageSource imgSource = new BitmapImage(uri);
                    ImageIcon.Source = imgSource;
                }
                catch
                {
                }

                LabelTempMax.Content    = Convert.ToInt16(dW.DailyForecasts[0].Temperature.Maximum.Value) + "°";
                LabelTempMaxAdd.Content = Properties.Resources.LabelTempMax;
                LabelTempMin.Content    = Convert.ToInt16(dW.DailyForecasts[0].Temperature.Minimum.Value) + "°";
                LabelTempMinAdd.Content = Properties.Resources.LabelTempMin;
                LabelTempAdd.Content    = "C"; LabelTempAdd_Copy.Content = "C";

                LabelRealFeel.Content      = Properties.Resources.LabelRealFeel + " " + Convert.ToInt16(dW.DailyForecasts[0].RealFeelTemperature.Maximum.Value) + "°";
                LabelRealFeelShade.Content = Properties.Resources.LabelRealFeelShade + " " + Convert.ToInt16(dW.DailyForecasts[0].RealFeelTemperatureShade.Maximum.Value) + "°";
                LabelRealFeelMin.Content   = Properties.Resources.LabelRealFeel + " " + Convert.ToInt16(dW.DailyForecasts[0].RealFeelTemperature.Minimum.Value) + "°";

                LabelShortPhrase.Content = dW.DailyForecasts[0].Day.ShortPhrase;

                LabelIndex.Content   = Properties.Resources.LabelUVIndex;
                LabelUVIndex.Content = dW.DailyForecasts[0].AirAndPollen[5].Value + " "
                                       + Classes.UvIndex.UV_Category(dW.DailyForecasts[0].AirAndPollen[5].CategoryValue, dW.DailyForecasts[0].AirAndPollen[5].Category);

                LabelWind.Content      = Properties.Resources.LabelWind;
                LabelWindValue.Content = Classes.WindDirection.Wind_Direction(dW.DailyForecasts[0].Day.Wind.Direction.Degrees, dW.DailyForecasts[0].Day.Wind.Direction.Localized) + " " + Convert.ToInt16(dW.DailyForecasts[0].Day.Wind.Speed.Value) + " " +
                                         Classes.UnitTypes.UnitName(dW.DailyForecasts[0].Day.Wind.Speed.UnitType, dW.DailyForecasts[0].Day.Wind.Speed.Unit);

                LabelWindGust.Content      = Properties.Resources.LabelWindGust;
                LabelWindGustValue.Content = Convert.ToInt16(dW.DailyForecasts[0].Day.WindGust.Speed.Value) + " " +
                                             Classes.UnitTypes.UnitName(dW.DailyForecasts[0].Day.WindGust.Speed.UnitType, dW.DailyForecasts[0].Day.WindGust.Speed.Unit);

                LabelPrecipitationProbability.Content    = Properties.Resources.LabelPrecipitationProbability;
                LabelPrecipitationProbabilityVal.Content = dW.DailyForecasts[0].Day.PrecipitationProbability + " %";

                LabelThunderstormProbability.Content    = Properties.Resources.LabelThunderstormProbability;
                LabelThunderstormProbabilityVal.Content = dW.DailyForecasts[0].Day.ThunderstormProbability + " %";

                string liquidKind = "";
                if (dW.DailyForecasts[0].Day.TotalLiquid.Value > 0)
                {
                    liquidKind = "(" + Liquid.LiquidKind(dW.DailyForecasts[0].Day.Rain.Value, dW.DailyForecasts[0].Day.Snow.Value, dW.DailyForecasts[0].Day.Ice.Value) + ")";
                }
                LabelPrecipitation.Content         = Properties.Resources.LabelPrecipitation + " " + liquidKind;
                LabelTotalPrecipitationVal.Content = Convert.ToInt16(dW.DailyForecasts[0].Day.TotalLiquid.Value) + " " +
                                                     Classes.UnitTypes.UnitName(dW.DailyForecasts[0].Day.TotalLiquid.UnitType, dW.DailyForecasts[0].Day.TotalLiquid.Unit);

                LabelHoursPrecipitationVal.Content = dW.DailyForecasts[0].Day.HoursOfPrecipitation + UnitTypes.Hour();

                LabelVisibility.Content = aW.DailyForecasts[0].Day.CloudCover + " %";
            }
        }