From 86ce7e89e1fe6ffa7b1b730418f7c5750c6d48ed Mon Sep 17 00:00:00 2001 From: Meik Date: Fri, 13 Feb 2026 09:30:46 +0100 Subject: [PATCH] Logging --- .../Models/TicketOverviewSettingsProvider.cs | 17 +- .../Services/TicketOverviewUpdateService.cs | 116 +++++++---- .../UserControls/TicketOverview.xaml.cs | 190 ++++++++++++------ .../Pages/SearchPage/SearchPageView.xaml.cs | 42 ++-- 4 files changed, 238 insertions(+), 127 deletions(-) diff --git a/FasdDesktopUi/Basics/Services/Models/TicketOverviewSettingsProvider.cs b/FasdDesktopUi/Basics/Services/Models/TicketOverviewSettingsProvider.cs index 0026f8e..106ab8f 100644 --- a/FasdDesktopUi/Basics/Services/Models/TicketOverviewSettingsProvider.cs +++ b/FasdDesktopUi/Basics/Services/Models/TicketOverviewSettingsProvider.cs @@ -1,6 +1,8 @@ using System; -using System.Diagnostics; +using System.Reflection; using C4IT.FASD.Base; +using C4IT.Logging; +using static C4IT.Logging.cLogManager; namespace FasdDesktopUi.Basics.Services.Models { @@ -13,6 +15,13 @@ namespace FasdDesktopUi.Basics.Services.Models { public int GetPollingMinutes(TileScope scope) { + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) + { + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); + } + int minutes = scope == TileScope.Role ? cF4sdTicketConfig.DefaultOverviewPollingRole : cF4sdTicketConfig.DefaultOverviewPollingPersonal; @@ -29,7 +38,11 @@ namespace FasdDesktopUi.Basics.Services.Models } catch (Exception ex) { - Debug.WriteLine($"[TicketOverview] Settings fallback to defaults: {ex.Message}"); + LogException(ex); + } + finally + { + LogMethodEnd(CM); } if (minutes < 1) diff --git a/FasdDesktopUi/Basics/Services/TicketOverviewUpdateService.cs b/FasdDesktopUi/Basics/Services/TicketOverviewUpdateService.cs index 16636b0..4a9b4aa 100644 --- a/FasdDesktopUi/Basics/Services/TicketOverviewUpdateService.cs +++ b/FasdDesktopUi/Basics/Services/TicketOverviewUpdateService.cs @@ -1,19 +1,22 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Threading; using C4IT.FASD.Base; using C4IT.FASD.Cockpit.Communication; +using C4IT.Logging; using FasdDesktopUi.Basics.Models; using FasdDesktopUi.Basics.Services.Models; -#if isDemo -using System.Net; -using FasdCockpitCommunicationDemo; -using System.Text.RegularExpressions; -#endif +#if isDemo +using System.Net; +using FasdCockpitCommunicationDemo; +using System.Text.RegularExpressions; +#endif +using static C4IT.Logging.cLogManager; namespace FasdDesktopUi.Basics.Services { @@ -304,18 +307,25 @@ namespace FasdDesktopUi.Basics.Services private async Task FetchScopeAsync(TileScope scope) { - if (!_isEnabled) - return; - - var communication = _communicationSource.Resolve(); - if (communication == null) + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) { - ScheduleFetchRetry(scope); - return; + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); } try { + if (!_isEnabled) + return; + + var communication = _communicationSource.Resolve(); + if (communication == null) + { + ScheduleFetchRetry(scope); + return; + } + _isDemo = communication.IsDemo(); var rawCounts = await communication.GetTicketOverviewCounts(OverviewKeys, scope == TileScope.Role).ConfigureAwait(false); @@ -339,9 +349,13 @@ namespace FasdDesktopUi.Basics.Services } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"[TicketOverview] Fetch {scope} failed: {ex}"); + LogException(ex); ScheduleFetchRetry(scope); } + finally + { + LogMethodEnd(CM); + } } #endregion @@ -790,41 +804,59 @@ namespace FasdDesktopUi.Basics.Services private void ScheduleFetchRetry(TileScope scope) { - if (!_isEnabled) - return; - - lock (_retryScopes) + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) { - _retryScopes.Add(scope); - if (_retryScheduled) - return; - - _retryScheduled = true; + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); } - _ = _dispatcher.InvokeAsync(async () => + try { - try - { - await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); - TileScope[] scopes; - lock (_retryScopes) - { - scopes = _retryScopes.ToArray(); - _retryScopes.Clear(); - _retryScheduled = false; - } + if (!_isEnabled) + return; - foreach (var pendingScope in scopes) - { - await FetchAsync(pendingScope).ConfigureAwait(false); - } - } - catch (Exception ex) + lock (_retryScopes) { - System.Diagnostics.Debug.WriteLine($"[TicketOverview] Retry scheduling failed: {ex}"); + _retryScopes.Add(scope); + if (_retryScheduled) + return; + + _retryScheduled = true; } - }); + + _ = _dispatcher.InvokeAsync(async () => + { + try + { + await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); + TileScope[] scopes; + lock (_retryScopes) + { + scopes = _retryScopes.ToArray(); + _retryScopes.Clear(); + _retryScheduled = false; + } + + foreach (var pendingScope in scopes) + { + await FetchAsync(pendingScope).ConfigureAwait(false); + } + } + catch (Exception ex) + { + LogException(ex); + } + }); + } + catch (Exception ex) + { + LogException(ex); + } + finally + { + LogMethodEnd(CM); + } } #endregion diff --git a/FasdDesktopUi/Basics/UserControls/TicketOverview.xaml.cs b/FasdDesktopUi/Basics/UserControls/TicketOverview.xaml.cs index 5d0d0ce..c630c10 100644 --- a/FasdDesktopUi/Basics/UserControls/TicketOverview.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/TicketOverview.xaml.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -9,10 +9,12 @@ using System.Windows.Input; using System.Windows.Threading; using C4IT.FASD.Cockpit.Communication; +using C4IT.Logging; using FasdDesktopUi.Basics.Models; using FasdDesktopUi.Basics.Services; using FasdDesktopUi.Basics.Services.Models; using FasdDesktopUi.Pages.SearchPage; +using static C4IT.Logging.cLogManager; namespace FasdDesktopUi.Basics.UserControls { public partial class TicketOverview : UserControl @@ -176,27 +178,45 @@ namespace FasdDesktopUi.Basics.UserControls #region Methods private async void TicketOverview_Loaded(object sender, RoutedEventArgs e) { - if (_isInitialized) - return; - - _isInitialized = true; - - bool filter = SearchPageView.Instance?.IsFilterChecked == true; - await UpdateDataContextAsync(filter); - - if (SearchPageView.Instance != null) + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) { - SearchPageView.Instance.FilterToggleCheckedChanged += async (s, isChecked) => + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); + } + + try + { + if (_isInitialized) + return; + + _isInitialized = true; + + bool filter = SearchPageView.Instance?.IsFilterChecked == true; + await UpdateDataContextAsync(filter); + + if (SearchPageView.Instance != null) { - try + SearchPageView.Instance.FilterToggleCheckedChanged += async (s, isChecked) => { - await UpdateDataContextAsync(isChecked); - } - catch (Exception ex) - { - Debug.WriteLine($"[TicketOverview] Refresh after toggle failed: {ex}"); - } - }; + try + { + await UpdateDataContextAsync(isChecked); + } + catch (Exception ex) + { + LogException(ex); + } + }; + } + } + catch (Exception E) + { + LogException(E); + } + finally + { + LogMethodEnd(CM); } } @@ -218,67 +238,105 @@ namespace FasdDesktopUi.Basics.UserControls private async Task RefreshCountsAsync(bool useRoleTickets) { - Dictionary counts = null; - var service = TicketOverviewUpdateService.Instance; - - if (service != null) + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) { - try - { - var scope = useRoleTickets ? TileScope.Role : TileScope.Personal; - await service.FetchAsync(scope).ConfigureAwait(false); - counts = service.GetCountsForScope(useRoleTickets); - } - catch (Exception ex) - { - Debug.WriteLine($"[TicketOverview] Service refresh failed: {ex}"); - counts = null; - } + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); } - if (counts == null || counts.Count == 0) - counts = await LoadCountsFallbackAsync(useRoleTickets).ConfigureAwait(false); - - await Dispatcher.InvokeAsync(() => + Dictionary counts = null; + try { - foreach (var (key, setter) in CategorySetters) + var service = TicketOverviewUpdateService.Instance; + + if (service != null) { - counts.TryGetValue(key, out var value); - setter(_viewModel, value); + try + { + var scope = useRoleTickets ? TileScope.Role : TileScope.Personal; + await service.FetchAsync(scope).ConfigureAwait(false); + counts = service.GetCountsForScope(useRoleTickets); + } + catch (Exception ex) + { + LogException(ex); + counts = null; + } } - _viewModel.ResetSelection(); - SearchPageView.Instance?.CloseTicketOverviewResults(); - UpdateHighlightState(useRoleTickets); - }, DispatcherPriority.Background); + if (counts == null || counts.Count == 0) + counts = await LoadCountsFallbackAsync(useRoleTickets).ConfigureAwait(false); + + await Dispatcher.InvokeAsync(() => + { + foreach (var (key, setter) in CategorySetters) + { + counts.TryGetValue(key, out var value); + setter(_viewModel, value); + } + + _viewModel.ResetSelection(); + SearchPageView.Instance?.CloseTicketOverviewResults(); + UpdateHighlightState(useRoleTickets); + }, DispatcherPriority.Background); + } + catch (Exception E) + { + LogException(E); + } + finally + { + LogMethodEnd(CM); + } } private async Task> LoadCountsFallbackAsync(bool useRoleTickets) { - var counts = CategorySetters.ToDictionary(item => item.Key, _ => 0); - var communication = cFasdCockpitCommunicationBase.Instance; - if (communication == null) - return counts; - - var tasks = CategorySetters.ToDictionary( - item => item.Key, - item => communication.GetTicketOverviewRelations(item.Key, useRoleTickets, 0)); - - foreach (var kvp in tasks) + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) { - try - { - var relations = await kvp.Value.ConfigureAwait(false); - counts[kvp.Key] = relations?.Count ?? 0; - } - catch (Exception ex) - { - Debug.WriteLine($"[TicketOverview] Fallback load failed for '{kvp.Key}': {ex}"); - counts[kvp.Key] = 0; - } + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); } - return counts; + try + { + var counts = CategorySetters.ToDictionary(item => item.Key, _ => 0); + var communication = cFasdCockpitCommunicationBase.Instance; + if (communication == null) + return counts; + + var tasks = CategorySetters.ToDictionary( + item => item.Key, + item => communication.GetTicketOverviewRelations(item.Key, useRoleTickets, 0)); + + foreach (var kvp in tasks) + { + try + { + var relations = await kvp.Value.ConfigureAwait(false); + counts[kvp.Key] = relations?.Count ?? 0; + } + catch (Exception ex) + { + LogException(ex); + counts[kvp.Key] = 0; + } + } + + return counts; + } + catch (Exception E) + { + LogException(E); + } + finally + { + LogMethodEnd(CM); + } + + return CategorySetters.ToDictionary(item => item.Key, _ => 0); } public void UpdateCounts(IDictionary counts, bool useRoleTickets) diff --git a/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml.cs b/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml.cs index 7839d56..c636e26 100644 --- a/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml.cs +++ b/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml.cs @@ -1400,13 +1400,20 @@ namespace FasdDesktopUi.Pages.SearchPage { LogException(ex); } - } - private async void TicketOverview_SelectionRequested(object sender, TicketOverviewSelectionRequestedEventArgs e) - { - try - { - var app = Application.Current as FasdDesktopUi.App; - app?.ClearTicketOverviewTrayNotification(); + } + private async void TicketOverview_SelectionRequested(object sender, TicketOverviewSelectionRequestedEventArgs e) + { + MethodBase CM = null; + if (cLogManager.DefaultLogger.IsDebug) + { + CM = MethodBase.GetCurrentMethod(); + LogMethodBegin(CM); + } + + try + { + var app = Application.Current as FasdDesktopUi.App; + app?.ClearTicketOverviewTrayNotification(); _renderTicketOverviewUserNames = true; SetSearchHistoryVisibility(false); @@ -1418,14 +1425,13 @@ namespace FasdDesktopUi.Pages.SearchPage ShowLoadingTextItem(cMultiLanguageSupport.GetItem("Searchbar.Loading.CaseData")); SetPendingInformationClasses(new HashSet { enumFasdInformationClass.Ticket }); - + var relations = await LoadRelationsForTileAsync(e.Key, e.UseRoleScope, Math.Max(0, e.Count)); await PopulateTicketOverviewRelationUsersAsync(relations); - Debug.WriteLine($"[TicketOverview] Relations loaded: {relations?.Count ?? 0}"); var firstRelation = relations.FirstOrDefault(); string displayText = header; if (firstRelation != null) - { + { string firstSummary = null; if (firstRelation.Infos != null && firstRelation.Infos.TryGetValue("Summary", out var summaryValue)) { @@ -1482,13 +1488,15 @@ namespace FasdDesktopUi.Pages.SearchPage UpdatePendingInformationClasses(new HashSet()); } catch (Exception ex) - { - LogException(ex); - CancledSearchAction(); - } - System.Diagnostics.Debug.WriteLine( - $"[TicketOverview] Key={e.Key}, UseRoleScope={e.UseRoleScope}, Count={e.Count}"); - } + { + LogException(ex); + CancledSearchAction(); + } + finally + { + LogMethodEnd(CM); + } + } private string BuildHeaderText(string key, bool useRoleScope, int? count = null) { string scopeKey = useRoleScope ? "Searchbar.Header.Scope.Role" : "Searchbar.Header.Scope.Personal";