public async Task <ILocationData> EnrichLocationsAsync(ILocationData locations, TocLookup lookup, CancellationToken token) { var refData = await GetReferenceData(token).ConfigureAwait(false); var mapper = new StationMapper(lookup, locations, _logger); foreach (var location in refData.LocationRef) { try { if (ShouldUpdate(location) && locations.TryGetStation(location.crs, out var target)) { mapper.Update(target, location); } else { _logger.Debug("Darwin Location not loaded: {tpl} : {name}", location.tpl, location.locname); } } catch (Exception e) { _logger.Warning(e, "Error updating station: {station} with Darwin data.", location.crs); } } foreach (var viaRule in refData.Via) { try { if (locations.TryGetStation(viaRule.at, out var target)) { mapper.AddRule(target, viaRule); } } catch (Exception e) { _logger.Warning(e, "Error updating station: {station} with Via rule.", viaRule.at); } } return(locations); bool ShouldUpdate(LocationRef location) { return(!string.IsNullOrEmpty(location.crs)); } }
public async Task <ILocationData> UpdateLocationsWithKnowledgebaseStationsAsync(ILocationData locations, TocLookup lookup, CancellationToken token) { var mapper = new StationMapper(lookup); StationList stations = null; try { stations = await _knowledgebase.GetStations(token).ConfigureAwait(false); } catch (Exception e) { _logger.Warning(e, "Error loading Knowledgebase Stations."); } if (stations == null) { return(locations); } foreach (var station in stations.Station) { try { if (locations.TryGetStation(station.CrsCode, out var target)) { mapper.Update(target, station); } } catch (Exception e) { _logger.Warning(e, "Error updating station: {station} with knowledgebase.", station.CrsCode); } } return(locations); }