Logging
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
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
|
||||
@@ -14,6 +16,7 @@ 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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1403,6 +1403,13 @@ namespace FasdDesktopUi.Pages.SearchPage
|
||||
}
|
||||
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;
|
||||
@@ -1421,7 +1428,6 @@ namespace FasdDesktopUi.Pages.SearchPage
|
||||
|
||||
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)
|
||||
@@ -1486,8 +1492,10 @@ namespace FasdDesktopUi.Pages.SearchPage
|
||||
LogException(ex);
|
||||
CancledSearchAction();
|
||||
}
|
||||
System.Diagnostics.Debug.WriteLine(
|
||||
$"[TicketOverview] Key={e.Key}, UseRoleScope={e.UseRoleScope}, Count={e.Count}");
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
private string BuildHeaderText(string key, bool useRoleScope, int? count = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user