From 9777c6b5a27d3ebf4dd218d86e442817e9c4ce5c Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Wed, 22 Apr 2026 08:09:28 +0200 Subject: [PATCH] [fix:] naming window showed nothing --- DataStore/DataStructures.cs | 12 ++++++--- MainWindow.axaml.cs | 10 +++---- NamingWindow.axaml.cs | 9 +++---- Tasks/CombineAddresses.cs | 53 ++++++++++--------------------------- Tasks/DataImport.cs | 19 ++++++------- 5 files changed, 41 insertions(+), 62 deletions(-) diff --git a/DataStore/DataStructures.cs b/DataStore/DataStructures.cs index 6c81528..b082d93 100644 --- a/DataStore/DataStructures.cs +++ b/DataStore/DataStructures.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace Logof_Client; @@ -32,11 +33,16 @@ public class KasAddressList //Address-Set this.owner_id = owner_id; } - public static string GenerateName(string basic_type, bool? is_rest = false) + public static async Task GenerateName(string basic_type, bool? is_rest = false) { + string pre = ""; + if (is_rest == true) return basic_type + " - " + DateTime.Now.ToShortDateString() + " - Rest"; - return basic_type + " - " + DateTime.Now.ToShortDateString(); + pre = basic_type + " - " + DateTime.Now.ToShortDateString(); + + var result = await NamingWindow.Show(MainWindow._instance, pre); + return string.IsNullOrWhiteSpace(result) ? pre : result; } // public void UpdateErrorList(List errorList) @@ -206,4 +212,4 @@ public class KasPersonError return output; } -} \ No newline at end of file +} diff --git a/MainWindow.axaml.cs b/MainWindow.axaml.cs index 31d9dbb..1d826de 100644 --- a/MainWindow.axaml.cs +++ b/MainWindow.axaml.cs @@ -194,7 +194,7 @@ public partial class MainWindow : Window private async void StartCombine(Uri path) { MakeCalcManVisible(); - var addresses = DataImport.ImportKasAddressList(path); + var addresses = await DataImport.ImportKasAddressList(path); var progressWindow = new ProgressWindow(); var address_list = new List { addresses.Item2 }; @@ -216,7 +216,7 @@ public partial class MainWindow : Window if (file == null) return; //filePath = file[0].Path; - foreach (var f in file) address_list.Add(DataImport.ImportKasAddressList(f.Path).Item2); + foreach (var f in file) address_list.Add((await DataImport.ImportKasAddressList(f.Path)).Item2); progressWindow.Show(_instance); @@ -542,7 +542,7 @@ public partial class MainWindow : Window { if (customer.patch == null) { - var got = DataImport.ImportKasAddressList(selected_path, null, customer.separator); + var got = await DataImport.ImportKasAddressList(selected_path, null, customer.separator); if (!got.Item1) { Console.WriteLine("Error while importing. Please try another file."); @@ -558,7 +558,7 @@ public partial class MainWindow : Window } else { - var got = DataImport.ImportKasAddressList(selected_path, customer.patch, customer.separator); + var got = await DataImport.ImportKasAddressList(selected_path, customer.patch, customer.separator); if (!got.Item1) { Console.WriteLine("Error while importing. Please try another file."); @@ -933,4 +933,4 @@ public partial class MainWindow : Window MessageBox.Show(this, ex.StackTrace, "Fehler"); } } -} \ No newline at end of file +} diff --git a/NamingWindow.axaml.cs b/NamingWindow.axaml.cs index 12c7bc0..3cf6f34 100644 --- a/NamingWindow.axaml.cs +++ b/NamingWindow.axaml.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Avalonia.Controls; -using Avalonia.Markup.Xaml; namespace Logof_Client; @@ -9,9 +8,7 @@ public partial class NamingWindow : Window { public NamingWindow() { - AvaloniaXamlLoader.Load(this); - - //InitializeComponent(); + InitializeComponent(); } public static Task Show(Window parent, string input = "", string info = "Bitte geben Sie einen Namen ein:") @@ -54,7 +51,7 @@ public partial class NamingWindow : Window catch (Exception ex) { Console.WriteLine("Error while showing naming window: " + ex.Message); - return null; + return Task.FromResult(null!); } } -} \ No newline at end of file +} diff --git a/Tasks/CombineAddresses.cs b/Tasks/CombineAddresses.cs index 140a6f7..e20a194 100644 --- a/Tasks/CombineAddresses.cs +++ b/Tasks/CombineAddresses.cs @@ -19,36 +19,11 @@ public class CombineAddresses public async Task<(KasAddressList, KasAddressList)> Perform(List address_lists, string type, bool? exportUnused) { - var res = await Task.Run(async () => - { - if (type == "difference") return Difference(address_lists, exportUnused); - if (type == "union") return Union(address_lists, exportUnused); - if (type == "intersection") return Intersection(address_lists, exportUnused); - if (type == "symdiff") return SymmetricDifference(address_lists, exportUnused); + if (type == "difference") return await Difference(address_lists, exportUnused); + if (type == "union") return await Union(address_lists, exportUnused); + if (type == "intersection") return await Intersection(address_lists, exportUnused); + if (type == "symdiff") return await SymmetricDifference(address_lists, exportUnused); - return null; - }); - - - return res.Result; - - - // 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; return (null, null); } @@ -97,7 +72,7 @@ public class CombineAddresses Progress? progress = null) { if (address_lists == null || address_lists.Count == 0) - return (new KasAddressList(KasAddressList.GenerateName("difference")), null); + return (new KasAddressList(await KasAddressList.GenerateName("difference")), null); progress ??= new Progress { @@ -109,8 +84,8 @@ public class CombineAddresses var restUnion = new List(); for (var i = 1; i < address_lists.Count; i++) restUnion.AddRange(address_lists[i].KasPersons); - var result = new KasAddressList(KasAddressList.GenerateName("difference")); - var second_result = new KasAddressList(KasAddressList.GenerateName("difference_rest")); + var result = new KasAddressList(await KasAddressList.GenerateName("difference")); + var second_result = new KasAddressList(await KasAddressList.GenerateName("difference_rest", false)); foreach (var person in address_lists[0].KasPersons) { @@ -136,8 +111,8 @@ public class CombineAddresses public async Task<(KasAddressList, KasAddressList)> Union(List address_lists, bool? return_unused, Progress progress = null) { - var result = new KasAddressList(KasAddressList.GenerateName("union")); - var second_result = new KasAddressList(KasAddressList.GenerateName("union_rest")); + var result = new KasAddressList(await KasAddressList.GenerateName("union")); + var second_result = new KasAddressList(await KasAddressList.GenerateName("union_rest", false)); if (address_lists == null || address_lists.Count == 0) return (result, null); @@ -178,8 +153,8 @@ public class CombineAddresses public async Task<(KasAddressList, KasAddressList)> Intersection(List address_lists, bool? return_unused, Progress progress = null) { - var result = new KasAddressList(KasAddressList.GenerateName("intersection")); - var second_result = new KasAddressList(KasAddressList.GenerateName("intersection_rest")); + var result = new KasAddressList(await KasAddressList.GenerateName("intersection")); + var second_result = new KasAddressList(await KasAddressList.GenerateName("intersection_rest", false)); if (address_lists == null || address_lists.Count == 0) return (result, null); @@ -225,8 +200,8 @@ public class CombineAddresses public async Task<(KasAddressList, KasAddressList)> SymmetricDifference(List address_lists, bool? return_unused, Progress progress = null) { - var result = new KasAddressList(KasAddressList.GenerateName("symmetric_difference")); - var second_result = new KasAddressList(KasAddressList.GenerateName("symmetric_rest")); + var result = new KasAddressList(await KasAddressList.GenerateName("symmetric_difference")); + var second_result = new KasAddressList(await KasAddressList.GenerateName("symmetric_rest", false)); if (address_lists == null || address_lists.Count == 0) return (result, null); @@ -354,4 +329,4 @@ public class Progress var comparedPersons = ComparedPersons; Interlocked.Increment(ref comparedPersons); } -} \ No newline at end of file +} diff --git a/Tasks/DataImport.cs b/Tasks/DataImport.cs index d7e5940..d2961f6 100644 --- a/Tasks/DataImport.cs +++ b/Tasks/DataImport.cs @@ -4,20 +4,21 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; +using System.Threading.Tasks; namespace Logof_Client; public class DataImport { - public static (bool, KasAddressList) ImportKasAddressList(Uri pathToCsv, AddressPatch patch = null, + public static async Task<(bool, KasAddressList)> ImportKasAddressList(Uri pathToCsv, AddressPatch patch = null, char separator = ',') { if (patch == null) - return ImportKasAddressListWithoutPatch(pathToCsv, separator); - return ImportKasAddressListWithPatch(pathToCsv, patch, separator); + return await ImportKasAddressListWithoutPatch(pathToCsv, separator); + return await ImportKasAddressListWithPatch(pathToCsv, patch, separator); } - private static (bool, KasAddressList) ImportKasAddressListWithoutPatch(Uri pathToCsv, char separator) + private static async Task<(bool, KasAddressList)> ImportKasAddressListWithoutPatch(Uri pathToCsv, char separator) { if (!File.Exists(pathToCsv.LocalPath)) { @@ -33,8 +34,8 @@ public class DataImport return (false, null); } - var imported = - new KasAddressList(KasAddressList.GenerateName(Path.GetFileNameWithoutExtension(pathToCsv.LocalPath))); + var imported = new KasAddressList( + await KasAddressList.GenerateName(Path.GetFileNameWithoutExtension(pathToCsv.LocalPath))); while (!reader.EndOfStream) { @@ -91,7 +92,7 @@ public class DataImport return (true, imported); } - private static (bool, KasAddressList) ImportKasAddressListWithPatch(Uri pathToCsv, AddressPatch patch, + private static async Task<(bool, KasAddressList)> ImportKasAddressListWithPatch(Uri pathToCsv, AddressPatch patch, char separator) { if (!File.Exists(pathToCsv.LocalPath)) @@ -110,8 +111,8 @@ public class DataImport var headers = ParseCsvLine(headerLine, separator); - var imported = - new KasAddressList(KasAddressList.GenerateName(Path.GetFileNameWithoutExtension(pathToCsv.LocalPath))); + var imported = new KasAddressList( + await KasAddressList.GenerateName(Path.GetFileNameWithoutExtension(pathToCsv.LocalPath))); var patchType = typeof(AddressPatch); var binding = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase;