public DomainConnectDDNSWorker(EventLog eventLog) { this.eventLog1 = eventLog; this.settings = new DomainConnectDDNSSettings(); this.settings.Load("settings.txt"); }
//------------------------------------------------------- // InitService // // Initializes the service // public void InitService() { int status = 0; this.settings = new DomainConnectDDNSSettings(); this.settings.Load("settings.txt"); string domain_name = (string)this.settings.ReadValue("domain_name", null); string access_token = (string)this.settings.ReadValue("access_token", null); string refresh_token = (string)this.settings.ReadValue("refresh_token", null); string provider_name = (string)this.settings.ReadValue("provider_name", null); string urlAPI = (string)this.settings.ReadValue("urlAPI", null); string host = (string)this.settings.ReadValue("host", null); if (String.IsNullOrEmpty(domain_name) || String.IsNullOrEmpty(access_token) || String.IsNullOrEmpty(refresh_token) || String.IsNullOrEmpty(provider_name) || String.IsNullOrEmpty(urlAPI)) { this.WriteEvent("Initiaize failure: missing data. Run installer and restart service.", EventLogEntryType.Error); this._initialized = true; return; } // Query the initial (current) IP from DNS. Null is an error, "" means no current value string fqdn = domain_name; if (!String.IsNullOrEmpty(host)) { fqdn = host + "." + fqdn; } this._currentIP = RestAPIHelper.RestAPIHelper.GetDNSIP(fqdn); if (this._currentIP == null) { this.WriteEvent("Failed to read current IP for domain.", EventLogEntryType.Error); // We won't penalize if internet or service is down if (status != 0 && status < 500) { this.numInitializeFails++; } // After 10 tries to init that fail, we give up if (this.numInitializeFails > 10) { this.WriteEvent("Initialize failure: threshold for attempted initialize reached. Restart service.", EventLogEntryType.Error); this._initialized = true; } return; } // Service successfully initalized. Mark it sas such and start monitoring this._initialized = true; this._monitoring = true; this.WriteEvent("Initialize success: Initialized and monitoring for changes.", EventLogEntryType.Information); }