private void Update()
    {
        UpdateMotor();

        WindForce     = force.GetWindForce();
        WindDirection = direction.GetWindDirection();
    }
Beispiel #2
0
        public async Task LoadWeatherForModels(ObservableCollection <CityTableCellViewModel> citiesModels)
        {
            using (var httpClient = new HttpClient())
            {
                foreach (var cityModel in citiesModels)
                {
                    try
                    {
                        string url  = UrlResolver.ResolveWeatherApiUrl(cityModel.WeatherId);
                        string json = await httpClient.GetStringAsync(url);

                        var data         = JObject.Parse(json);
                        int temp         = data["main"]["temp"].Value <int>();
                        var selectedCity = Cities.First((item) => item.WeatherId == cityModel.WeatherId);
                        selectedCity.CurrentWeather = Convert.ToString(temp) + " °C";
                        selectedCity.WindDegree     = data["wind"]["deg"].Value <int>();
                        cityModel.Weather           = selectedCity.CurrentWeather;
                        var wind = WindDirection.GetWindDirection(selectedCity.WindDegree);
                        cityModel.WindDirectionImageSource = WindDirection.GetWindImageDirection(wind);
                        cityModel.UpdateWeather();
                    }
                    catch
                    {
                        if (cityModel.WindDirectionImageSource == null)
                        {
                            cityModel.WindDirectionImageSource = WindDirection.GetNotLoadedImageDirection();
                            cityModel.UpdateWeather();
                        }
                    }
                }
            }
            WeatherUpdated(this, new EventArgs());
        }
Beispiel #3
0
        public void TestNorth()
        {
            string isNorth = WindDirection.GetWindDirection(0);

            Assert.IsTrue(isNorth == "N");
            string isN = WindDirection.GetWindDirection(360);

            Assert.IsTrue(isN == "N");
        }
        // Uses the API class to get the current weather data
        private async void GetCurrentWeather()
        {
            try
            {
                WeatherAPI weatherApi = new WeatherAPI();
                await weatherApi.GetCurrentWeatherAPI(cityName, unit);

                var data = JsonConvert.DeserializeObject <WeatherData>(weatherApi.responseString);

                int    curTemp = (int)data.Main.Temp;
                int    curMax  = (int)data.Main.Temp_Max;
                int    curMin  = (int)data.Main.Temp_Min;
                int    curHum  = data.Main.Humidity;
                int    windDeg = data.Wind.Deg;
                double speed   = data.Wind.Speed;

                temp.Text          = curTemp.ToString() + "°";
                maxTemp.Text       = curMax.ToString() + "°";
                minTemp.Text       = curMin.ToString() + "°";
                humidity.Text      = curHum.ToString() + "%";
                windSpeed.Text     = speed.ToString();
                windDirection.Text = WindDirection.GetWindDirection(windDeg);
                desc.Text          = data.Weather[0].Description.ToUpper();
                UpdateWeatherIcon();
                now = DateTime.Now;
                LoggingService.Instance.LogSuccess(now, "Connected to API");
            }
            catch
            {
                now = DateTime.Now;
                LoggingService.Instance.LogCatastrophicError(now, "Can't connect to API!");
                ContentDialog noConnection = new ContentDialog
                {
                    Title           = "Can't Connect to API",
                    Content         = "Check your connection and try again.",
                    CloseButtonText = "Ok"
                };
                ContentDialogResult result = await noConnection.ShowAsync();
            }
        }
Beispiel #5
0
        public void TestWNW()
        {
            string isWNW = WindDirection.GetWindDirection(314);

            Assert.IsTrue(isWNW == "WNW");
        }
Beispiel #6
0
        public void TestWSW()
        {
            string isWSW = WindDirection.GetWindDirection(269);

            Assert.IsTrue(isWSW == "WSW");
        }
Beispiel #7
0
        public void TestWest()
        {
            string isWest = WindDirection.GetWindDirection(270);

            Assert.IsTrue(isWest == "W");
        }
Beispiel #8
0
        public void TestSSW()
        {
            string isSSW = WindDirection.GetWindDirection(181);

            Assert.IsTrue(isSSW == "SSW");
        }
Beispiel #9
0
        public void TestSouth()
        {
            string isSouth = WindDirection.GetWindDirection(180);

            Assert.IsTrue(isSouth == "S");
        }
Beispiel #10
0
        public void TestSSE()
        {
            string isSSE = WindDirection.GetWindDirection(136);

            Assert.IsTrue(isSSE == "SSE");
        }
Beispiel #11
0
        public void TestNE()
        {
            string isNE = WindDirection.GetWindDirection(45);

            Assert.IsTrue(isNE == "NE");
        }