void GetWeatherData(object parameter) { var data = DarkSkyWrapper.RequestDataFromApi(CurrentCity, CurrentLanguage, "ca"); if (data != null) { ActualData = data; Forecast.Clear(); int dateOffset = 0; foreach (Datum3 d in actualData.daily.data) { dateOffset++; Forecast.Add(new ForecastData { Temperature = d.temperatureHigh, Icon = d.icon, ApparentTemperature = d.apparentTemperatureHigh, Humidity = d.humidity, Pressure = d.pressure, WindSpeed = d.windSpeed, UvIndex = d.uvIndex, Date = DateTime.Today.AddDays(dateOffset).Day.ToString(), Month = DateTime.Today.AddDays(dateOffset).ToString("MMMM") }); } } else { ErrorMsg = Visibility.Visible; } }
async void Refresh() { try { Time = DateTime.Now.ToString("h:mm tt"); Day = DateTime.Now.ToString("dddd, MMMM d"); if (itr % 100 == 0) { TempNow = (await WeatherLib.WeatherAPI.GetCurrentTemperature("98004") + "°"); Conditions = await WeatherLib.WeatherAPI.GetCurrentConditions("98004"); WindSpeed = (await WeatherLib.WeatherAPI.GetWindSpeed("98004") + "mph"); Sunrise = (await WeatherLib.WeatherAPI.GetSunrise("98004")).ToString("h:mm tt"); Sunset = (await WeatherLib.WeatherAPI.GetSunset("98004")).ToString("h:mm tt"); Humidity = (await WeatherLib.WeatherAPI.GetHumidity("98004") + "%"); var f = await WeatherLib.WeatherAPI.GetForecast("98004"); Forecast.Clear(); foreach (var fx in f) { Forecast.Add(fx); } } //Webcam1 = "http://davux.gotdns.com:89/snapshot.cgi?user=admin&pwd=davehome&guid=" + Guid.NewGuid().ToString(); var pg = await DownloadPageAsync("http://localhost:9494"); XmlDocument x = new XmlDocument(); x.LoadXml(pg); //var x = await XmlDocument.LoadFromUriAsync(new Uri("http://localhost:9494")); CPU.Clear(); foreach (var cpu in x.GetElementsByTagName("cpu")) { CPU.Add(cpu.InnerText); } TotalCPU = x.GetElementsByTagName("allcpu")[0].InnerText + "%"; var m = x.GetElementsByTagName("memory")[0]; long total = long.Parse(m.Attributes.GetNamedItem("total").InnerText) / 1073741824; // # 1Gb long free = long.Parse(m.InnerText) / 1024; TotalMemory = total; UsedMemory = total - free; FreeMemory = free; Memory = string.Format("{0}Gb", free, total); } catch (Exception ex) { Debug.WriteLine(ex.Message); Day = ex.Message; } itr++; }
public async Task ExecuteGetWeatherCommand() { if (IsBusy) { return; } IsBusy = true; try { WeatherRoot weatherRoot = null; var units = IsImperial ? Units.Imperial : Units.Metric; if (UseGPS) { //var gps = await CrossGeolocator.Current.GetPositionAsync(1000); //var gps = await Geolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(10)); var gps = await Geolocation.GetLocationAsync(); weatherRoot = await WeatherService.GetWeather(gps.Latitude, gps.Longitude, units); } else { //Get weather by city weatherRoot = await WeatherService.GetWeather(Location.Trim(), units); } //await Task.Delay(500); //Get forecast based on cityId var fullForecast = await WeatherService.GetForecast(weatherRoot.CityId, units); Forecast.Clear(); foreach (var item in fullForecast.Items) { Forecast.Add(item); } var unit = IsImperial ? "F" : "C"; TempValue = weatherRoot?.MainWeather?.Temperature ?? 0; Humidity = weatherRoot?.MainWeather?.Humidity ?? 0; DisplayTemp = $"{weatherRoot?.MainWeather?.Temperature ?? 0}°{unit}"; Condition = $"{weatherRoot.Name}: {weatherRoot?.Weather?[0]?.Description ?? string.Empty}"; DisplayCity = weatherRoot?.Name; UpdateCalendar(); } catch (Exception ex) { DisplayTemp = "Unable to get Weather"; } finally { IsBusy = false; } }
public override void DisposeScreen() { if (AnimatedThreadWorker.IsBusy) { AnimatedThreadWorker.CancelAsync(); } AnimatedThreadWorker.DoWork -= AnimatedThreadWorkerDoWork; AnimatedThreadWorker.RunWorkerCompleted -= AnimatedThreadWorkerRunWorkerCompleted; AnimatedThreadWorker.Dispose(); _initialDirectiveArray.Clear(); _resultDirectiveArray.Clear(); _openPubWorkPackages.Clear(); _initialDirectiveArray = null; _resultDirectiveArray = null; _openPubWorkPackages = null; if (_currentForecast != null) { _currentForecast.Dispose(); _currentForecast = null; } if (_currentForecast != null) { _currentForecast.Clear(); } _currentForecast = null; if (_toolStripMenuItemOpen != null) { _toolStripMenuItemOpen.Dispose(); } if (_toolStripMenuItemHighlight != null) { foreach (var ttmi in _toolStripMenuItemHighlight.Items) { ttmi.Click -= HighlightItemClick; } _toolStripMenuItemHighlight.Items.Clear(); _toolStripMenuItemHighlight.Dispose(); } if (_toolStripSeparator1 != null) { _toolStripSeparator1.Dispose(); } if (_directivesViewer != null) { _directivesViewer.Dispose(); } Dispose(true); }
public override void DisposeScreen() { if (AnimatedThreadWorker.IsBusy) { AnimatedThreadWorker.CancelAsync(); } AnimatedThreadWorker.Dispose(); _resultDirectiveArray.Clear(); _preResultDirectiveArray.Clear(); _openPubWorkPackages.Clear(); _openPubQuotations.Clear(); //_deferredCategories.Clear(); _resultDirectiveArray = null; _preResultDirectiveArray = null; _openPubWorkPackages = null; _openPubQuotations = null; //_deferredCategories = null; if (_currentForecast != null) { _currentForecast.Dispose(); _currentForecast = null; } if (_initialFilter != null) { _initialFilter.Filters.Clear(); _initialFilter = null; } if (_currentForecast != null) { _currentForecast.Clear(); } _currentForecast = null; if (_directivesViewer != null) { _directivesViewer.Dispose(); } Dispose(true); }
private void RefreshWeatherUI(GenericWeather weather) { WeatherProviderString = weather.Source ?? Common.GetLocalizedText("NotAvailable"); CurrentTemperature = GetCurrentTemperatureString(weather); CurrentAdditionalInfo = weather.CurrentObservation.AdditionalInfo; CurrentWeatherIcon = weather.CurrentObservation.Icon; CurrentWeather = weather.CurrentObservation.WeatherDescription; Forecast.Clear(); for (int i = 0; i < 5 && i < _weather.Forecast.Days.Length; ++i) { Forecast.Add(new ForecastDay { Day = _weather.Forecast.Days[i].DayOfWeek, TempF = _weather.Forecast.Days[i].TemperatureFahrenheit, TempC = _weather.Forecast.Days[i].TemperatureCelsius, Icon = _weather.Forecast.Days[i].WeatherIcon, Desc = _weather.Forecast.Days[i].WeatherDescription, }); } }