Ejemplo n.º 1
0
        public void showDetails(clsForecast forecast)
        {
            imgSunrise.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/weather-icons/sunrise.png"));
            imgSunset.Source  = new BitmapImage(new Uri("pack://application:,,,/Resources/weather-icons/sunset.png"));

            this.Title         = "Forecast details for " + forecast.getSetLongDate;
            lblDate.Content    = forecast.getSetLongDate;
            lblSummary.Content = forecast.getSetSummary;

            /*while (lblSummary.Width < System.Windows.Forms.TextRenderer.MeasureText(lblSummary.Text,
             *  new Font(lblSummary.Font.FontFamily, lblSummary.Font.Size, lblSummary.Font.Style)).Width)
             * {
             * lblSummary.Font = new Font(lblSummary.Font.FontFamily, lblSummary.Font.Size - 0.5f, lblSummary.Font.Style);
             * }*/

            imgIcon.Source = new BitmapImage(forecast.getIcon());

            lblSunrise.Content = "Sunrise: " + forecast.getSetSunrise;
            lblSunset.Content  = "Sunset: " + forecast.getSetSunset;

            imgMoonPhase.Source  = new BitmapImage(forecast.getMoonPhase());
            lblMoonPhase.Content = "Phase: " + forecast.getSetMoonPhaseString;

            lblPrecipIntensity.Content    = "Intensity: " + forecast.getSetPrecipIntensity + " inches/hour";
            lblPrecipIntensityMax.Content = "Max Intensity: " + forecast.getSetPrecipIntensityMax + " inches";
            lblPrecipProbability.Content  = "Probability: " + forecast.getSetPrecipProbability + "%";
            lblPrecipType.Content         = "Type: " + forecast.getSetPrecipType;
            lblPrecipAccumulation.Content = "Accumulation: " + forecast.getSetPrecipAccumulation + " inches";

            lblHigh.Content     = "High: " + forecast.getSetHigh + "\u00B0" + forecast.Units;
            lblHighTime.Content = "High Time: " + forecast.getSetHighTime;
            lblLow.Content      = "Low: " + forecast.getSetLow + "\u00B0" + forecast.Units;
            lblLowTime.Content  = "Low Time: " + forecast.getSetLowTime;

            lblFeelsHigh.Content     = "High: " + forecast.getSetFeelsHigh + "\u00B0" + forecast.Units;
            lblFeelsHighTime.Content = "High Time: " + forecast.getSetFeelsHighTime;
            lblFeelsLow.Content      = "Low: " + forecast.getSetFeelsLow + "\u00B0" + forecast.Units;
            lblFeelsLowTime.Content  = "Low Time: " + forecast.getSetFeelsLowTime;

            lblWindSpeed.Content   = "Speed: " + forecast.getSetWindSpeed + " miles/hour";
            lblWindBearing.Content = "Bearing: " + forecast.getSetWindBearing + "\u00B0";
            imgWindBearing.Source  = new BitmapImage(forecast.getWindBearing());

            if (forecast.getSetVisibility == 11)
            {
                lblVisibility.Content = "Visibility: 10+ miles";
            }
            else
            {
                lblVisibility.Content = "Visibility: " + forecast.getSetVisibility + " miles";
            }
            lblCloudCover.Content = "Cloud Cover: " + forecast.getSetCloudCover + "%";

            lblDewPoint.Content = "Dew Point: " + forecast.getSetDewPoint + "\u00B0" + forecast.Units;
            lblHumidity.Content = "Humidity: " + forecast.getSetHumidity + "%";
            lblPressure.Content = "Pressure: " + forecast.getSetPressure + " millibars";
            lblOzone.Content    = "Ozone: " + forecast.getSetOzone;

            this.Show();
        }
Ejemplo n.º 2
0
        public void showAlerts(clsForecast forecast)
        {
            lblAlertTitle.Content  = forecast.getSetAlertTitle;
            lblAlertTime.Content   = "Alert time: " + forecast.getSetAlertTime;
            lblAlertExpire.Content = "Alert expires: " + forecast.getSetAlertExpire;

            string formattedDescription = forecast.getSetAlertDescription.Replace("\r\n", Environment.NewLine).Replace("\n", Environment.NewLine).Replace("\r", Environment.NewLine);

            txtDescription.Text = formattedDescription;

            lblAlertURL.Focus();

            alertURL = forecast.getSetAlertURL;

            this.Show();
        }
