Esempio n. 1
0
        static void Main(string[] args)
        {
            IConfigHandler _configHandler = new AppConfigHandler();
            var config = _configHandler.GetConfig();
            IIpChecker _ipChecker = new AwsIpChecker();
            IAmazonRoute53 _amazonClient = new AmazonRoute53Client(config.Route53AccessKey, config.Route53SecretKey, RegionEndpoint.EUWest1);
            var dnsUpdater = new DnsUpdater(_configHandler, _ipChecker, _amazonClient);

            HostFactory.Run(x =>
            {
                x.Service<IScheduledTaskService>(s =>
                {
                    s.ConstructUsing(name => new DnsUpdateService(new SchedulerRegistry(new ScheduledTaskWorker(dnsUpdater))));
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDisplayName("DynDns53 Service");
                x.SetServiceName("DynDns53");
                x.SetDescription("Updates AWS Route53 records with the current external IP of the system");

                x.StartAutomatically();

                x.EnableServiceRecovery(s =>
                {
                    s.RestartService(1);
                    s.RestartService(2);
                    s.RestartService(5);
                });
            });
        }
Esempio n. 2
0
 public ScheduledTaskWorker(DnsUpdater dnsUpdater)
 {
     _dnsUpdater = dnsUpdater;
 }
Esempio n. 3
0
        private void InitConfig()
        {
            AddLog("Loading configuration values...");

            // _configHandler = new AppConfigHandler();
            _configHandler = new JsonConfigHandler();
            var config = _configHandler.GetConfig();
            _ipChecker = new AwsIpChecker();
            IAmazonRoute53 _amazonClient = new AmazonRoute53Client(config.Route53AccessKey, config.Route53SecretKey, RegionEndpoint.EUWest1);
            _dnsUpdater = new DnsUpdater(_configHandler, _ipChecker, _amazonClient);

            AddLog($"Found {config.DomainList.Count} domain(s)");
            foreach (HostedDomainInfo domainInfo in config.DomainList)
            {
                AddLog($"{domainInfo.DomainName}");
            }

            if (_timer != null)
            {
                // Stop to avoid multiple timer_Tick invocations
                _timer.Stop();
            }

            int interval = config.UpdateInterval;
            _timer = new System.Windows.Threading.DispatcherTimer();
            _timer.Tick += timer_Tick;
            _timer.Interval = new TimeSpan(0, interval, 0);
            _timer.Start();

            AddLog($"Time set to update domains every {interval} minutes");

            SetAutoStart();
        }