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!");
                    }
                }
            }
        }
Exemple #2
0
            public async Task SendIp([Remainder] string serverName = "minecraft server")
            {
                // Check to make sure that the desired server actually exists.
                List <string> serverNames = Data.Data.GetServerProcessNames();

                if (!Data.Data.GetServerProcessNames().Contains(serverName))
                {
                    await Context.Channel.SendMessageAsync($"{serverName} is not an existing server!\nExisting servers are:\n\t{string.Join("\n\t", serverNames.ToArray())}");

                    return;
                }

                try {
                    string externalIp = new System.Net.WebClient().DownloadString("http://icanhazip.com");
                    await Context.User.SendMessageAsync($"The server IP address for {serverName} is {externalIp.TrimEnd()}:{Data.Data.GetServerPort(serverName)}");
                } catch (Exception e) {
                    Console.WriteLine(e);
                    throw;
                }
            }