private async Task Execute(string csvTableName, FbConnection fbConnection, Func <FbConnection, EcfTableReader, Task <int> > action) { var sourceFile = Path.ChangeExtension(Path.Combine(_sourceFolder.FullName, csvTableName), ".csv"); if (!File.Exists(sourceFile)) { return; } // Report status Console.WriteLine($"[Importing] [{csvTableName}] Start..."); // Init CSV file stream using var csvfileStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.None); // Init CSV Reader using var csvReader = new CsvReader(csvfileStream, Encoding.UTF8); // Init ECF Reader var ecfTableReader = new EcfTableReader(csvReader); await ecfTableReader.ReadHeadersAsync(); _currentCsv = csvTableName; // Call table specific action var ecfRecordCounter = await action(fbConnection, ecfTableReader); // Inc counters _recordCounter += ecfRecordCounter; _tableCounter++; // Report status Console.WriteLine($"[Importing] [{csvTableName}] {ecfRecordCounter} record(s) imported"); }
private async Task ValidateSchooClassesFile(DirectoryInfo ecfFolder) { using var csvReader = new CsvReader(Path.Combine(ecfFolder.FullName, EcfTables.SchoolClasses + ".csv"), true); var ecfTableReader = new EcfTableReader(csvReader); await ecfTableReader.ReadHeadersAsync(); Assert.Equal(2, ecfTableReader.Headers.Count); Assert.Equal(EcfHeaders.Id, ecfTableReader.Headers[0]); Assert.Equal(EcfHeaders.Code, ecfTableReader.Headers[1]); }
private async Task ValidateStudentsFile(DirectoryInfo ecfFolder) { using var csvReader = new CsvReader(Path.Combine(ecfFolder.FullName, EcfTables.Students + ".csv"), true); var ecfTableReader = new EcfTableReader(csvReader); await ecfTableReader.ReadHeadersAsync(); Assert.Equal(5, ecfTableReader.Headers.Count); Assert.Equal(EcfHeaders.Id, ecfTableReader.Headers[0]); Assert.Equal(EcfHeaders.LastName, ecfTableReader.Headers[1]); Assert.Equal(EcfHeaders.FirstName, ecfTableReader.Headers[2]); Assert.Equal(EcfHeaders.Gender, ecfTableReader.Headers[3]); Assert.Equal(EcfHeaders.Birthdate, ecfTableReader.Headers[4]); await ecfTableReader.ReadAsync(); Assert.Equal("Duck", ecfTableReader.GetValue <string>(EcfHeaders.LastName)); Assert.Equal("Tick", ecfTableReader.GetValue <string>(EcfHeaders.FirstName)); Assert.Equal(EcfGender.Female, ecfTableReader.GetValue <EcfGender>(EcfHeaders.Gender)); Assert.Equal(new Date(2001, 1, 1), ecfTableReader.GetValue <Date>(EcfHeaders.Birthdate)); }