[chore:] basic logging

This commit is contained in:
2026-05-16 14:41:16 +02:00
parent 6f03a26c29
commit 6dfab5e73a
+222 -166
View File
@@ -24,14 +24,18 @@ public partial class MainWindow : Window
public MainWindow()
{
Logger.Log("Welcome to logofclient");
Logger.Log($"Session on {DateTime.Now:G}");
Logger.Log("Initializing...");
InitializeComponent();
//Hide();
var s = new StartupWindow();
//s.Show();
_instance = this;
WindowState = WindowState.Maximized;
Logger.Log("Loading settings...");
Global.Load();
Settings.Load();
LoadPdfExportOptions();
@@ -40,6 +44,7 @@ public partial class MainWindow : Window
RefreshCountryView();
// Initialize wiki integration
Logger.Log("Buliding wiki...");
_wikiService = new WikiService();
try
{
@@ -54,8 +59,9 @@ public partial class MainWindow : Window
if (!string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path))
TbWikiPath.Text = Global._instance.wiki_storage_path;
}
catch
catch (Exception ex)
{
Logger.Log($"Error while setting paths: {ex.Message}", Logger.LogType.Error);
}
try
@@ -64,12 +70,14 @@ public partial class MainWindow : Window
BtnFontPath.Click += BtnFontPath_Click;
BtnConfigPath.Click += BtnConfigPath_Click;
}
catch
catch (Exception ex)
{
Logger.Log($"Error while adding click functions?: {ex.Message}", Logger.LogType.Error);
}
}
catch
catch (Exception ex)
{
Logger.Log($"Error while doing wiki stuff: {ex.Message}", Logger.LogType.Error);
}
//Thread.Sleep(3000);
@@ -120,24 +128,7 @@ public partial class MainWindow : Window
Settings.Save();
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
}
// private async void StartAddressRepair(Uri path)
// {
// var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier
// var progressWindow = new ProgressWindow();
//
// progressWindow.Show(_instance);
//
// var processor = new AddressRepair(progressWindow);
// //var result = await processor.Perform(addresses.Item2, errors);
//
//
// progressWindow.Close();
//
//
// //new ResultWindow(result, addresses.Item2).Show();
// //await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
// }
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
{
@@ -156,7 +147,7 @@ public partial class MainWindow : Window
}
catch (Exception ex)
{
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
Logger.Log($"Error while starting process: {ex.Message}", Logger.LogType.Error);
}
}
@@ -172,7 +163,7 @@ public partial class MainWindow : Window
}
catch (Exception ex)
{
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
Logger.Log($"Error while starting process: {ex.Message}", Logger.LogType.Error);
}
}
@@ -188,7 +179,7 @@ public partial class MainWindow : Window
}
catch (Exception ex)
{
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
Logger.Log($"Error while starting process: {ex.Message}", Logger.LogType.Error);
}
}
@@ -232,13 +223,13 @@ public partial class MainWindow : Window
var rendered = MarkdownRenderer.Render(text ?? string.Empty);
PreviewPanel.Children.Add(rendered);
}
catch
catch (Exception ex)
{
// fallback: plain text
Logger.Log($"Error while rendering markdown: {ex.Message}", Logger.LogType.Error);
PreviewPanel.Children.Clear();
PreviewPanel.Children.Add(new TextBlock { Text = text ?? string.Empty });
}
EditButton.IsEnabled = true;
}
else
@@ -250,18 +241,24 @@ public partial class MainWindow : Window
public void PopulateNavTree(string? expandToPath = null, string? selectPath = null)
{
var roots = _wikiService.GetRootItems();
var nodes = new List<TreeViewItem>();
foreach (var r in roots) nodes.Add(BuildNode(r));
NavTree.ItemsSource = nodes;
try
{
var roots = _wikiService.GetRootItems();
var nodes = new List<TreeViewItem>();
foreach (var r in roots) nodes.Add(BuildNode(r));
NavTree.ItemsSource = nodes;
if (!string.IsNullOrWhiteSpace(expandToPath))
ExpandAndFindNode(nodes, expandToPath, out _);
if (!string.IsNullOrWhiteSpace(expandToPath))
ExpandAndFindNode(nodes, expandToPath, out _);
if (!string.IsNullOrWhiteSpace(selectPath) &&
ExpandAndFindNode(nodes, selectPath, out var selectedNode) &&
selectedNode != null)
NavTree.SelectedItem = selectedNode;
if (!string.IsNullOrWhiteSpace(selectPath) &&
ExpandAndFindNode(nodes, selectPath, out var selectedNode) &&
selectedNode != null)
NavTree.SelectedItem = selectedNode;
}catch (Exception ex)
{
Logger.Log($"Error while populating nav tree: {ex.Message}", Logger.LogType.Error);
}
}
private TreeViewItem BuildNode(WikiItem item)
@@ -276,16 +273,23 @@ public partial class MainWindow : Window
private string GetSelectedWikiTargetDirectory()
{
var wikiRoot = Global._instance.wiki_storage_path;
if (NavTree.SelectedItem is TreeViewItem treeItem && treeItem.Tag is WikiItem selectedItem)
try
{
if (selectedItem.IsFolder) return selectedItem.Path;
var wikiRoot = Global._instance.wiki_storage_path;
if (NavTree.SelectedItem is TreeViewItem treeItem && treeItem.Tag is WikiItem selectedItem)
{
if (selectedItem.IsFolder) return selectedItem.Path;
var parentDir = Path.GetDirectoryName(selectedItem.Path);
if (!string.IsNullOrWhiteSpace(parentDir)) return parentDir;
var parentDir = Path.GetDirectoryName(selectedItem.Path);
if (!string.IsNullOrWhiteSpace(parentDir)) return parentDir;
}
return wikiRoot;
}catch (Exception ex)
{
Logger.Log($"Error while getting selected wiki target directory: {ex.Message}", Logger.LogType.Error);
}
return wikiRoot;
return null;
}
private static bool PathsEqual(string left, string right)
@@ -344,8 +348,9 @@ public partial class MainWindow : Window
UseShellExecute = true
});
}
catch
catch (Exception ex)
{
Logger.Log($"Error while starting process: {ex.Message}", Logger.LogType.Error);
}
}
@@ -443,8 +448,9 @@ public partial class MainWindow : Window
{
LstSettingsCustomers.SelectedIndex = LstSettingsCustomers.Items.Count - 1;
}
catch
catch (Exception ex)
{
Logger.Log($"Error while setting selected item: {ex.Message}", Logger.LogType.Error);
}
}
@@ -515,17 +521,25 @@ public partial class MainWindow : Window
{
LstSettingsCustomers.SelectedIndex = index;
}
catch
catch (Exception ex)
{
Logger.Log($"Error while setting selected index: {ex.Message}", Logger.LogType.Error);
}
}
private void TbSettingsCustomerDescription_OnTextChanged(object? sender, TextChangedEventArgs e)
{
if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return;
foreach (var customer in Settings._instance.customers.customers)
if (customer.ID == Settings._instance.customers.current.ID)
customer.description = TbSettingsCustomerDescription.Text;
try
{
if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return;
foreach (var customer in Settings._instance.customers.customers)
if (customer.ID == Settings._instance.customers.current.ID)
customer.description = TbSettingsCustomerDescription.Text;
} catch (Exception ex)
{
Logger.Log($"Error while changing customer description: {ex.Message}", Logger.LogType.Error);
}
//Settings.Save();
}
@@ -545,63 +559,72 @@ public partial class MainWindow : Window
private async void BtnCustomerAddressSetImport_OnClick(object? sender, RoutedEventArgs e)
{
MakeCalcManVisible();
var opts = new FilePickerOpenOptions();
opts.Title = "Address-Set importieren...";
opts.AllowMultiple = false;
var type = new FilePickerFileType("CSV-Dateien (*.csv)");
type.Patterns = new[] { "*.csv" };
opts.FileTypeFilter = new[] { type };
var paths = await StorageProvider.OpenFilePickerAsync(opts);
if (paths?.Count <= 0) return;
if (LstCustomers.SelectedIndex < 0) return;
var selected_path = paths[0].Path;
foreach (var customer in Settings._instance.customers.customers)
if (customer == ((Customer)LstCustomers.SelectedItems[0]))
{
if (customer.patch == null)
{
var got = await DataImport.ImportKasAddressList(selected_path, null, customer.separator);
if (!got.Item1)
{
Console.WriteLine("Error while importing. Please try another file.");
}
else
{
got.Item2.SetOwner(customer.ID);
Settings._instance.addressSets.addresses.Add(got.Item2);
}
//var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]);
RefreshAddressSetListItems(customer.ID);
}
else
{
var got = await DataImport.ImportKasAddressList(selected_path, customer.patch, customer.separator);
if (!got.Item1)
{
Console.WriteLine("Error while importing. Please try another file.");
}
else
{
got.Item2.SetOwner(customer.ID);
Settings._instance.addressSets.addresses.Add(got.Item2);
}
//var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]);
RefreshAddressSetListItems(customer.ID);
}
}
Settings.Save();
try
{
MakeCalcManVisible();
var opts = new FilePickerOpenOptions();
opts.Title = "Address-Set importieren...";
opts.AllowMultiple = false;
var type = new FilePickerFileType("CSV-Dateien (*.csv)");
type.Patterns = new[] { "*.csv" };
opts.FileTypeFilter = new[] { type };
var paths = await StorageProvider.OpenFilePickerAsync(opts);
if (paths?.Count <= 0) return;
if (LstCustomers.SelectedIndex < 0) return;
var selected_path = paths[0].Path;
foreach (var customer in Settings._instance.customers.customers)
if (customer == ((Customer)LstCustomers.SelectedItems[0]))
{
if (customer.patch == null)
{
var got = await DataImport.ImportKasAddressList(selected_path, null, customer.separator);
if (!got.Item1)
{
Console.WriteLine("Error while importing. Please try another file.");
}
else
{
got.Item2.SetOwner(customer.ID);
Settings._instance.addressSets.addresses.Add(got.Item2);
}
//var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]);
RefreshAddressSetListItems(customer.ID);
}
else
{
var got = await DataImport.ImportKasAddressList(selected_path, customer.patch, customer.separator);
if (!got.Item1)
{
Console.WriteLine("Error while importing. Please try another file.");
}
else
{
got.Item2.SetOwner(customer.ID);
Settings._instance.addressSets.addresses.Add(got.Item2);
}
//var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]);
RefreshAddressSetListItems(customer.ID);
}
}
Settings.Save();
}
catch (Exception ex)
{
Logger.Log($"Error while importing: {ex.Message}", Logger.LogType.Error);
}
}
public void RefreshAddressSetListItems(int customer_id)
@@ -647,31 +670,38 @@ public partial class MainWindow : Window
private async void BtnSettingsImportCustomerAddressPatch_OnClick(object? sender, RoutedEventArgs e)
{
if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return;
var opts = new FilePickerOpenOptions();
opts.Title = "Address-Patch für " + LstSettingsCustomers.SelectedItems[0] + "importieren...";
opts.AllowMultiple = false;
var type = new FilePickerFileType("ADPAC-Dateien (*.adpac)");
type.Patterns = new[] { "*.adpac" };
opts.FileTypeFilter = new[] { type };
var paths = await StorageProvider.OpenFilePickerAsync(opts);
if (paths?.Count <= 0) return;
//if (LstSettingsCustomers.SelectedIndex < 0) return;
var selected_path = paths[0].Path;
foreach (var customer in Settings._instance.customers.customers)
if (customer.ID == ((Customer)LstSettingsCustomers.SelectedItems[0]).ID)
customer.patch = AddressPatch.Import(selected_path);
Settings.Save();
try
{
if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return;
var opts = new FilePickerOpenOptions();
opts.Title = "Address-Patch für " + LstSettingsCustomers.SelectedItems[0] + "importieren...";
opts.AllowMultiple = false;
var type = new FilePickerFileType("ADPAC-Dateien (*.adpac)");
type.Patterns = new[] { "*.adpac" };
opts.FileTypeFilter = new[] { type };
var paths = await StorageProvider.OpenFilePickerAsync(opts);
if (paths?.Count <= 0) return;
//if (LstSettingsCustomers.SelectedIndex < 0) return;
var selected_path = paths[0].Path;
foreach (var customer in Settings._instance.customers.customers)
if (customer.ID == ((Customer)LstSettingsCustomers.SelectedItems[0]).ID)
customer.patch = AddressPatch.Import(selected_path);
Settings.Save();
} catch (Exception ex)
{
Logger.Log($"Error while importing customer address patch: {ex.Message}", Logger.LogType.Error);
}
}
private void TbSettingsCustomerCsvSeparator_OnTextChanged(object? sender, TextChangedEventArgs e)
@@ -689,11 +719,14 @@ public partial class MainWindow : Window
catch (FormatException ex)
{
MessageBox.Show(this, "Error while converting: " + ex.Message, "Could not parse");
Logger.Log($"Error while converting: {ex.Message}", Logger.LogType.Error);
}
catch (Exception ex)
{
MessageBox.Show(this, "Unknown Error: " + ex.Message, "Error");
Logger.Log($"Error while converting: {ex.Message}", Logger.LogType.Error);
}
}
private void BtnCombineDifference_OnClick(object? sender, RoutedEventArgs e)
@@ -704,10 +737,9 @@ public partial class MainWindow : Window
try
{
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem), "difference", GetCombiningTyp());
}
catch
}catch (Exception ex)
{
Logger.Log($"Error while combining (difference): {ex.Message}", Logger.LogType.Error);
}
}
@@ -720,9 +752,9 @@ public partial class MainWindow : Window
{
StartCombine(list, Convert.ToInt32((LstCustomers.SelectedItem as Customer).ID), "union", GetCombiningTyp());
}
catch
catch (Exception ex)
{
Logger.Log($"Error while combining (union): {ex.Message}", Logger.LogType.Error);
}
}
@@ -736,9 +768,9 @@ public partial class MainWindow : Window
{
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "intersection", GetCombiningTyp());
}
catch
catch (Exception ex)
{
Logger.Log($"Error while combining (intersection): {ex.Message}", Logger.LogType.Error);
}
}
@@ -815,37 +847,53 @@ public partial class MainWindow : Window
Console.WriteLine("PDF OK");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
File.WriteAllText("crash.txt", ex.ToString());
Logger.Log($"Error while generating labels: {ex.Message}", Logger.LogType.Error);
}
}
private void HookPdfExportOptionEvents()
{
var controls = GetPdfExportControls();
foreach (var control in controls) control.ValueChanged += PdfExportOption_OnValueChanged;
try
{
var controls = GetPdfExportControls();
foreach (var control in controls) control.ValueChanged += PdfExportOption_OnValueChanged;
}
catch (Exception ex)
{
Logger.Log($"Error while hooking pdf export margins: {ex.Message}", Logger.LogType.Error);
}
}
private void LoadPdfExportOptions()
{
var options = Settings._instance.pdfExport ?? new PdfExportSettings();
try
{
var options = Settings._instance.pdfExport ?? new PdfExportSettings();
NudExpMargCellPaddingTop.Value = (decimal)options.cellPaddingTopMm;
NudExpMargCellPaddingBot.Value = (decimal)options.cellPaddingBottomMm;
NudExpMargCellPaddingLeft.Value = (decimal)options.cellPaddingLeftMm;
NudExpMargCellPaddingRight.Value = (decimal)options.cellPaddingRightMm;
NudExpMargCellPaddingTop.Value = (decimal)options.cellPaddingTopMm;
NudExpMargCellPaddingBot.Value = (decimal)options.cellPaddingBottomMm;
NudExpMargCellPaddingLeft.Value = (decimal)options.cellPaddingLeftMm;
NudExpMargCellPaddingRight.Value = (decimal)options.cellPaddingRightMm;
TbExpMargMarginTop.Value = (decimal)options.pageMarginTopMm;
TbExpMargMarginBottom.Value = (decimal)options.pageMarginBottomMm;
TbExpMargMarginLeft.Value = (decimal)options.pageMarginLeftMm;
TbExpMargMarginRight.Value = (decimal)options.pageMarginRightMm;
TbExpMargMarginTop.Value = (decimal)options.pageMarginTopMm;
TbExpMargMarginBottom.Value = (decimal)options.pageMarginBottomMm;
TbExpMargMarginLeft.Value = (decimal)options.pageMarginLeftMm;
TbExpMargMarginRight.Value = (decimal)options.pageMarginRightMm;
TbExpMargRowsPerPage.Value = options.rowsPerPage;
NudExpMargColumnsPerPage.Value = options.columnsPerPage;
NudExpMargFontSize.Value = (decimal)options.fontSize;
NudExpMargSmallFontSize.Value = (decimal)options.smallFontSize;
TbExpMargRowsPerPage.Value = options.rowsPerPage;
NudExpMargColumnsPerPage.Value = options.columnsPerPage;
NudExpMargFontSize.Value = (decimal)options.fontSize;
NudExpMargSmallFontSize.Value = (decimal)options.smallFontSize;
}
catch (Exception ex)
{
Logger.Log($"Error while loading PDF Export Options: {ex.Message}", Logger.LogType.Error);
}
}
private void SavePdfExportOptions()
@@ -926,6 +974,7 @@ public partial class MainWindow : Window
public void RefreshCountryView()
{
if (_suppressCountryRefresh) return;
try
{
@@ -940,8 +989,9 @@ public partial class MainWindow : Window
{
CountryList.Items.Clear();
}
catch
catch (Exception ex)
{
Logger.Log($"Error while clearing country list: {ex.Message}", Logger.LogType.Error);
}
foreach (var c in Global._instance.countries) CountryList.Items.Add(c.name);
@@ -949,17 +999,19 @@ public partial class MainWindow : Window
{
CountryList.SelectedIndex = country_index;
}
catch
catch (Exception ex)
{
Logger.Log($"Error while setting selected item: {ex.Message}", Logger.LogType.Error);
}
try
{
_selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString());
}
catch
catch (Exception ex)
{
_selectedCountry = null;
Logger.Log($"Error while getting country: {ex.Message}", Logger.LogType.Error);
}
if (_selectedCountry == null) return;
@@ -973,8 +1025,9 @@ public partial class MainWindow : Window
{
LbSettingsAlternatives.SelectedIndex = alt_index;
}
catch
catch (Exception ex)
{
Logger.Log($"Error while setting selected item: {ex.Message}", Logger.LogType.Error);
}
}
finally
@@ -990,9 +1043,9 @@ public partial class MainWindow : Window
{
_selectedCountry.alternatives.Remove(selected.ToString());
}
catch
catch (Exception ex)
{
Console.WriteLine("Error while removing country alternative");
Logger.Log($"Error while removing alternatives: {ex.Message}", Logger.LogType.Error);
}
RefreshCountryView();
@@ -1067,6 +1120,7 @@ public partial class MainWindow : Window
catch (Exception ex)
{
MessageBox.Show(this, ex.StackTrace, "Fehler");
Logger.Log($"Error while adding wiki file: {ex.Message}", Logger.LogType.Error);
}
}
@@ -1090,6 +1144,7 @@ public partial class MainWindow : Window
catch (Exception ex)
{
MessageBox.Show(this, ex.StackTrace, "Fehler");
Logger.Log($"Error while adding wiki folder: {ex.Message}", Logger.LogType.Error);
}
}
@@ -1116,12 +1171,12 @@ public partial class MainWindow : Window
curr_set.Name = result;
Settings.Save();
RefreshAddressSetListItems(cus_id);
return;
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.StackTrace, "Fehler");
Logger.Log($"Error while renaming address set: {ex.Message}", Logger.LogType.Error);
}
}
@@ -1135,6 +1190,7 @@ public partial class MainWindow : Window
catch (Exception ex)
{
MessageBox.Show(this, "Unknown Error: " + ex.Message, "Error");
Logger.Log($"Error while deleting customer: {ex.Message}", Logger.LogType.Error);
}
RefreshCustomerItems();
}
@@ -1161,9 +1217,9 @@ public partial class MainWindow : Window
TbSettingsCustomerCsvSeparator.Text = div;
Settings.Save();
}
catch
catch (Exception ex)
{
Console.WriteLine("Error while parsing");
Logger.Log($"Error while changing CSV divider: {ex.Message}", Logger.LogType.Error);
}
}