Exemplo n.º 1
0
        //Текущая погода
        private async void CurrentWeather()
        {
            LabelHeadingPage.Content = Properties.Resources.LabelHeadingPageCurrentConditions;

            //String url = $"http://dataservice.accuweather.com/currentconditions/v1/{geoKey}?apikey=9pbmpNTkGYJTGy8sKGDxiIy8ADvYjqIl&language=ru-ru&details=true";
            string url = $"http://dataservice.accuweather.com/currentconditions/v1/{geoKey}?apikey=9pbmpNTkGYJTGy8sKGDxiIy8ADvYjqIl&language={Classes.Language.nameLanguage}&details=true";
            //String url = $"http://dataservice.accuweather.com/currentconditions/v1/{geoKey}?apikey=9pbmpNTkGYJTGy8sKGDxiIy8ADvYjqIl&details=true";

            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;

                List <CurrentWeather.Class1> cW = JsonConvert.DeserializeObject <List <CurrentWeather.Class1> >(answer);

                //Вывод даты и дня недели
                //LabelDT.Content = (Classes.DateTimeConverting.dayOfWeek(cW[0].EpochTime) + ", " + Classes.DateTimeConverting.dayOfMonth(cW[0].EpochTime)).ToUpper();
                //LabelDateTime.Content = Classes.DateTimeConverting.timeOfDay(cW[0].EpochTime);

                DateTimeConverting myDateTime = new DateTimeConverting(cW[0].EpochTime);
                LabelDT.Content       = (myDateTime.dayOfWeek + ", " + myDateTime.dayOfMonth).ToUpper();
                LabelDateTime.Content = myDateTime.timeOfDay();

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

                LabelTemp.Content    = cW[0].Temperature.Metric.value;
                LabelTempAdd.Content = cW[0].Temperature.Metric.Unit;

                LabelRealFeel.Content      = Properties.Resources.LabelRealFeel + " " + cW[0].RealFeelTemperature.Metric.value;
                LabelRealFeelShade.Content = Properties.Resources.LabelRealFeelShade + " " + cW[0].RealFeelTemperatureShade.Metric.value;

                LabelShortPhrase.Content = cW[0].WeatherText;

                LabelIndex.Content   = Properties.Resources.LabelUVIndex;
                LabelUVIndex.Content = Classes.UvIndex.UV_Category(Convert.ToInt16(cW[0].UVIndex / 2), cW[0].UVIndexText) + " " + cW[0].UVIndex;

                LabelWind.Content      = Properties.Resources.LabelWind;
                LabelWindValue.Content = Classes.WindSpeed.Power(cW[0].Wind.Speed.Metric.Value) + " " + cW[0].Wind.Direction.Localized + " " + Convert.ToInt16(cW[0].Wind.Speed.Metric.Value) + " " + Classes.UnitTypes.UnitName(cW[0].Wind.Speed.Metric.UnitType, cW[0].Wind.Speed.Metric.Unit);
                LabelWindGust.Content  = Classes.WindSpeed.Power(cW[0].WindGust.Speed.Metric.Value) + " " + Convert.ToInt16(cW[0].WindGust.Speed.Metric.Value) + " " + Classes.UnitTypes.UnitName(cW[0].WindGust.Speed.Metric.UnitType, cW[0].WindGust.Speed.Metric.Unit);
                LabelHumidity.Content  = cW[0].RelativeHumidity + " %";
                LabelDewPoint.Content  = Convert.ToInt16(cW[0].DewPoint.Metric.Value) + "°" + cW[0].DewPoint.Metric.unit;

                LabelPressure.Content   = Classes.Pressure.Tendency(cW[0].PressureTendency.Code) + " " + Classes.Pressure.PressureUnitRu(cW[0].Pressure.Metric.UnitType, cW[0].Pressure.Metric.Unit, cW[0].Pressure.Metric.Value);
                LabelCloudCover.Content = cW[0].CloudCover + " %";
                LabelVisibility.Content = Convert.ToInt16(cW[0].Visibility.Metric.Value) + " " + Classes.Distance.DistanceRu(cW[0].Visibility.Metric.Unit, cW[0].Visibility.Metric.UnitType);
                LabelCeiling.Content    = Convert.ToInt16(cW[0].Ceiling.Metric.Value / 100) * 100 + " " + Classes.Distance.DistanceRu(cW[0].Ceiling.Metric.Unit, cW[0].Ceiling.Metric.UnitType);
            }
        }
Exemplo n.º 2
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 + " %";
            }
        }