Ejemplo n.º 1
0
        public static async Task RunWeatherServiceGetWeatherFromLatLngAsync()
        {
            ForecastIO forecast = await ForecastIOService.GetWeatherFromLatLng("51.039889", "3.725620");

            Console.WriteLine("####################################################################");
            Console.WriteLine("##                           Weather App                          ##");
            Console.WriteLine("## -------------------------------------------------------------- ##");
            Console.WriteLine("## Data from Forecast.io Service                                  ##");
            Console.WriteLine("## Developed by Philippe De Pauw - Waterschoot (drdynscript)      ##");
            Console.WriteLine("## Arteveldehogeschool                                            ##");
            Console.WriteLine("####################################################################");
            //Console.BackgroundColor = ConsoleColor.Blue;
            //Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(String.Format("Weathersituation: {0}", forecast.Now.Summary));
            Console.WriteLine(String.Format("Current temperature: {0} °C, feels like {1} °C", forecast.Now.Temperature, forecast.Now.ApparentTemperature));
            Console.WriteLine(String.Format("Cloud cover: {0} %", forecast.Now.CloudCover));
            Console.WriteLine(String.Format("Humidity: {0}", forecast.Now.Humidity));
            Console.WriteLine(String.Format("Wind speed: {0} m/s", forecast.Now.WindSpeed));
            Console.WriteLine(String.Format("Wind direction: {0}", GetDirectionFromDegrees(forecast.Now.WindBearing)));
            Console.WriteLine(String.Format("Precip intensity: {0} mm/h", forecast.Now.PrecipIntensity));
            Console.WriteLine(String.Format("Precip probability: {0} %", forecast.Now.PrecipProbability));
            Console.WriteLine(String.Format("Pressure: {0} hPa", forecast.Now.Pressure));
            Console.WriteLine(String.Format("Dewpoint: {0} °C", forecast.Now.DewPoint));
            Console.WriteLine(String.Format("Ozon: {0}", forecast.Now.Ozone));
            Console.WriteLine(String.Format("Nearest storm distance: {0} km", forecast.Now.NearestStormDistance));
            Console.WriteLine(String.Format("Nearest storm direction: {0}", GetDirectionFromDegrees(forecast.Now.NearestStormBearing)));
            //Console.ResetColor();
            Console.WriteLine("####################################################################");
        }
Ejemplo n.º 2
0
 public WeatherModel(ForecastIO.ForecastIOResponse forecast)
 {
     this.currentWeather = new Current(forecast);
     this.day0 = new Daily(forecast, 0);
     this.day1 = new Daily(forecast, 1);
     this.day2 = new Daily(forecast, 2);
 }
        public static async Task <ForecastIO> GetWeatherFromLatLng(string lat, string lng)
        {
            string url = String.Format(ForecastIOService.RESTURL, ForecastIOService.KEY, lat, lng, "si");

            using (var handler = new HttpClientHandler())
            {
                handler.AllowAutoRedirect = false;
                //handler.ServerCertificateCustomValidationCallback = (msg, cert, chain, errors) => true;

                using (var client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");

                    HttpResponseMessage response = await client.GetAsync(url);

                    if (response.IsSuccessStatusCode)
                    {
                        var result = await response.Content.ReadAsStringAsync();

                        var        serializer = new DataContractJsonSerializer(typeof(ForecastIO));
                        var        ms         = new MemoryStream(Encoding.UTF8.GetBytes(result));
                        ForecastIO forecast   = (ForecastIO)serializer.ReadObject(ms);

                        return(forecast);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
            public int windSpeed; // Wind speed in mph

            #endregion Fields

            #region Constructors

            public Current(ForecastIO.ForecastIOResponse forecast)
            {
                this.apparentTemperature = forecast.currently.apparentTemperature;
                this.cloudCover = Convert.ToInt32(forecast.currently.cloudCover * 100);
                this.dewPoint = forecast.currently.dewPoint;
                this.humidity = Convert.ToInt32(forecast.currently.humidity * 100);
                this.icon = forecast.currently.icon;
                this.nearestStormBearing = Convert.ToInt32(forecast.currently.nearestStormBearing);
                this.nearestStormDistance = Convert.ToInt32(forecast.currently.nearestStormDistance);
                this.ozone = forecast.currently.ozone;
                this.precipIntensity = forecast.currently.precipIntensity;
                this.precipProbablity = Convert.ToInt32(forecast.currently.precipProbability);
                this.pressure = forecast.currently.pressure;
                this.summary = forecast.currently.summary;
                this.temperature = forecast.currently.temperature;
                this.visibility = forecast.currently.visibility;
                this.windBearing = Convert.ToInt32(forecast.currently.windBearing);
                this.windSpeed = Convert.ToInt32(forecast.currently.windSpeed);

                DateTime UnixTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                this.time = UnixTime.AddSeconds(forecast.currently.time);
            }
Ejemplo n.º 5
0
            public int windSpeed; // Wind speed in mph

            #endregion Fields

            #region Constructors

            public Daily(ForecastIO.ForecastIOResponse forecast, int index)
            {
                this.apparentTemperatureMax = forecast.daily.data[index].apparentTemperatureMax;
                this.apparentTemperatureMin = forecast.daily.data[index].apparentTemperatureMin;
                this.apparentTemperatureMaxTime = forecast.daily.data[index].apparentTemperatureMaxTime;
                this.apparentTemperatureMinTime = forecast.daily.data[index].apparentTemperatureMinTime;
                this.cloudCover = Convert.ToInt32(forecast.daily.data[index].cloudCover * 100);
                this.dewPoint = forecast.daily.data[index].dewPoint;
                this.humidity = Convert.ToInt32(forecast.daily.data[index].humidity * 100);
                this.icon = forecast.daily.data[index].icon;
                this.moonPhase = forecast.daily.data[index].moonPhase;
                this.ozone = forecast.daily.data[index].ozone;
                this.precipIntensity = forecast.daily.data[index].precipIntensity;
                this.precipIntensityMax = forecast.daily.data[index].precipIntensityMax;
                this.precipProbablity = Convert.ToInt32(forecast.daily.data[index].precipProbability);
                this.pressure = forecast.daily.data[index].pressure;
                this.summary = forecast.daily.data[index].summary;
                this.temperatureMax = forecast.daily.data[index].temperatureMax;
                this.temperatureMin = forecast.daily.data[index].temperatureMin;
                this.visibility = forecast.daily.data[index].visibility;
                this.windBearing = Convert.ToInt32(forecast.daily.data[index].windBearing);
                this.windSpeed = Convert.ToInt32(forecast.daily.data[index].windSpeed);

                DateTime UnixTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                this.time = UnixTime.AddSeconds(forecast.daily.data[index].time);
                this.SunriseTime = UnixTime.AddSeconds(forecast.daily.data[index].sunriseTime);
                this.SunsetTime = UnixTime.AddSeconds(forecast.daily.data[index].sunsetTime);
                this.temperatureMaxTime = UnixTime.AddSeconds(forecast.daily.data[index].temperatureMaxTime);
                this.temperatureMinTime = UnixTime.AddSeconds(forecast.daily.data[index].temperatureMinTime);
            }
Ejemplo n.º 6
0
        public async Task GetWeatherFromLocation()
        {
            ForecastIO forecast = await ForecastIOService.GetWeatherFromLatLng("51.039889", "3.725620");

            Assert.NotNull(forecast);
        }