private void checkForUpdate(String localVersion) { if (System.Diagnostics.Debugger.IsAttached && File.Exists(tzdbFilename)) { return; } log.Debug("Checking for new timezone database..."); String nodatimeURL = "http://nodatime.org/tzdb/latest.txt"; String html = ""; try { html = new System.Net.WebClient().DownloadString(nodatimeURL); } catch (System.Exception ex) { log.Error("Failed to get latest NodaTime db version."); OGCSexception.Analyse(ex); return; } if (string.IsNullOrEmpty(html)) { log.Warn("Empty response from " + nodatimeURL); } else { html = html.TrimEnd('\r', '\n'); if (html.EndsWith(localVersion + ".nzd")) { log.Debug("Already have latest TZDB version."); } else { Regex rgx = new Regex(@"https*:.*/tzdb(.*)\.nzd$", RegexOptions.IgnoreCase); MatchCollection matches = rgx.Matches(html); if (matches.Count > 0) { String remoteVersion = matches[0].Result("$1"); if (string.Compare(localVersion, remoteVersion, System.StringComparison.InvariantCultureIgnoreCase) < 0) { log.Debug("There is a new version " + remoteVersion); try { new System.Net.WebClient().DownloadFile(html, tzdbFilename); log.Debug("New version downloaded - disposing of reference to old db data."); instance = null; } catch (System.Exception ex) { log.Error("Failed to download new database from " + html); OGCSexception.Analyse(ex); } } } else { log.Warn("Regex to extract latest version is no longer working!"); } } } }