Testdateien hinzugefügt.
Schächte werden Importiert
This commit is contained in:
52
WWTech_KanalSchnittstelle/Importer/CSVImporter.cs
Normal file
52
WWTech_KanalSchnittstelle/Importer/CSVImporter.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using SewerStammGen.Shared.Domain;
|
||||
using Shared.Contracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WWTech_KanalSchnittstelle.Importer
|
||||
{
|
||||
public class CSVImporter : IImport
|
||||
{
|
||||
private string[] input;
|
||||
private readonly Projekt projekt;
|
||||
|
||||
#pragma warning disable CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable.
|
||||
public CSVImporter(int projektID)
|
||||
#pragma warning restore CS8618 // Ein Non-Nullable-Feld muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie die Deklaration als Nullable.
|
||||
{
|
||||
projekt = new Projekt() { Id = projektID };
|
||||
}
|
||||
public List<Schacht> LoadSchaechte(string filename, EEntwaeserung entwaeserung)
|
||||
{
|
||||
List<Schacht> result = new List<Schacht>();
|
||||
|
||||
if(!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException(filename);
|
||||
}
|
||||
|
||||
input = File.ReadAllLines(filename);
|
||||
int zeile = -1;
|
||||
|
||||
foreach (string line in input)
|
||||
{
|
||||
zeile++;
|
||||
if (zeile == 0) continue;
|
||||
string[] parsed = line.Split(new char[] { ';' });
|
||||
result.Add(new Schacht()
|
||||
{
|
||||
Objektbezeichnung = parsed[0],
|
||||
RechtsWert = decimal.Parse(parsed[1].Replace('.',',')),
|
||||
HochWert = decimal.Parse(parsed[2].Replace('.', ',')),
|
||||
DeckelHoehe = decimal.Parse(parsed[3].Replace('.', ',')),
|
||||
Projekt = projekt,
|
||||
Entwaesserung = entwaeserung
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user