This commit is contained in:
Meik
2026-02-13 09:30:46 +01:00
parent 352dc42ae7
commit 86ce7e89e1
4 changed files with 238 additions and 127 deletions

View File

@@ -1,6 +1,8 @@
using System; using System;
using System.Diagnostics; using System.Reflection;
using C4IT.FASD.Base; using C4IT.FASD.Base;
using C4IT.Logging;
using static C4IT.Logging.cLogManager;
namespace FasdDesktopUi.Basics.Services.Models namespace FasdDesktopUi.Basics.Services.Models
{ {
@@ -13,6 +15,13 @@ namespace FasdDesktopUi.Basics.Services.Models
{ {
public int GetPollingMinutes(TileScope scope) public int GetPollingMinutes(TileScope scope)
{ {
MethodBase CM = null;
if (cLogManager.DefaultLogger.IsDebug)
{
CM = MethodBase.GetCurrentMethod();
LogMethodBegin(CM);
}
int minutes = scope == TileScope.Role int minutes = scope == TileScope.Role
? cF4sdTicketConfig.DefaultOverviewPollingRole ? cF4sdTicketConfig.DefaultOverviewPollingRole
: cF4sdTicketConfig.DefaultOverviewPollingPersonal; : cF4sdTicketConfig.DefaultOverviewPollingPersonal;
@@ -29,7 +38,11 @@ namespace FasdDesktopUi.Basics.Services.Models
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.WriteLine($"[TicketOverview] Settings fallback to defaults: {ex.Message}"); LogException(ex);
}
finally
{
LogMethodEnd(CM);
} }
if (minutes < 1) if (minutes < 1)

View File

@@ -1,12 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Threading; using System.Windows.Threading;
using C4IT.FASD.Base; using C4IT.FASD.Base;
using C4IT.FASD.Cockpit.Communication; using C4IT.FASD.Cockpit.Communication;
using C4IT.Logging;
using FasdDesktopUi.Basics.Models; using FasdDesktopUi.Basics.Models;
using FasdDesktopUi.Basics.Services.Models; using FasdDesktopUi.Basics.Services.Models;
#if isDemo #if isDemo
@@ -14,6 +16,7 @@ using System.Net;
using FasdCockpitCommunicationDemo; using FasdCockpitCommunicationDemo;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
#endif #endif
using static C4IT.Logging.cLogManager;
namespace FasdDesktopUi.Basics.Services namespace FasdDesktopUi.Basics.Services
{ {
@@ -304,18 +307,25 @@ namespace FasdDesktopUi.Basics.Services
private async Task FetchScopeAsync(TileScope scope) private async Task FetchScopeAsync(TileScope scope)
{ {
if (!_isEnabled) MethodBase CM = null;
return; if (cLogManager.DefaultLogger.IsDebug)
var communication = _communicationSource.Resolve();
if (communication == null)
{ {
ScheduleFetchRetry(scope); CM = MethodBase.GetCurrentMethod();
return; LogMethodBegin(CM);
} }
try try
{ {
if (!_isEnabled)
return;
var communication = _communicationSource.Resolve();
if (communication == null)
{
ScheduleFetchRetry(scope);
return;
}
_isDemo = communication.IsDemo(); _isDemo = communication.IsDemo();
var rawCounts = await communication.GetTicketOverviewCounts(OverviewKeys, scope == TileScope.Role).ConfigureAwait(false); var rawCounts = await communication.GetTicketOverviewCounts(OverviewKeys, scope == TileScope.Role).ConfigureAwait(false);
@@ -339,9 +349,13 @@ namespace FasdDesktopUi.Basics.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
System.Diagnostics.Debug.WriteLine($"[TicketOverview] Fetch {scope} failed: {ex}"); LogException(ex);
ScheduleFetchRetry(scope); ScheduleFetchRetry(scope);
} }
finally
{
LogMethodEnd(CM);
}
} }
#endregion #endregion
@@ -790,41 +804,59 @@ namespace FasdDesktopUi.Basics.Services
private void ScheduleFetchRetry(TileScope scope) private void ScheduleFetchRetry(TileScope scope)
{ {
if (!_isEnabled) MethodBase CM = null;
return; if (cLogManager.DefaultLogger.IsDebug)
lock (_retryScopes)
{ {
_retryScopes.Add(scope); CM = MethodBase.GetCurrentMethod();
if (_retryScheduled) LogMethodBegin(CM);
return;
_retryScheduled = true;
} }
_ = _dispatcher.InvokeAsync(async () => try
{ {
try if (!_isEnabled)
{ return;
await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
TileScope[] scopes;
lock (_retryScopes)
{
scopes = _retryScopes.ToArray();
_retryScopes.Clear();
_retryScheduled = false;
}
foreach (var pendingScope in scopes) lock (_retryScopes)
{
await FetchAsync(pendingScope).ConfigureAwait(false);
}
}
catch (Exception ex)
{ {
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 #endregion

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@@ -9,10 +9,12 @@ using System.Windows.Input;
using System.Windows.Threading; using System.Windows.Threading;
using C4IT.FASD.Cockpit.Communication; using C4IT.FASD.Cockpit.Communication;
using C4IT.Logging;
using FasdDesktopUi.Basics.Models; using FasdDesktopUi.Basics.Models;
using FasdDesktopUi.Basics.Services; using FasdDesktopUi.Basics.Services;
using FasdDesktopUi.Basics.Services.Models; using FasdDesktopUi.Basics.Services.Models;
using FasdDesktopUi.Pages.SearchPage; using FasdDesktopUi.Pages.SearchPage;
using static C4IT.Logging.cLogManager;
namespace FasdDesktopUi.Basics.UserControls namespace FasdDesktopUi.Basics.UserControls
{ {
public partial class TicketOverview : UserControl public partial class TicketOverview : UserControl
@@ -176,27 +178,45 @@ namespace FasdDesktopUi.Basics.UserControls
#region Methods #region Methods
private async void TicketOverview_Loaded(object sender, RoutedEventArgs e) private async void TicketOverview_Loaded(object sender, RoutedEventArgs e)
{ {
if (_isInitialized) MethodBase CM = null;
return; if (cLogManager.DefaultLogger.IsDebug)
_isInitialized = true;
bool filter = SearchPageView.Instance?.IsFilterChecked == true;
await UpdateDataContextAsync(filter);
if (SearchPageView.Instance != null)
{ {
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); try
} {
catch (Exception ex) await UpdateDataContextAsync(isChecked);
{ }
Debug.WriteLine($"[TicketOverview] Refresh after toggle failed: {ex}"); 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) private async Task RefreshCountsAsync(bool useRoleTickets)
{ {
Dictionary<string, int> counts = null; MethodBase CM = null;
var service = TicketOverviewUpdateService.Instance; if (cLogManager.DefaultLogger.IsDebug)
if (service != null)
{ {
try CM = MethodBase.GetCurrentMethod();
{ LogMethodBegin(CM);
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;
}
} }
if (counts == null || counts.Count == 0) Dictionary<string, int> counts = null;
counts = await LoadCountsFallbackAsync(useRoleTickets).ConfigureAwait(false); try
await Dispatcher.InvokeAsync(() =>
{ {
foreach (var (key, setter) in CategorySetters) var service = TicketOverviewUpdateService.Instance;
if (service != null)
{ {
counts.TryGetValue(key, out var value); try
setter(_viewModel, value); {
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(); if (counts == null || counts.Count == 0)
SearchPageView.Instance?.CloseTicketOverviewResults(); counts = await LoadCountsFallbackAsync(useRoleTickets).ConfigureAwait(false);
UpdateHighlightState(useRoleTickets);
}, DispatcherPriority.Background); 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<Dictionary<string, int>> LoadCountsFallbackAsync(bool useRoleTickets) private async Task<Dictionary<string, int>> LoadCountsFallbackAsync(bool useRoleTickets)
{ {
var counts = CategorySetters.ToDictionary(item => item.Key, _ => 0); MethodBase CM = null;
var communication = cFasdCockpitCommunicationBase.Instance; if (cLogManager.DefaultLogger.IsDebug)
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 CM = MethodBase.GetCurrentMethod();
{ LogMethodBegin(CM);
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;
}
} }
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<string, int> counts, bool useRoleTickets) public void UpdateCounts(IDictionary<string, int> counts, bool useRoleTickets)

View File

@@ -1403,6 +1403,13 @@ namespace FasdDesktopUi.Pages.SearchPage
} }
private async void TicketOverview_SelectionRequested(object sender, TicketOverviewSelectionRequestedEventArgs e) private async void TicketOverview_SelectionRequested(object sender, TicketOverviewSelectionRequestedEventArgs e)
{ {
MethodBase CM = null;
if (cLogManager.DefaultLogger.IsDebug)
{
CM = MethodBase.GetCurrentMethod();
LogMethodBegin(CM);
}
try try
{ {
var app = Application.Current as FasdDesktopUi.App; var app = Application.Current as FasdDesktopUi.App;
@@ -1421,7 +1428,6 @@ namespace FasdDesktopUi.Pages.SearchPage
var relations = await LoadRelationsForTileAsync(e.Key, e.UseRoleScope, Math.Max(0, e.Count)); var relations = await LoadRelationsForTileAsync(e.Key, e.UseRoleScope, Math.Max(0, e.Count));
await PopulateTicketOverviewRelationUsersAsync(relations); await PopulateTicketOverviewRelationUsersAsync(relations);
Debug.WriteLine($"[TicketOverview] Relations loaded: {relations?.Count ?? 0}");
var firstRelation = relations.FirstOrDefault(); var firstRelation = relations.FirstOrDefault();
string displayText = header; string displayText = header;
if (firstRelation != null) if (firstRelation != null)
@@ -1486,8 +1492,10 @@ namespace FasdDesktopUi.Pages.SearchPage
LogException(ex); LogException(ex);
CancledSearchAction(); CancledSearchAction();
} }
System.Diagnostics.Debug.WriteLine( finally
$"[TicketOverview] Key={e.Key}, UseRoleScope={e.UseRoleScope}, Count={e.Count}"); {
LogMethodEnd(CM);
}
} }
private string BuildHeaderText(string key, bool useRoleScope, int? count = null) private string BuildHeaderText(string key, bool useRoleScope, int? count = null)
{ {