Ejemplo n.º 3
0
        public void showDetails(clsForecast forecast)
        {
            this.Title         = "Forecast details for " + forecast.getSetLongDate;
            lblDate.Content    = forecast.getSetLongDate;
            lblSummary.Content = forecast.getSetSummary;

            imgIcon.Source = new BitmapImage(forecast.getIcon());

            lblPrecipIntensity.Content   = "Intensity: " + forecast.getSetPrecipIntensity + " inches/hour";
            lblPrecipProbability.Content = "Probability: " + forecast.getSetPrecipProbability + "%";
            lblPrecipType.Content        = "Type: " + forecast.getSetPrecipType;

            lblCurrentTemp.Content      = "Temp: " + forecast.getSetTemp + "\u00B0" + forecast.Units;
            lblCurrentFeelsTemp.Content = "Temp: " + forecast.getSetFeelsLike + "\u00B0" + forecast.Units;

            lblWindSpeed.Content   = "Speed: " + forecast.getSetWindSpeed + " miles/hour";
            lblWindBearing.Content = "Bearing: " + forecast.getSetWindBearing + "\u00B0";
            imgWindBearing.Source  = new BitmapImage(forecast.getWindBearing());

            if (forecast.getSetVisibility == 11)
            {
                lblVisibility.Content = "Visibility: 10+ miles";
            }
            else
            {
                lblVisibility.Content = "Visibility: " + forecast.getSetVisibility + " miles";
            }
            lblCloudCover.Content = "Cloud Cover: " + forecast.getSetCloudCover + "%";

            lblDewPoint.Content = "Dew Point: " + forecast.getSetDewPoint + "\u00B0" + forecast.Units;
            lblHumidity.Content = "Humidity: " + forecast.getSetHumidity + "%";
            lblPressure.Content = "Pressure: " + forecast.getSetPressure + " millibars";
            lblOzone.Content    = "Ozone: " + forecast.getSetOzone;

            this.Show();
        }
