示例#1
0
        public async Task <IActionResult> PutUpdateData()
        {
            // HM TODO: update this code according to changes in POIs
            if (!IsRequestLocal())
            {
                return(BadRequest("This operation can't be done from a remote client, please run this from the server"));
            }
            if (!RebuildSemaphore.WaitOne(0))
            {
                return(BadRequest("Can't run update while full update is running"));
            }
            RebuildSemaphore.Release();
            await UpdateSemaphore.WaitAsync();

            try
            {
                _logger.LogInformation("Starting incremental site's databases update");
                using (var updatesStream = await _osmLatestFileFetcherExecutor.GetUpdates())
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(OsmChange));
                    var           changes    = (OsmChange)serializer.Deserialize(updatesStream);
                    await _databasesUpdaterService.Update(changes);
                }
                _logger.LogInformation("Finished incremental site's databases update");
                return(Ok());
            }
            finally
            {
                UpdateSemaphore.Release();
            }
        }
        public void TestUpdate_EmptyOsmChangeFile_ShouldNotUpdateAnything()
        {
            var changes = new OsmChange {
                Create = new OsmGeo[0], Modify = new OsmGeo[0], Delete = new OsmGeo[0]
            };

            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <Dictionary <string, List <ICompleteOsmGeo> > >(x => x.Values.Count == 0))
            .Returns(new List <Feature>());
            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <List <CompleteWay> >(x => x.Count == 0))
            .Returns(new List <Feature>());

            _service.Update(changes).Wait();

            _elasticSearchGateway.Received(1).UpdatePointsOfInterestData(Arg.Is <List <Feature> >(x => x.Count == 0));
            _elasticSearchGateway.Received(1).UpdateHighwaysData(Arg.Is <List <Feature> >(x => x.Count == 0));
        }