48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using ImportAssist.Core;
|
|
|
|
// Einstiegspunkt für die lokale Prüfung: args[0] enthält den Pfad zur CSV-Datei.
|
|
if (args.Length != 1)
|
|
{
|
|
Console.Error.WriteLine(
|
|
"Bitte den Pfad zur CSV-Datei als Argument angeben.");
|
|
Environment.ExitCode = 1;
|
|
return;
|
|
}
|
|
|
|
var path = args[0];
|
|
|
|
if (!File.Exists(path))
|
|
{
|
|
Console.Error.WriteLine($"Datei nicht gefunden: {path}");
|
|
Environment.ExitCode = 1;
|
|
return;
|
|
}
|
|
|
|
IReadOnlyList<InvoiceRow> rows;
|
|
|
|
try
|
|
{
|
|
rows = InvoiceCsvParser.Parse(File.ReadAllText(path));
|
|
}
|
|
catch (FormatException exception)
|
|
{
|
|
// Ein fehlerhafter Dateiaufbau verhindert die Prüfung aller enthaltenen Rechnungen.
|
|
Console.Error.WriteLine(exception.Message);
|
|
Environment.ExitCode = 1;
|
|
return;
|
|
}
|
|
|
|
// Fachliche Fehler werden je Rechnung ausgegeben; sie ändern den Prozess-Exitcode nicht.
|
|
foreach (var row in rows)
|
|
{
|
|
var errors = InvoiceValidator.Validate(row);
|
|
|
|
var invoiceId = string.IsNullOrWhiteSpace(row.InvoiceId)
|
|
? "(ohne Rechnungsnummer)"
|
|
: row.InvoiceId;
|
|
|
|
Console.WriteLine(
|
|
errors.Count == 0
|
|
? $"{invoiceId}: Gültig"
|
|
: $"{invoiceId}: {string.Join("; ", errors)}");
|
|
} |