private void btnHeadends_Click(object sender, EventArgs e) { headEnds = sd.GetHeadends("USA", "10001"); if (headEnds == null) { reportErrors(); return; } lbContinents.Items.Clear(); lbCountries.Items.Clear(); foreach (var headEnd in headEnds) { if (headEnd == null) { continue; } lbContinents.Items.Add($"{headEnd.headend}\t{headEnd.location}\t{headEnd.transport}"); } mode = 3; if (lbContinents.Items.Count > 0) { lbContinents.SelectedIndex = 0; } }
public IEnumerable <SDHeadendsResponse> GetHeadendData(SDJson sd, string country, string postcode) { var headendKey = $"{country},{postcode}"; if (!headendData.ContainsKey(headendKey)) { var headendDataJS = sd.GetHeadends(country, postcode); if (headendDataJS != null) { headendData.Add(headendKey, headendDataJS); } return(headendDataJS); } else { // Validate oldest cached value var oldestDate = headendData[headendKey].Where(line => line.cacheDate != null).Select(line => line.cacheDate).Min() ?? DateTime.UtcNow; if (oldestDate <= DateTime.UtcNow.AddHours(0 - cacheExpiryHours)) { // Delete cached value and return new value headendData.Remove(headendKey); return(GetHeadendData(sd, country, postcode)); } // Otherwise return from cache return(headendData[headendKey]); } }