public async Task <List <NaceRegionData> > PopulateDB()
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            System.DateTime moment = System.DateTime.Now;
            EndYear = moment.Year;
            List <EuroStatTable> tables = await databaseStore.getAllEuroStatTables();

            int    i             = 0;
            int    infoMaxLength = 70;
            string info;

            foreach (EuroStatTable table in tables)
            {
                info = $"Saving data in database: {(double)i++ * 100 / tables.Count:0.0}% - {table.attributeName} ";
                Console.Write($"\r{info}{Strings.Space(infoMaxLength - info.Length)}");
                await FetchAndStore(table);
            }
            info = "Done saving data in database";
            Console.WriteLine($"\r{info}{Strings.Space(infoMaxLength - info.Length)}");

            watch.Stop();
            var elapsedS = watch.ElapsedMilliseconds / 1000;
            var minutes  = elapsedS / 60;
            var seconds  = elapsedS - (minutes * 60);

            Console.WriteLine("Database populated in: " + minutes + ":" + seconds + " minutes.");
            return(await databaseStore.getAllNaceRegionData());
        }
Пример #2
0
        public async Task <String> PopulateDatabase()
        {
            List <Nace> savedNaces = await ds.getAllNaces();

            List <Region> savedRegions = await ds.getAllRegions();

            List <EuroStatTable> savedTables = await ds.getAllEuroStatTables();

            foreach (Nace nace in baseData.getAllNaces())
            {
                try
                {
                    if (!savedNaces.Contains(nace))
                    {
                        await ds.createNace(nace);
                    }
                } catch (Exception exception)
                {
                    _logger.LogError(exception.ToString());
                    return(exception.ToString());
                }
            }
            foreach (Region region in baseData.getAllRegions())
            {
                try
                {
                    if (!savedRegions.Contains(region))
                    {
                        await ds.createRegion(region);
                    }
                } catch (Exception exception)
                {
                    _logger.LogError(exception.ToString());
                    return(exception.ToString());
                }
            }
            foreach (EuroStatTable table in baseData.getAllEuroStatTables())
            {
                try
                {
                    if (!savedTables.Contains(table))
                    {
                        await ds.createEuroStatTable(table);
                    }
                } catch (Exception exception)
                {
                    _logger.LogError(exception.ToString());
                    return(exception.ToString());
                }
            }
            return("The base data was added successfully");
        }
Пример #3
0
 public async Task <List <EuroStatTable> > getAllTables()
 {
     return(await _databaseStore.getAllEuroStatTables());
 }