From cdc4fb70cd051cab0cb1a764e28f16a657dba6fe Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Sat, 16 May 2026 15:09:50 +0200 Subject: [PATCH] [chore:] logging for AddressShortener.cs --- Tasks/AddressShortener.cs | 125 ++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/Tasks/AddressShortener.cs b/Tasks/AddressShortener.cs index e7451c3..53ac048 100644 --- a/Tasks/AddressShortener.cs +++ b/Tasks/AddressShortener.cs @@ -12,68 +12,73 @@ public class AddressShortener(ProgressWindow progressWindow) public async Task Perform(KasAddressList list) { - // find doubled addresses by refsid - List doubled_ids = new List(); - for (int i = 0; i < list.KasPersons.Count; i++) + try { - var address = list.KasPersons[i]; - for (int j = 0; j < list.KasPersons.Count; j++) - { - if (i == j) continue; - var sec_address = list.KasPersons[j]; - - if (address.refsid == sec_address.refsid && !doubled_ids.Contains(address.refsid) && address.refsid != 0) - { - doubled_ids.Add(address.refsid); - } - } + List doubled_ids = new List(); + for (int i = 0; i < list.KasPersons.Count; i++) + { + var address = list.KasPersons[i]; + for (int j = 0; j < list.KasPersons.Count; j++) + { + if (i == j) continue; + var sec_address = list.KasPersons[j]; + + if (address.refsid == sec_address.refsid && !doubled_ids.Contains(address.refsid) && address.refsid != 0) + { + doubled_ids.Add(address.refsid); + } + } + } + + + // delete doubled addresses by refsid + foreach (int id in doubled_ids) + { + // does this remove both of the doubled addresses? + list.KasPersons.Remove(list.KasPersons.FirstOrDefault(x => x.refsid == id)); + } + + List toRemove = new List(); + foreach (var address in list.KasPersons) + { + try + { + if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.NoPLZorPPLZ)) + { + toRemove.Add(address.id); + } + else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PlzNotUsable) && + address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PPlzNotUsable)) + { + toRemove.Add(address.id); + } else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PlzNotUsable) && + address.PersonError.warnings.Contains(AddressCheck.WarningTypes.NoPPLZ)) + { + toRemove.Add(address.id); + } + else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PPlzNotUsable) && + address.PersonError.warnings.Contains(AddressCheck.WarningTypes.NoPLZ)) + { + toRemove.Add(address.id); + } + } + catch + { + Console.WriteLine("PersonError not accessible: " + address.id); + } + } + + // delete doubled addresses by refsid + foreach (int id in toRemove) + { + // does this remove both of the doubled addresses? + list.KasPersons.Remove(list.KasPersons.Find(x => x.id == id)); + } + } + catch (Exception ex) + { + Logger.Log($"Error while performing address shortener: {ex.Message}", Logger.LogType.Error); } - - // delete doubled addresses by refsid - foreach (int id in doubled_ids) - { - // does this remove both of the doubled addresses? - list.KasPersons.Remove(list.KasPersons.FirstOrDefault(x => x.refsid == id)); - } - - List toRemove = new List(); - foreach (var address in list.KasPersons) - { - try - { - if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.NoPLZorPPLZ)) - { - toRemove.Add(address.id); - } - else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PlzNotUsable) && - address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PPlzNotUsable)) - { - toRemove.Add(address.id); - } else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PlzNotUsable) && - address.PersonError.warnings.Contains(AddressCheck.WarningTypes.NoPPLZ)) - { - toRemove.Add(address.id); - } - else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PPlzNotUsable) && - address.PersonError.warnings.Contains(AddressCheck.WarningTypes.NoPLZ)) - { - toRemove.Add(address.id); - } - } - catch - { - Console.WriteLine("PersonError not accessible: " + address.id); - } - } - - // delete doubled addresses by refsid - foreach (int id in toRemove) - { - // does this remove both of the doubled addresses? - list.KasPersons.Remove(list.KasPersons.Find(x => x.id == id)); - } - - //return null; } } \ No newline at end of file