128 lines
4.3 KiB
C#
128 lines
4.3 KiB
C#
using SewerStammGen.Shared.Domain;
|
|
using SewerStammGen.Shared.Enum;
|
|
using Shared.Contracts;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WWTech_KanalSchnittstelle.Importer
|
|
{
|
|
internal enum EKennung
|
|
{
|
|
DECKEL = 1,
|
|
SOHLE = 2
|
|
}
|
|
public class CSVImporter : IImport
|
|
{
|
|
private string[]? input;
|
|
private readonly Projekt projekt;
|
|
|
|
|
|
public CSVImporter(int projektID)
|
|
{
|
|
projekt = new Projekt() { Id = projektID };
|
|
}
|
|
|
|
private decimal parseKoordinate(string input)
|
|
{
|
|
decimal result = 0m;
|
|
input = string.Format("{0:0.000}", input).Replace('.', ',');
|
|
if(!decimal.TryParse(input, out result))
|
|
{
|
|
throw new Exception("Konnte koordinate nicht parsen");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public List<Schacht> LoadSchaechte(string filename, string vermesser)
|
|
{
|
|
List<Schacht> result = new List<Schacht>();
|
|
|
|
Dictionary<string, EEntwaeserung> entwaesserungKennung = new Dictionary<string, EEntwaeserung>()
|
|
{
|
|
{ "1100", EEntwaeserung.Schmutzwasser },
|
|
{ "1200", EEntwaeserung.Mischwasser },
|
|
{ "1300", EEntwaeserung.Regenwasser },
|
|
{ "3110", EEntwaeserung.Schmutzwasser },
|
|
{ "3210", EEntwaeserung.Mischwasser },
|
|
{ "3310", EEntwaeserung.Regenwasser }
|
|
};
|
|
|
|
Dictionary<string, ESchachtType> schachtKennung = new Dictionary<string, ESchachtType>()
|
|
{
|
|
{ "1100", ESchachtType.Hauptkanal },
|
|
{ "1200", ESchachtType.Hauptkanal },
|
|
{ "1300", ESchachtType.Hauptkanal },
|
|
{ "3110", ESchachtType.Revisionschacht },
|
|
{ "3210", ESchachtType.Revisionschacht },
|
|
{ "3310", ESchachtType.Revisionschacht }
|
|
};
|
|
|
|
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[] { ';' });
|
|
|
|
string objektbezeichnung = parsed[0];
|
|
|
|
string objektname = objektbezeichnung.Substring(0, objektbezeichnung.Length - 2);
|
|
EKennung kennung = (EKennung)Convert.ToInt32(objektbezeichnung.Substring(objektbezeichnung.Length - 2, 2));
|
|
|
|
bool neueSchacht = false;
|
|
Schacht? schacht = result.FindLast(x => x.Objektbezeichnung.Equals(objektname) && x.Projekt.Id.Equals(projekt.Id));
|
|
if (schacht == null)
|
|
{
|
|
schacht = new Schacht();
|
|
neueSchacht = true;
|
|
}
|
|
|
|
if(kennung == EKennung.DECKEL)
|
|
{
|
|
schacht.DeckelRechtsWert = parseKoordinate(parsed[1]);
|
|
schacht.DeckelHochWert = parseKoordinate(parsed[2]);
|
|
schacht.DeckelHoehe = parseKoordinate(parsed[3]);
|
|
}
|
|
if(kennung == EKennung.SOHLE)
|
|
{
|
|
schacht.SohlRechtsWert = parseKoordinate(parsed[1]);
|
|
schacht.SohlHochWert = parseKoordinate(parsed[2]);
|
|
schacht.SohlHoehe = parseKoordinate(parsed[3]);
|
|
}
|
|
|
|
if (parsed.Length > 4)
|
|
{
|
|
schacht.Entwaesserung = entwaesserungKennung[parsed[4]];
|
|
schacht.SchachtType = schachtKennung[parsed[4]];
|
|
}
|
|
else
|
|
{
|
|
schacht.Entwaesserung = EEntwaeserung.Schmutzwasser;
|
|
schacht.SchachtType = ESchachtType.Hauptkanal;
|
|
}
|
|
schacht.Projekt = projekt;
|
|
|
|
schacht.Vermesser = vermesser;
|
|
schacht.AufnahmeDatum = DateTime.Now.ToShortDateString();
|
|
|
|
if (neueSchacht)
|
|
{
|
|
schacht.Objektbezeichnung = objektname;
|
|
result.Add(schacht);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|