public async Task StartUpdate() { var ipChecker = IPCheckerHelper.CreateIPChecker(this.config.IPChecker); var dynDns53 = new DnsUpdater(route53Client); while (true) { try { logger.Info("Getting public IP..."); var ipAddress = await ipChecker.GetExternalIpAsync(); logger.Info($"Current public IP: {ipAddress}"); logger.Info("Updating DNS..."); await dynDns53.UpdateAllAsync(ipAddress, this.config.DomainList); logger.Info($"Update completed. Waiting for {this.config.UpdateInterval} seconds"); SendHeartbeat(); } catch (Exception ex) { logger.Error($"Exception: {ex.Message}"); } System.Threading.Thread.Sleep(this.config.UpdateInterval.Value * 1000); } }
public DynDns53Config GetConfig() { return(new DynDns53Config() { Route53AccessKey = config.AccessKey, Route53SecretKey = config.SecretKey, UpdateInterval = config.UpdateInterval.HasValue ? config.UpdateInterval.Value : 300, RunAtSystemStart = false, IPChecker = IPCheckerHelper.CreateIPChecker(config.IPChecker), DomainList = config.DomainList.ToList() }); }
public DynDns53Config GetConfig() { ConfigurationManager.RefreshSection("appSettings"); ConfigurationManager.RefreshSection("awsSettings"); ConfigurationManager.RefreshSection("domainSettings"); _config = new DynDns53Config(); string exeFile = System.Reflection.Assembly.GetCallingAssembly().Location; var configFile = ConfigurationManager.OpenExeConfiguration(exeFile); var awsConfigSection = configFile.GetSection("awsSettings"); _config.UpdateInterval = int.Parse(ConfigurationManager.AppSettings["UpdateInterval"]); _config.ClientId = ConfigurationManager.AppSettings["ClientId"]; _config.IPChecker = IPCheckerHelper.CreateIPChecker((IPChecker)Enum.Parse(typeof(IPChecker), ConfigurationManager.AppSettings["IPChecker"])); _config.Route53AccessKey = awsConfigSection.ElementInformation.Properties["route53AccessKey"].Value.ToString(); _config.Route53SecretKey = awsConfigSection.ElementInformation.Properties["route53SecretKey"].Value.ToString(); _config.RunAtSystemStart = bool.Parse(ConfigurationManager.AppSettings["RunAtSystemStart"]); _config.DomainList = new List <HostedDomainInfo>(); var domainConfigSection = configFile.GetSection("domainSettings") as DomainSettings; var domainList = domainConfigSection.ElementInformation.Properties; foreach (DomainElement domainInfo in DomainSettings.Settings.DomainList) { if (!string.IsNullOrEmpty(domainInfo.SubDomain) && !string.IsNullOrEmpty(domainInfo.ZoneId)) { _config.DomainList.Add(new HostedDomainInfo() { DomainName = domainInfo.SubDomain, ZoneId = domainInfo.ZoneId }); } } return(_config); }