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) { try { 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); } } }