From 028b9793db6b68ef37f682959de9e924a58a2739 Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Wed, 6 May 2026 06:33:37 +0200 Subject: [PATCH] [chore:] basic address shortener --- Tasks/AddressShortener.cs | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Tasks/AddressShortener.cs diff --git a/Tasks/AddressShortener.cs b/Tasks/AddressShortener.cs new file mode 100644 index 0000000..e7451c3 --- /dev/null +++ b/Tasks/AddressShortener.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Threading.Tasks.Dataflow; + +namespace Logof_Client; + +public class AddressShortener(ProgressWindow progressWindow) +{ + private readonly ProgressWindow _progress = 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++) + { + 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)); + } + + //return null; + } +} \ No newline at end of file