public ClockModel() { _weatherClockTimeFormat = Configuration.Instance.ClockTimeFormat.GetValueOrDefault(ClockTimeFormat.Hours12); // // Set up our clock refresh timer. The timer itself // is also a ModelItem. This clock is the "owner" of // the Timer. So, when this clock is disposed, all // its owned objects will be disposed automatically. // _timer = new Timer(this); _timer.Interval = 1000; // 1 second refresh interval _timer.Tick += delegate { UpdateTime(); }; _timer.Enabled = true; UpdateTime(); }
public WeatherModel() { if (Configuration.Instance.IsValid() == true) { _weatherApiKey = Configuration.Instance.ApiKey; _weatherLocationCode = Configuration.Instance.LocationCode; _weatherUnit = Configuration.Instance.WeatherUnit.GetValueOrDefault(WeatherUnit.Imperial); _weatherClockTimeFormat = Configuration.Instance.ClockTimeFormat.GetValueOrDefault(ClockTimeFormat.Hours12); _weatherRefreshRateInMinutes = Configuration.Instance.RefreshRateInMinutes.GetValueOrDefault(10); _weatherLanguage = Configuration.Instance.Language.GetValueOrDefault(Language.EN); } // set the correct language for the UI thread System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(Enum.GetName(typeof(Language), Configuration.Instance.Language)); _weatherFileName = String.Format(Configuration.Instance.WeatherFileNamePattern, _weatherLocationCode, _weatherLanguage); _weatherFileName = _weatherFileName.Replace(":", "."); // small cleanup is needed for zmw location codes _weatherFileLocation = Path.Combine(Configuration.Instance.ConfigFileFolder, _weatherFileName); _weatherApiAddress = String.Format(Configuration.Instance.ApiUrlPattern, _weatherApiKey, _weatherLanguage, _weatherLocationCode); _xmlWeatherData = new XmlDocument(); _dailyForecast = new ArrayListDataSet(); _hourlyForecast = new ArrayListDataSet(); _uiRefreshNeeded = true; _isLoaded = false; // refresh timer if (_weatherRefreshTimer == null) { _weatherRefreshTimer = new Timer(this); _weatherRefreshTimer.Interval = 10000; // 10 seconds interval _weatherRefreshTimer.Tick += delegate { LoadWeatherData(); }; } }