示例#1
0
        private async void LoadWeatherData(object sender, RoutedEventArgs e)
        {
            string           selectedCity = SelectedCity.Text;
            string           responseXML;
            WeatherDataEntry result;


            while (true)
            {
                responseXML = await APIConnection.LoadDataAsync(selectedCity);

                using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(responseXML)))
                {
                    result = ParseWeather_LINQ.Parse(stream);
                    var newEntry = new Pogoda();
                    newEntry.Miasto = result.City;
                    if (HumidityCheck.IsChecked == true)
                    {
                        newEntry.Wiatr = result.Humidity.ToString();
                    }
                    if (TempratureCheck.IsChecked == true)
                    {
                        newEntry.Temperatura = KelvinToCelsius.KelvToCel(result.Temperature);
                    }
                    if (PressureCheck.IsChecked == true)
                    {
                        newEntry.Ciśnienie = result.Pressure.ToString();
                    }

                    db.Pogoda.Add(newEntry);
                    db.SaveChanges();
                    if (worker.IsBusy != true)
                    {
                        worker.RunWorkerAsync();
                    }
                }
                await Task.Delay(3000);
            }
        }
示例#2
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            string           selectedCity = CityTextBox.Text;
            string           responseXML;
            WeatherDataEntry result;

            responseXML = await APIConnection.LoadDataAsync(CityTextBox.Text);

            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(responseXML)))
            {
                result = ParseWeather_LINQ.Parse(stream);
                var newEntry = new Pogoda();
                newEntry.Miasto = result.City;
                if (HumidityCheck.IsChecked == true)
                {
                    newEntry.Wiatr = result.Humidity.ToString();
                }
                if (TempratureCheck.IsChecked == true)
                {
                    newEntry.Temperatura = KelvinToCelsius.KelvToCel(result.Temperature);
                }
                if (PressureCheck.IsChecked == true)
                {
                    newEntry.Ciśnienie = result.Pressure.ToString();
                }
                db.Pogoda.Add(newEntry);
                db.SaveChanges();
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    db.Pogoda.Local.Remove(newEntry);
                    Debug.WriteLine("Error, id is not unique!");
                }
            }
        }