private static void saveConfig(GeoLocation location) { System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(location.GetType()); using (var xml = new XmlTextWriter("config", Encoding.UTF8)) { s.Serialize(xml, location); } }
private void linkSetup_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { using (SetupForm f = new SetupForm()) { f.CurrentLocation = currentLocation; f.ShowDialog(); currentLocation = f.CurrentLocation; } renderWeather(Weather.Parse(getWeather(currentLocation))); }
private XDocument getWeather(GeoLocation currentLocation) { if (currentLocation == null) return null; try { XDocument xdoc = XDocument.Load(string.Format(WEATHERAPI, currentLocation.WOEID, currentLocation.Scale.ToString().ToLower() ) ); return xdoc; } catch (Exception ex) { return null; } }
private void lbLocations_SelectedIndexChanged(object sender, EventArgs e) { var o = lbLocations.SelectedItem; if (o is GeoLocation) { var location = (GeoLocation)o; Debug.WriteLine("Location: " + location.Name + " > WOEID: " + location.WOEID); //lblCurrentLocation.Text = location.ToString(); saveConfig(location); CurrentLocation = location; cbTempScale.SelectedItem = CurrentLocation.Scale; cbTempScale.Visible = true; //renderWeather(Weather.Parse(getWeather(currentLocation))); } }
private void loadConfig() { System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(typeof(GeoLocation)); try { using (var xml = new XmlTextReader("config")) { currentLocation = (GeoLocation)s.Deserialize(xml); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (currentLocation != null) { lblCurrentLocation.Text = currentLocation.ToString(); } }
private void renderTrayWeather(Weather weather, GeoLocation currentLocation) { notifyIconWeather.Text = weather.GetTemperature() + " - " + currentLocation.Name; notifyIconWeather.BalloonTipText = weather.ToString(); notifyIconWeather.BalloonTipTitle = "Weather"; notifyIconWeather.Icon = renderIcon(weather.Temperature); }