예제 #1
0
        public async Task <List <GalacticPOI> > GetPOIs(GalacticSystemContext context)
        {
            if (pois == null || (DateTime.UtcNow - lastRefreshTime) >= new TimeSpan(1, 0, 0))
            {
                pois = await context.GalacticPOIs.ToListAsync();

                lastRefreshTime = DateTime.UtcNow;
            }

            return(pois);
        }
예제 #2
0
        public static void UpdatePOIsFromFile(GalacticSystemContext context, string filename, ILogger logger)
        {
            logger.Log(LogLevel.Information, $"Updating POIs from {filename}...");
            // The total number of POIs in Elite Dangerous is low enough to add all at once.
            var jsonConverter = new JSONToGalacticPointConverter();
            var pois          = jsonConverter.ConvertJSONToPOIs(filename)
                                .Where(a => !context.GalacticPOIs.Any(b => b.Id == a.Id)).ToImmutableList();

            logger.Log(LogLevel.Debug, $"{pois.Count} new POIs in this file.");
            context.GalacticPOIs.AddRange(pois);
            context.SaveChanges();
            logger.Log(LogLevel.Information, $"Done updating POIs from {filename}.");
        }
예제 #3
0
        private void ConsumePoisFromJsonFile(GalacticSystemContext context, ILogger logger, IConfiguration config)
        {
            const string configKey = "POIUpdateDirectory";
            var          updateDir = config.GetSection("GalaxyUpdates")[configKey];

            if (!Directory.Exists(updateDir))
            {
                logger.Log(LogLevel.Information, $"POI folder {updateDir} did not exist, skipping import.");
                return;
            }
            if (!string.IsNullOrEmpty(updateDir))
            {
                logger.Log(LogLevel.Information, $"Checking {configKey} {updateDir}...");
                foreach (var jsonFile in Directory.GetFiles(updateDir, "*.json"))
                {
                    DatabaseUpdater.UpdatePOIsFromFile(context, jsonFile, logger);
                    File.Delete(jsonFile);
                }
            }
        }
예제 #4
0
 public DatabaseGalaxyRepository(GalacticSystemContext galacticSystemContext, PoiCache poiCache)
 {
     context       = galacticSystemContext;
     this.poiCache = poiCache;
 }