Exemple #1
0
        private static void ExtractZipAndImportDataFromExcelAndMongoDb(
            IAirportsDataSqlServer airportsData, 
            IAirportsDataMongoDb mongoData)
        {
            Console.WriteLine("Unpacking zip archive...");
            var zipExtractor = new ZipExtractor();
            zipExtractor.Extract(SampleFlightsArchivedFilePath, SampleFlightsUnpackedDestinationPath);

            Console.WriteLine("Importing flights data from directory with xls/xlsx files...");
            var excelDataImporter = new ExcelDataImporter();
            ICollection<Flight> importedFlightsFromExcel = excelDataImporter
                .ImportFlightsDataFromDirectory(SampleFlightsUnpackedDestinationPath);

            Console.WriteLine("Loading imported flights from Excel to SQL Server...");

            foreach (var flight in importedFlightsFromExcel)
            {
                airportsData.Flights.Add(flight);
            }

            airportsData.SaveChanges();

            var countriesFromMongo = mongoData.Countries.ToList();

            foreach (var country in countriesFromMongo)
            {
                airportsData.Countries.Add(country);
            }

            var citiesFromMongo = mongoData.Cities.ToList();

            foreach (var city in citiesFromMongo)
            {
                airportsData.Cities.Add(city);
            }

            airportsData.SaveChanges();
        }
Exemple #2
0
        private static void ImportFlightsDataFromXmlAndLoadToMongoDb(IAirportsDataSqlServer airportsData, IAirportsDataMongoDb mongoData)
        {
            Console.WriteLine("Importing flights data from xml file...");

            XmlDataImporter xmlDataImporter = new XmlDataImporter();

            ICollection<Flight> importedFlightsFromXml =
                xmlDataImporter.ImportFlightsDataFromFile(SampleFlightsDataXmlFilePath);

            Console.WriteLine("Loading imported flights to SQL Server and MongoDb...");

            foreach (var flight in importedFlightsFromXml)
            {
                airportsData.Flights.Add(flight);
                mongoData.Save(flight);
            }

            airportsData.SaveChanges();
        }