예제 #1
0
        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;
            }
        }
예제 #2
0
파일: DataCache.cs 프로젝트: M0OPK/SDJSharp
        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]);
            }
        }