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,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<string, int> 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<string, int> 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<Dictionary<string, int>> 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<string, int> counts, bool useRoleTickets)