using System; using System.Collections.Generic; using System.Threading.Tasks; using Avalonia.Threading; namespace Logof_Client; public class CombineAddresses { private readonly ProgressWindow _progress; public CombineAddresses(ProgressWindow progressWindow) { _progress = progressWindow; } public async Task Perform(List address_lists) { KasAddressList result = new("Ergebnis_" + DateTime.Now.ToString("ddMMyy_HHmmss")); await Task.Run(async () => { for (var i = 0; i < address_lists.Count; i++) if (i == 0) lock (result) { result = address_lists[i]; } else lock (result) { result = Merge(result, address_lists[i], i + 1, address_lists.Count).Result; } }); return result; } private async Task Merge(KasAddressList first, KasAddressList second, int num, int total) { foreach (var sec in second.KasPersons) { var is_new = true; foreach (var fi in first.KasPersons) { if (fi.refsid == sec.refsid) { is_new = false; break; } if (fi.name == sec.name && fi.anrede == sec.anrede && fi.anredzus == sec.anredzus && fi.namezus == sec.namezus && fi.titel == sec.titel && fi.adel == sec.adel && fi.strasse == sec.strasse && fi.strasse2 == sec.strasse2 && fi.vorname == sec.vorname && fi.ort == sec.ort && fi.land == sec.land && fi.plz == sec.plz && fi.pplz == sec.pplz && fi.funktion == sec.funktion && fi.funktion2 == sec.funktion2 && fi.funktionad == sec.funktionad && fi.abteilung == sec.abteilung && fi.postfach == sec.postfach && fi.name1 == sec.name1 && fi.name2 == sec.name2 && fi.name3 == sec.name3 && fi.name4 == sec.name4 && fi.name5 == sec.name5) { is_new = false; break; } } if (is_new) first.KasPersons.Add(sec); var subperc = second.KasPersons.IndexOf(sec) / second.KasPersons.Count; var percent = (num + (double)subperc) / total * 100; await Dispatcher.UIThread.InvokeAsync(() => { if (is_new) _progress.AddToLog($"Person mit refsid {sec.refsid} ergänzt"); else _progress.AddToLog($"Person mit refsid {sec.refsid} bereits vorhanden"); _progress.ChangePercentage(percent); }); } return first; } /// /// Returns true if the addresses are the same. /// /// First address to compare /// Second address to compare /// If true, only a refsid-check will be done /// public bool CompareAddresses(KasPerson first, KasPerson second, bool only_refsid = false) { if (first.refsid == second.refsid) return true; if (!only_refsid) if (first.name == second.name && first.anrede == second.anrede && first.anredzus == second.anredzus && first.namezus == second.namezus && first.titel == second.titel && first.adel == second.adel && first.strasse == second.strasse && first.strasse2 == second.strasse2 && first.vorname == second.vorname && first.ort == second.ort && first.land == second.land && first.plz == second.plz && first.pplz == second.pplz && first.funktion == second.funktion && first.funktion2 == second.funktion2 && first.funktionad == second.funktionad && first.abteilung == second.abteilung && first.postfach == second.postfach && first.name1 == second.name1 && first.name2 == second.name2 && first.name3 == second.name3 && first.name4 == second.name4 && first.name5 == second.name5) return true; return false; } public async Task Difference() { return null; } public async Task Union() { return null; } public async Task MoveDuplicatesToNew() { return null; } public async Task Intersection() { return null; } public async Task SymmetricDifference() { return null; } }