public async Task <IActionResult> PostRebuildSource(string source) { var adapter = _adaptersFactory.GetBySource(source); if (adapter == null) { return(NotFound($"Source {source} does not exist")); } _logger.LogInformation($"Starting rebuilding {source}, getting points..."); var points = await adapter.GetPointsForIndexing(); _logger.LogInformation($"Got {points.Count} points for {source}"); var fullPoints = new ConcurrentBag <FeatureCollection>(); await _elasticSearchGateway.DeleteExternalPoisBySource(source); var counter = 0; Parallel.For(0, points.Count, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (index) => { var featureCollection = adapter.GetRawPointOfInterestById(points[index].Attributes[FeatureAttributes.ID].ToString()).Result; _elasticSearchGateway.AddExternalPoi(featureCollection); Interlocked.Increment(ref counter); if (counter % 100 == 0) { _logger.LogInformation($"Indexed {counter} points of {points.Count} for {source}"); } }); _logger.LogInformation($"Finished rebuilding {source}, indexed {points.Count} points."); // HM TODO: set rebuild date for source somehow... return(Ok()); }
public async Task <IActionResult> PostRebuildSource(string source) { if (!GetSources().Contains(source) && source != "all") { return(NotFound($"Source {source} does not exist")); } var sources = source == "all" ? GetSources() : new[] { source }; foreach (var currentSource in sources) { _logger.LogInformation($"Starting rebuilding {currentSource}, getting points..."); var adapter = _adaptersFactory.GetBySource(currentSource); var points = await adapter.GetPointsForIndexing(); _logger.LogInformation($"Got {points.Count} points for {currentSource}"); var fullPoints = new ConcurrentBag <FeatureCollection>(); await _elasticSearchGateway.DeleteExternalPoisBySource(currentSource); var counter = 0; Parallel.For(0, points.Count, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (index) => { try { var feature = adapter.GetRawPointOfInterestById(points[index].Attributes[FeatureAttributes.ID].ToString()).Result; var geoLocation = feature.Attributes[FeatureAttributes.POI_GEOLOCATION] as AttributesTable; var geoLocationCoordinate = new Coordinate((double)geoLocation[FeatureAttributes.LON], (double)geoLocation[FeatureAttributes.LAT]); feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ALT, _elevationDataStorage.GetElevation(geoLocationCoordinate).Result); var northEast = _wgs84ItmTransform.Transform(geoLocationCoordinate.X, geoLocationCoordinate.Y); feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_EAST, (int)northEast.x); feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_NORTH, (int)northEast.y); _elasticSearchGateway.AddExternalPoi(feature); Interlocked.Increment(ref counter); if (counter % 100 == 0) { _logger.LogInformation($"Indexed {counter} points of {points.Count} for {currentSource}"); } } catch (Exception ex) { _logger.LogError($"failed to index point with title: {points[index].GetTitle(Languages.ALL)} for {currentSource} with exception: {ex.ToString()}"); } }); _logger.LogInformation($"Finished rebuilding {currentSource}, indexed {points.Count} points."); // HM TODO: set rebuild date for source somehow... } return(Ok()); }