Esempio n. 1
0
 public CsvExportStudent(CsvTableReader csvTableReader)
 {
     csvTableReader.TryGetValue("Schüler_Stamm_ID", out Id);
     csvTableReader.TryGetValue("Vornamen", out FirstName);
     csvTableReader.TryGetValue("Familienname", out LastName);
     csvTableReader.TryGetValue("Geburtsdatum", out BirthDate);
     csvTableReader.TryGetValue("Geschlecht (männlich/weiblich)", out Gender);
 }
Esempio n. 2
0
        public ExportStudent(Configuration config, CsvTableReader csvTableReader)
        {
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Vorname"), out FirstName);
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Mittelname"), out MiddleName);
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Nachname"), out LastName);
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Geburtstag"), out BirthDate);
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Rufname"), out NickName);
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Geschlecht"), out Gender);
            csvTableReader.TryGetValue(config.GetCsvHeaderName("Anrede"), out Salutation);

            if (csvTableReader.TryGetValue(config.GetCsvHeaderName("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 (!csvTableReader.TryGetValue(config.GetCsvHeaderName("Id"), out Id))
            {
                Id = GenerateId();
            }
        }
 public CsvExportSchoolClass(CsvTableReader csvTableReader)
 {
     if (csvTableReader.TryGetValue("Klasse", out Id))
     {
         Code = Id;
     }
     else if (csvTableReader.TryGetValue("Klasse / Klassengruppe", out Id))
     {
         Code = Id;
     }
 }
Esempio n. 4
0
        public async Task TestTypedValues()
        {
            var csvData =
                "A;B;C;D;E" + Environment.NewLine +
                "22;Text;true;01.01.2010;A" + Environment.NewLine +
                "-31;A long text;false;20.01.2050;B" + Environment.NewLine +
                "55;\"A text with ;\";;31.07.1971;C";

            using var csvReader = new CsvReader(csvData);

            var csvTableReader = new CsvTableReader(csvReader);

            Assert.NotNull(csvTableReader);

            csvTableReader.SetFormats <DateTime>("dd.MM.yyyy");

            await csvTableReader.ReadHeadersAsync();

            Assert.Equal(5, csvTableReader.Headers.Count);
            Assert.Equal("A", csvTableReader.Headers[0]);
            Assert.Equal("B", csvTableReader.Headers[1]);
            Assert.Equal("C", csvTableReader.Headers[2]);
            Assert.Equal("D", csvTableReader.Headers[3]);
            Assert.Equal("E", csvTableReader.Headers[4]);

            await csvTableReader.ReadAsync();

            Assert.Equal(22, csvTableReader.GetValue <int>("A"));
            Assert.Equal("Text", csvTableReader.GetValue <string>("B"));
            Assert.True(csvTableReader.GetValue <bool>("C"));
            Assert.Equal(new DateTime(2010, 1, 1), csvTableReader.GetValue <DateTime>("D"));
            Assert.Equal(SampleEnum.A, csvTableReader.GetValue <SampleEnum>("E"));

            await csvTableReader.ReadAsync();

            Assert.Equal(-31, csvTableReader.GetValue <int>("A"));
            Assert.Equal("A long text", csvTableReader.GetValue <string>("B"));
            Assert.False(csvTableReader.GetValue <bool>("C"));
            Assert.Equal(new DateTime(2050, 1, 20), csvTableReader.GetValue <DateTime>("D"));
            Assert.Equal(SampleEnum.B, csvTableReader.GetValue <SampleEnum?>("E"));

            await csvTableReader.ReadAsync();

            Assert.True(csvTableReader.TryGetValue <int>("A", out var a));
            Assert.Equal(55, a);
            Assert.True(csvTableReader.TryGetValue <string>("B", out var b));
            Assert.Equal("A text with ;", b);
            Assert.True(csvTableReader.TryGetValue <bool?>("C", out var c));
            Assert.Null(c);
            Assert.True(csvTableReader.TryGetValue <DateTime>("D", out var d));
            Assert.Equal(new DateTime(1971, 7, 31), d);
        }
Esempio n. 5
0
 public ExportSchoolClass(Configuration config, CsvTableReader csvTableReader)
 {
     if (csvTableReader.TryGetValue(config.GetCsvHeaderName("Klasse"), out Id))
     {
         Code = Id;
     }
 }
Esempio n. 6
0
 public ExportSubject(Configuration config, CsvTableReader csvTableReader, string headerName)
 {
     if (csvTableReader.TryGetValue(config.GetCsvHeaderName(headerName), out Id))
     {
         Code = Id;
     }
 }
        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);
        }
Esempio n. 8
0
        public async Task TestTryGetValue()
        {
            var csvData =
                "A;B;C" + Environment.NewLine +
                "a1;b1;c1" + Environment.NewLine +
                "a2;b2;c2";

            using var csvReader = new CsvReader(csvData);

            var csvTableReader = new CsvTableReader(csvReader);

            Assert.NotNull(csvTableReader);

            await csvTableReader.ReadHeadersAsync();

            await csvTableReader.ReadAsync();

            Assert.Equal(3, csvTableReader.Headers.Count);
            Assert.True(csvTableReader.TryGetValue(0, out string v1));
            Assert.Equal("a1", v1);
            Assert.True(csvTableReader.TryGetValue(1, out string v2));
            Assert.Equal("b1", v2);
            Assert.True(csvTableReader.TryGetValue(2, out string v3));
            Assert.Equal("c1", v3);
            Assert.False(csvTableReader.TryGetValue(3, out string v4));
            Assert.Null(v4);

            await csvTableReader.ReadAsync();

            Assert.Equal(3, csvTableReader.Headers.Count);
            Assert.True(csvTableReader.TryGetValue("A", out string v5));
            Assert.Equal("a2", v5);
            Assert.True(csvTableReader.TryGetValue("B", out string v6));
            Assert.Equal("b2", v6);
            Assert.True(csvTableReader.TryGetValue("C", out string v7));
            Assert.Equal("c2", v7);
            Assert.False(csvTableReader.TryGetValue("D", out string v8));
            Assert.Null(v8);
        }
        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);
        }