private async Task <int> ExportTeachers(CsvTableReader csvTableReader, EcfTableWriter ecfTableWriter, string[] ecfHeaders) { var ecfCache = new HashSet <string>(); var ecfRecordCounter = 0; await csvTableReader.ReadHeadersAsync(); if (ecfHeaders != null && ecfHeaders.Length > 0) { await ecfTableWriter.WriteHeadersAsync(ecfHeaders); } else { await ecfTableWriter.WriteHeadersAsync( EcfHeaders.Id, EcfHeaders.Code); } while (await csvTableReader.ReadAsync() > 0) { if (csvTableReader.TryGetValue("Alle Lehrkräfte (Kürzel) mit Fach", out var value)) { var csvLineParser = new CsvLineParser(','); var subValues = csvLineParser.Read(value); csvLineParser.Configuration.Separator = ' '; foreach (var subValue in subValues) { if (!string.IsNullOrEmpty(subValue)) { var subValueParts = csvLineParser.Read(subValue.Trim()); if (subValueParts.Length == 2) { var teacherCode = subValueParts[0]; if (!string.IsNullOrEmpty(teacherCode) && !ecfCache.Contains(teacherCode)) { ecfTableWriter.TrySetValue(EcfHeaders.Id, teacherCode); ecfTableWriter.TrySetValue(EcfHeaders.Code, teacherCode); await ecfTableWriter.WriteAsync(); ecfCache.Add(teacherCode); ecfRecordCounter++; } } } } } } return(ecfRecordCounter); }
public void SupportConvertingEmptyLine() { var textLine = ""; var csvParser = new CsvLineParser(); { Assert.NotNull(csvParser); var fieldsArray = csvParser.Read(textLine); Assert.Single(fieldsArray); var fieldsList = new List <string>(); csvParser.Read(textLine, fieldsList); Assert.Single(fieldsList); } }
public ExportStudent(Configuration config, XlsReader xlsReader) { xlsReader.TryGetValue(config.GetXlsColumnName("Vorname"), out FirstName); xlsReader.TryGetValue(config.GetXlsColumnName("Mittelname"), out MiddleName); xlsReader.TryGetValue(config.GetXlsColumnName("Nachname"), out LastName); xlsReader.TryGetValue(config.GetXlsColumnName("Geburtstag"), out BirthDate); xlsReader.TryGetValue(config.GetXlsColumnName("Rufname"), out NickName); xlsReader.TryGetValue(config.GetXlsColumnName("Geschlecht"), out Gender); xlsReader.TryGetValue(config.GetXlsColumnName("Anrede"), out Salutation); if (xlsReader.TryGetValue(config.GetXlsColumnName("Name"), out string name)) { var csvLineParser = new CsvLineParser(' '); var parts = csvLineParser.Read(name); if (parts.Length == 2) { FirstName = parts[0]; LastName = parts[1]; } else if (parts.Length == 3) { FirstName = parts[0]; MiddleName = parts[1]; LastName = parts[2]; } } if (!xlsReader.TryGetValue(config.GetXlsColumnName("Id"), out Id)) { Id = GenerateId(); } }
public void SupportConvertingToArray() { var textLine = "aaa1;bbb1;ccc1"; var csvParser = new CsvLineParser(); { Assert.NotNull(csvParser); var fields = csvParser.Read(textLine); Assert.Equal(3, fields.Count()); Assert.Equal("aaa1", fields[0]); Assert.Equal("bbb1", fields[1]); Assert.Equal("ccc1", fields[2]); } }
public void SupportConvertingToCollection() { var textLine = "aaa1;bbb1;ccc1"; var csvParser = new CsvLineParser(); { Assert.NotNull(csvParser); var fields = new List <string>(); csvParser.Read(textLine, fields); Assert.Equal(3, fields.Count); Assert.Equal("aaa1", fields[0]); Assert.Equal("bbb1", fields[1]); Assert.Equal("ccc1", fields[2]); } }
private async Task <int> ExportStudentSubjects(CsvTableReader csvTableReader, EcfTableWriter ecfTableWriter, string[] ecfHeaders) { var ecfRecordCounter = 0; await csvTableReader.ReadHeadersAsync(); if (ecfHeaders != null && ecfHeaders.Length > 0) { await ecfTableWriter.WriteHeadersAsync(ecfHeaders); } else { await ecfTableWriter.WriteHeadersAsync( EcfHeaders.StudentId, EcfHeaders.SchoolClassId, EcfHeaders.SubjectId, EcfHeaders.TeacherId); } while (await csvTableReader.ReadAsync() > 0) { var student = new CsvExportStudent(csvTableReader); var schoolClass = new CsvExportSchoolClass(csvTableReader); if (csvTableReader.TryGetValue("Alle Lehrkräfte (Kürzel) mit Fach", out var value)) { var csvLineParser = new CsvLineParser(','); var subValues = csvLineParser.Read(value); csvLineParser.Configuration.Separator = ' '; foreach (var subValue in subValues) { if (!string.IsNullOrEmpty(subValue)) { var subValueParts = csvLineParser.Read(subValue.Trim()); if (subValueParts.Length == 2) { var teacherCode = subValueParts[0]; var subjectCode = subValueParts[1]; if (!string.IsNullOrEmpty(subjectCode)) { ecfTableWriter.TrySetValue(EcfHeaders.StudentId, student.Id); ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, schoolClass.Id); ecfTableWriter.TrySetValue(EcfHeaders.SubjectId, subjectCode); ecfTableWriter.TrySetValue(EcfHeaders.TeacherId, teacherCode); await ecfTableWriter.WriteAsync(); ecfRecordCounter++; } } } } } } return(ecfRecordCounter); }