public SDGetLineupResponse GetLineupData(SDJson sd, string lineup) { if (!stationMapData.ContainsKey(lineup)) { var thisMap = sd.GetLineup(lineup, true); if (thisMap != null) { stationMapData.Add(lineup, thisMap); return(thisMap); } } else { SDGetLineupResponse map = null; if (stationMapData.ContainsKey(lineup)) { map = stationMapData[lineup]; // Validate cache is in date. If not replace it fresh if ((map.cacheDate ?? DateTime.MinValue) <= DateTime.UtcNow.AddHours(0 - cacheExpiryHours)) { stationMapData.Remove(lineup); return(GetLineupData(sd, lineup)); } } return(map); } return(null); }
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]); } }
public IEnumerable <SDPreviewLineupResponse> GetLineupPreview(SDJson sd, string lineup) { if (!previewStationData.ContainsKey(lineup)) { var thisPreview = sd.GetLineupPreview(lineup); if (thisPreview != null) { previewStationData.Add(lineup, thisPreview); return(thisPreview); } } else { var preview = previewStationData[lineup]; // Validate cache is in date. If not replace it fresh var oldestDate = preview.Where(line => line.cacheDate != null).Select(line => line.cacheDate).Min() ?? DateTime.UtcNow; if (oldestDate <= DateTime.UtcNow.AddHours(0 - cacheExpiryHours)) { previewStationData.Remove(lineup); return(GetLineupPreview(sd, lineup)); } return(preview); } return(null); }
public SDCountries GetCountryData(SDJson sd) { if (countryData == null || (countryData.cacheDate ?? DateTime.UtcNow) <= DateTime.UtcNow.AddHours(0 - cacheExpiryHours)) { countryData = sd.GetCountries(); } return(countryData); }
public CustomGridEntry(SDJson sdJS, Config dataconfig, DataCache datacache, Dictionary <string, Config.XmlTVTranslation> dataLocalTranslate) { InitializeComponent(); Localize(); sd = sdJS; config = dataconfig; cache = datacache; localTranslate = dataLocalTranslate; dgCustomEntry.SuspendLayout(); dgCustomEntry.Rows.Clear(); foreach (var item in dataLocalTranslate.Select(line => line.Value).Where(line => line.FieldMode == Config.XmlTVTranslation.TranslateField.Custom)) { var channelNum = string.Empty; var logicalChannelNum = string.Empty; var thisData = datacache.GetLineupData(sdJS, item.LineupID).stations.FirstOrDefault(line => line.stationID == item.SDStationID); if (thisData == null) { continue; } var thisMap = datacache.GetLineupData(sdJS, item.LineupID).map.FirstOrDefault(line => line.stationID == item.SDStationID); if (thisMap != null) { channelNum = thisMap.channel; logicalChannelNum = thisMap.logicalChannelNumber; } var thisLine = new string[] { item.LineupID, item.SDStationID, channelNum, logicalChannelNum, thisData.name, item.CustomTranslate }; dgCustomEntry.Rows.Add(thisLine); } if (dgCustomEntry.Rows.Count > 0) { dgCustomEntry.CurrentCell = dgCustomEntry.Rows[0].Cells[3]; } dgCustomEntry.ResumeLayout(); }
public formUIDemo() { InitializeComponent(); sd = new SDJson(); }