40 Zeilen
1.4 KiB
C#
40 Zeilen
1.4 KiB
C#
namespace PrinterMonitor.Configuration;
|
|
|
|
public class PrinterConfig
|
|
{
|
|
private static readonly HashSet<string> ValidTypes = new(StringComparer.OrdinalIgnoreCase)
|
|
{ "CabSquix", "Zebra", "Honeywell", "Simulation" };
|
|
|
|
public string Name { get; set; } = "";
|
|
public string Type { get; set; } = "CabSquix"; // "CabSquix", "Zebra", "Honeywell" oder "Simulation"
|
|
public string Host { get; set; } = "";
|
|
public int Port { get; set; } // Drucker-Kommunikationsport (bei Simulation ignoriert)
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Prüft die Konfiguration und gibt eine Liste von Fehlern zurück (leer = gültig).
|
|
/// </summary>
|
|
public List<string> Validate()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
if (string.IsNullOrWhiteSpace(Name))
|
|
errors.Add("Name darf nicht leer sein");
|
|
|
|
if (!ValidTypes.Contains(Type ?? ""))
|
|
errors.Add($"Ungültiger Druckertyp '{Type}'");
|
|
|
|
var isSimulation = string.Equals(Type, "Simulation", StringComparison.OrdinalIgnoreCase);
|
|
if (!isSimulation)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Host))
|
|
errors.Add($"'{Name}': Host darf nicht leer sein");
|
|
|
|
if (Port < 1 || Port > 65535)
|
|
errors.Add($"'{Name}': Port muss zwischen 1 und 65535 liegen (ist {Port})");
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
}
|