Ejemplo n.º 4
0
        public clsForecast[] getForecast(clsForecast[] forecast)
        {
            // API Key, Lat, Long, Unit

            string url = "https://api.forecast.io/forecast/" + API_KEY + "/" + flat + "," + flon;
            //var request = new ForecastIORequest(API_KEY, flat, flon, Unit.auto);
            var           response = new WebClient().DownloadData(url);
            UTF32Encoding utf32    = new UTF32Encoding();

            byte[]  utf32Array  = Encoding.Convert(Encoding.UTF8, Encoding.UTF32, response);
            string  finalString = utf32.GetString(utf32Array);
            dynamic weatherData = JObject.Parse(finalString.ToString());

            //var response = request.Get();

            for (int i = 0; i < 7; i++)
            {
                clsForecast tempForecast = new clsForecast();
                tempForecast.getSetDate     = (string)weatherData.daily.data[i].time.ToString();
                tempForecast.getSetLongDate = (string)weatherData.daily.data[i].time.ToString();
                tempForecast.getSetDay      = (string)weatherData.daily.data[i].time;
                tempForecast.getSetSummary  = (string)weatherData.daily.data[i].summary;
                tempForecast.setIcon((string)weatherData.daily.data[i].icon);
                tempForecast.getSetSunrise = (string)weatherData.daily.data[i].sunriseTime.ToString();
                tempForecast.getSetSunset  = (string)weatherData.daily.data[i].sunsetTime.ToString();
                tempForecast.setMoonPhase((float)weatherData.daily.data[i].moonPhase);
                tempForecast.getSetPrecipIntensity    = (float)weatherData.daily.data[i].precipIntensity;
                tempForecast.getSetPrecipIntensityMax = (float)weatherData.daily.data[i].precipIntensityMax;
                tempForecast.getSetPrecipProbability  = (float)weatherData.daily.data[i].precipProbability;
                tempForecast.getSetPrecipType         = (string)weatherData.daily.data[i].precipType;
                tempForecast.getSetLow           = (float)weatherData.daily.data[i].temperatureMin;
                tempForecast.getSetLowTime       = (string)weatherData.daily.data[i].temperatureMinTime.ToString();
                tempForecast.getSetHigh          = (float)weatherData.daily.data[i].temperatureMax;
                tempForecast.getSetHighTime      = (string)weatherData.daily.data[i].temperatureMaxTime.ToString();
                tempForecast.getSetFeelsLow      = (float)weatherData.daily.data[i].apparentTemperatureMin;
                tempForecast.getSetFeelsLowTime  = (string)weatherData.daily.data[i].apparentTemperatureMinTime.ToString();
                tempForecast.getSetFeelsHigh     = (float)weatherData.daily.data[i].apparentTemperatureMax;
                tempForecast.getSetFeelsHighTime = (string)weatherData.daily.data[i].apparentTemperatureMaxTime.ToString();
                tempForecast.getSetDewPoint      = (float)weatherData.daily.data[i].dewPoint;
                tempForecast.getSetHumidity      = (float)weatherData.daily.data[i].humidity;
                tempForecast.getSetWindSpeed     = (float)weatherData.daily.data[i].windSpeed;

                if (weatherData.daily.data[i].windBearing == null)
                {
                    tempForecast.getSetWindBearing = 0;
                }
                else
                {
                    tempForecast.getSetWindBearing = (int)weatherData.daily.data[i].windBearing;
                }

                if (weatherData.daily.data[i].visibility == null)
                {
                    tempForecast.getSetVisibility = 11;
                }
                else
                {
                    tempForecast.getSetVisibility = (float)weatherData.daily.data[i].visibility;
                }
                tempForecast.getSetCloudCover = (float)weatherData.daily.data[i].cloudCover;
                tempForecast.getSetPressure   = (float)weatherData.daily.data[i].pressure;
                tempForecast.getSetOzone      = (float)weatherData.daily.data[i].ozone;

                tempForecast.Units = (string)weatherData.flags.units;

                forecast[i] = tempForecast;
            }

            current.getSetDate     = (string)weatherData.currently.time;
            current.getSetLongDate = (string)weatherData.currently.time;
            current.getSetDay      = (string)weatherData.currently.time;
            current.getSetSummary  = (string)weatherData.currently.summary;
            current.setIcon((string)weatherData.currently.icon);
            current.getSetPrecipIntensity   = (float)weatherData.currently.precipIntensity;
            current.getSetPrecipProbability = (float)weatherData.currently.precipProbability;
            current.getSetPrecipType        = (string)weatherData.currently.precipType;
            current.getSetTemp        = (float)weatherData.currently.temperature;
            current.getSetFeelsLike   = (float)weatherData.currently.apparentTemperature;
            current.getSetDewPoint    = (float)weatherData.currently.dewPoint;
            current.getSetHumidity    = (float)weatherData.currently.humidity;
            current.getSetWindSpeed   = (float)weatherData.currently.windSpeed;
            current.getSetWindBearing = (int)weatherData.currently.windBearing;
            current.getSetVisibility  = (int)weatherData.currently.visibility;
            current.getSetCloudCover  = (float)weatherData.currently.cloudCover;
            current.getSetPressure    = (float)weatherData.currently.pressure;
            current.getSetOzone       = (float)weatherData.currently.ozone;

            try
            {
                current.getSetAlertTitle       = (string)weatherData.alerts[0].title;
                current.getSetAlertTime        = (string)weatherData.alerts[0].time;
                current.getSetAlertExpire      = (string)weatherData.alerts[0].expires;
                current.getSetAlertDescription = (string)weatherData.alerts[0].description;
                current.getSetAlertURL         = (string)weatherData.alerts[0].uri;
            }
            catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
            {
                // This section intentionally blank, this failure is expected and is okay.
            }

            current.Units = (string)weatherData.flags.units;

            forecast[9] = current;
            return(forecast);
        }