Files
XMLParser/XMLParser.Functions/CSVWriter.cs
2021-08-15 12:04:09 +02:00

57 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using XMLParser.Contract;
using XMLParser.Model;
namespace XMLProgramm
{
[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
public class CSVWriter : ICSVWriter
{
FileStream handle = null;
void writeToFile(string content)
{
content += Environment.NewLine;
byte[] bytes = Encoding.UTF8.GetBytes(content);
handle.Write(bytes,0,bytes.Length);
handle.Flush();
}
public CSVWriter()
{
handle = File.Create("./data.csv");
string WriteHeader = "Inspektionsdatum#Anzahl Straßenablaufe#Länge über 5m#SonstigeLeitungen#Sonstige Länge über 5m#Hauptkanallänge";
writeToFile(WriteHeader);
}
public void Save()
{
handle.Close();
}
private string GetDebuggerDisplay()
{
return ToString();
}
public void WriteEntry(Dictionary<ECalculatedResult, decimal> calculated, List<KanalObjekt> inspektionenAmTag)
{
int anzahlStraßenablaufe = (int)calculated[ECalculatedResult.STRASSENABLAUFANZAHL];
int sonstigeLeitungen = (int)calculated[ECalculatedResult.SONSTIGEANZAHL];
decimal Strassenablaufzulage = calculated[ECalculatedResult.STRASSENABLAUFLAENGEZULAGEMETER];
decimal Sonstigezulage = calculated[ECalculatedResult.SONSTIGELAENGEZULAGEMETER];
decimal HauptkanalLänge = calculated[ECalculatedResult.DN150DN250];
KanalObjekt last = inspektionenAmTag.Last();
string entry = last.Inspektionsdaten.OptischeInspektion.Inspektionsdatum + "#"+anzahlStraßenablaufe+"#"+Strassenablaufzulage+"#"+sonstigeLeitungen+"#"+Sonstigezulage+"#"+HauptkanalLänge;
writeToFile(entry);
}
}
}