public static IPFetchDataCache GetOrCreate(string cachePath) { IPFetchDataCache dataCache = new IPFetchDataCache(); if (File.Exists(cachePath)) { try { dataCache = JsonConvert.DeserializeObject <IPFetchDataCache>(File.ReadAllText(cachePath)); } catch (Exception ex) { Logger.Error("Unable to load cache file.", ex); } } dataCache.CachePath = cachePath; return(dataCache); }
private void InitializeSettings() { try { _receiverEmail = ConfigurationManager.AppSettings["receiverEmail"]; _receiverName = ConfigurationManager.AppSettings["receiverName"]; _cachePath = ConfigurationManager.AppSettings["cacheFilePath"]; _checkIntervalSec = int.Parse(ConfigurationManager.AppSettings["ipCheckIntervalSeconds"]); _dnsUpdateUrls = ConfigurationManager.AppSettings["dnsUpdateUrls"].Split(','); _ipAddressProviderUrl = ConfigurationManager.AppSettings["ipAddressProviderUrl"]; _mailgunAPIKey = ConfigurationManager.AppSettings["mailgunAPIKey"]; _mailgunDomainName = ConfigurationManager.AppSettings["mailgunDomainName"]; _machineName = Environment.MachineName; _dataCache = IPFetchDataCache.GetOrCreate(_cachePath); } catch (Exception ex) { _logger.Error("Unable to initialize settings", ex); _keepRunning = false; } }