public async Task EnsureDataPopulationAsync() { try { if (IsPopulated()) { return; } DataEntries = _dataRepository.GetDataEntries(); // If there is no data in the database, scrape it from the website and insert into the DB if (!DataEntries.Any()) { var result = await _dataScraper.FetchDataFromWebAsync(); result.ForEach(resultEntry => DataEntries.Add(new IanaTimeZoneEntry { IANATimeZoneID = resultEntry[0], WinTimeZoneID = resultEntry[1] })); _dataRepository.InsertEntries(DataEntries); } if (DataEntries.Any()) { PopulateDictionaries(); } } catch (Exception e) { Debug.WriteLine($"Failed to populate data due to {e}"); } }
public bool IsPopulated() => DataEntries.Any() && IanaToWindows.Any() && WindowsToIana.Any();