Files
Heimdall/src/Heimdall.Web/Components/Pages/AgentDetail.razor
T

752 lines
32 KiB
Plaintext
Raw Normal View History

2026-07-17 19:08:17 +00:00
@page "/agents/{Id:guid}"
@attribute [Authorize(Policy = "Admin.Users")]
2026-07-17 19:08:17 +00:00
@layout MainLayout
@inject HeimdallApiClient Api
@inject ISnackbar Snackbar
@inject NavigationManager Nav
@implements IDisposable
2026-07-17 19:08:17 +00:00
<MudText Typo="Typo.h1" Class="mb-6">
2026-07-17 19:08:17 +00:00
<MudIcon Icon="@Icons.Material.Filled.Dns" Class="mr-2" />
Agent : @_agent?.Name
</MudText>
@if (_loading)
{
<LoadingSkeleton LineCount="6" />
2026-07-17 19:08:17 +00:00
}
else if (_agent is null)
{
<EmptyState Icon="@Icons.Material.Filled.Dns"
Title="Agent introuvable"
Description="L'agent demandé n'existe pas ou a été supprimé.">
<ActionContent>
<MudButton Variant="Variant.Outlined" Color="Color.Primary"
OnClick="@(() => Nav.NavigateTo("/admin/agents"))">
<MudIcon Icon="@Icons.Material.Filled.ArrowBack" Class="mr-1" /> Retour aux agents
</MudButton>
</ActionContent>
</EmptyState>
2026-07-17 19:08:17 +00:00
}
else
{
@* ─── Status Bar ─── *@
<div class="d-flex align-center mb-4">
<StatusChip Text="@UiFormat.Status(_agent.Status)"
Color="@GetStatusColor(_agent.Status)"
Icon="@GetStatusIcon(_agent.Status)"
Size="Size.Medium" />
<MudSpacer />
<MudText Typo="Typo.body2" Color="Color.Secondary">
Dernier heartbeat : @(_agent.LastHeartbeat?.ToString("g") ?? "Jamais")
</MudText>
</div>
2026-07-17 19:08:17 +00:00
<MudGrid>
<MudItem xs="12" md="6">
<SectionCard Title="Informations" Icon="@Icons.Material.Filled.Info" Elevation="2">
2026-07-17 19:08:17 +00:00
<MudGrid>
<MudItem xs="6">
<MudText Typo="Typo.body2" Color="Color.Secondary">Hostname</MudText>
<MudText Typo="Typo.body1">@_agent.Hostname</MudText>
</MudItem>
<MudItem xs="6">
<MudText Typo="Typo.body2" Color="Color.Secondary">Version</MudText>
<MudText Typo="Typo.body1">@_agent.Version</MudText>
</MudItem>
<MudItem xs="6" Class="mt-2">
<MudText Typo="Typo.body2" Color="Color.Secondary">Statut</MudText>
<MudText Color="@GetStatusColor(_agent.Status)" Typo="Typo.body1">
@GetStatusIcon(_agent.Status) @_agent.Status
</MudText>
</MudItem>
<MudItem xs="6" Class="mt-2">
<MudText Typo="Typo.body2" Color="Color.Secondary">IP publique</MudText>
<MudText Typo="Typo.body1">@(_agent.PublicIp ?? "-")</MudText>
</MudItem>
<MudItem xs="6" Class="mt-2">
<MudText Typo="Typo.body2" Color="Color.Secondary">Dernier heartbeat</MudText>
<MudText Typo="Typo.body1">@(_agent.LastHeartbeat?.ToString("g") ?? "Jamais")</MudText>
</MudItem>
<MudItem xs="6" Class="mt-2">
<MudText Typo="Typo.body2" Color="Color.Secondary">Enregistré le</MudText>
<MudText Typo="Typo.body1">@_agent.CreatedAt.ToString("g")</MudText>
</MudItem>
</MudGrid>
</SectionCard>
2026-07-17 19:08:17 +00:00
</MudItem>
<MudItem xs="12" md="6">
<SectionCard Title="Capacités" Icon="@Icons.Material.Filled.Dns" Elevation="2">
2026-07-17 19:08:17 +00:00
<MudGrid>
<MudItem xs="6">
<MudText Typo="Typo.body2" Color="Color.Secondary">CPU</MudText>
<MudText Typo="Typo.body1">@_agent.CpuCores cœurs</MudText>
</MudItem>
<MudItem xs="6">
<MudText Typo="Typo.body2" Color="Color.Secondary">Mémoire</MudText>
<MudText Typo="Typo.body1">@FormatMemory(_agent.MemoryMb)</MudText>
</MudItem>
<MudItem xs="6" Class="mt-2">
<MudText Typo="Typo.body2" Color="Color.Secondary">GPU</MudText>
<MudText Typo="Typo.body1">
<MudIcon Icon="@(_agent.HasGpu ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
Color="@(_agent.HasGpu ? Color.Success : Color.Default)" Size="Size.Small" />
@(_agent.HasGpu ? _agent.GpuType : "Aucun")
</MudText>
</MudItem>
</MudGrid>
</SectionCard>
2026-07-17 19:08:17 +00:00
</MudItem>
</MudGrid>
@* ─── Agent Settings (globals hérités + overrides) ─── *@
<SectionCard Title="Configuration"
Icon="@Icons.Material.Filled.Tune"
Elevation="2"
HelpText="Paramètres globaux hérités par cet agent, modifiables pour ce site uniquement. Envoyés en temps réel via SignalR.">
@if (_settingsLoading)
{
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
}
else if (_settingsError)
{
<MudAlert Severity="Severity.Error" Class="mb-4">
Erreur lors du chargement de la configuration
<MudButton OnClick="@LoadSettingsAsync" Size="Size.Small" Variant="Variant.Text" Class="ml-2">Réessayer</MudButton>
</MudAlert>
}
else if (_globalSettings.Count == 0 && _settings.Count == 0)
{
<MudAlert Severity="Severity.Info" Class="mb-4">
Aucun paramètre global exposé aux agents pour le moment.
</MudAlert>
}
else
{
@foreach (var category in _globalSettings.GroupBy(s => s.Category).OrderBy(g => g.Key))
{
<div class="settings-category mb-4" @key="category.Key">
<div class="d-flex align-center mb-2 mt-2">
<MudText Typo="Typo.h6" Class="flex-grow-1">
<MudIcon Icon="@GetAgentCategoryIcon(category.Key)" Size="Size.Small" Class="mr-1" />
@category.Key
</MudText>
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined">@category.Count()</MudChip>
</div>
<MudGrid>
@foreach (var setting in category)
{
var overridden = IsOverridden(setting.Key);
var effectiveValue = EffectiveValue(setting.Key, setting.Value);
<MudItem xs="12" sm="6" lg="4" @key="setting.Key">
<MudPaper Elevation="1" Class="pa-4 settings-card" Style="border-radius: 12px; height: 100%;">
<div class="d-flex align-center mb-2">
<MudIcon Icon="@GetAgentTypeIcon(setting.ValueType)" Size="Size.Small"
Color="@GetAgentTypeColor(setting.ValueType)" Class="mr-2" />
<div class="flex-grow-1">
<MudText Typo="Typo.body1" Class="font-weight-medium settings-label">
@(setting.Description ?? HumanizeAgentKey(setting.Key))
</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="settings-key">
@setting.Key
</MudText>
</div>
@if (overridden)
{
<MudTooltip Text="Réinitialiser à la valeur globale">
<MudIconButton Icon="@Icons.Material.Filled.Restore" Size="Size.Small" aria-label="Restaurer"
Color="Color.Warning" OnClick="@(() => ExecuteRemoveSettingByKey(setting.Key))" />
</MudTooltip>
}
</div>
@if (overridden)
{
<MudChip T="string" Size="Size.Small" Color="Color.Warning" Class="mb-2">
Surchargé pour cet agent
</MudChip>
}
else
{
<MudChip T="string" Size="Size.Small" Color="Color.Info" Class="mb-2">
Hérité (global)
</MudChip>
}
@switch (setting.ValueType.ToLowerInvariant())
{
case "boolean":
case "bool":
<div class="d-flex align-center">
<MudSwitch T="bool"
Value="@(effectiveValue?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
ValueChanged="@(v => SaveGlobalOverrideBoolAsync(setting, v))"
Color="Color.Primary" Class="flex-grow-1" />
<MudText Typo="Typo.body2" Color="Color.Primary" Class="font-weight-medium">
@(effectiveValue?.Equals("true", StringComparison.OrdinalIgnoreCase) == true ? "Activé" : "Désactivé")
</MudText>
</div>
break;
case "number":
case "int":
case "integer":
case "double":
<MudTextField T="string" Value="@effectiveValue" Variant="Variant.Outlined" Dense="true"
ValueChanged="@(v => SaveGlobalOverrideAsync(setting, v))"
Label="Valeur" Type="InputType.Number" />
break;
case "select":
case "dropdown":
<MudSelect T="string" Value="@effectiveValue" Variant="Variant.Outlined" Dense="true"
ValueChanged="@(v => SaveGlobalOverrideAsync(setting, v))" Label="Valeur">
@foreach (var opt in (setting.AllowedValues ?? "").Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
<MudSelectItem Value="@opt" @key="opt">@opt</MudSelectItem>
}
</MudSelect>
break;
default:
<MudTextField T="string" Value="@effectiveValue" Variant="Variant.Outlined" Dense="true"
ValueChanged="@(v => SaveGlobalOverrideAsync(setting, v))" Label="Valeur" />
break;
}
</MudPaper>
</MudItem>
}
</MudGrid>
</div>
}
}
@if (_settings.Count > 0)
{
<MudAlert Severity="Severity.Warning" Class="mt-2">
@_settings.Count réglage(s) surchargé(s) pour cet agent — la valeur globale est ignorée pour ces clés.
</MudAlert>
}
</SectionCard>
@* ─── Agent Logs ─── *@
<SectionCard Title="Logs"
Icon="@Icons.Material.Filled.ReceiptLong"
Elevation="2"
HelpText="Logs remontés par l'agent, purgés quotidiennement (rétention 7 jours).">
<ChildContent>
<div class="d-flex flex-wrap gap-2 mb-4">
<MudSelect T="string" @bind-Value="_logLevel" Label="Niveau" Variant="Variant.Outlined"
Dense="true" Clearable="true" Class="logs-level-filter" Immediate="true">
<MudSelectItem T="string" Value="@null">Tous les niveaux</MudSelectItem>
<MudSelectItem Value="@("Critical")">Critical</MudSelectItem>
<MudSelectItem Value="@("Error")">Error</MudSelectItem>
<MudSelectItem Value="@("Warning")">Warning</MudSelectItem>
<MudSelectItem Value="@("Information")">Information</MudSelectItem>
<MudSelectItem Value="@("Debug")">Debug</MudSelectItem>
<MudSelectItem Value="@("Trace")">Trace</MudSelectItem>
</MudSelect>
<MudTextField T="string" @bind-Value="_logSearch" Label="Recherche" Variant="Variant.Outlined"
Dense="true" Immediate="true" Class="logs-search-filter"
Placeholder="Message ou source..." />
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => LoadLogsAsync(keepPage: false))"
StartIcon="@Icons.Material.Filled.Search" Class="align-self-center">
Filtrer
</MudButton>
</div>
@if (_logsLoading)
{
<MudPaper Elevation="1" Class="pa-4" Style="border-radius: 8px;">
<MudSkeleton Width="100%" Height="40px" />
<MudSkeleton Width="100%" Height="40px" Class="mt-1" />
<MudSkeleton Width="100%" Height="40px" Class="mt-1" />
</MudPaper>
}
else if (_logsError)
{
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
<MudText>Erreur lors du chargement des logs.</MudText>
<MudButton Variant="Variant.Text" Color="Color.Inherit"
OnClick="@(() => LoadLogsAsync(keepPage: true))" Class="mt-2">
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
</MudButton>
</MudAlert>
}
else
{
<MudTable Items="@_logs" Hover="true" Striped="true" Elevation="2" Dense="true">
<HeaderContent>
<MudTh>Date</MudTh>
<MudTh>Niveau</MudTh>
<MudTh>Source</MudTh>
<MudTh>Message</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date">
<MudTooltip Text="@context.TimestampUtc.ToLocalTime().ToString("F")">
<MudText Typo="Typo.body2">@context.TimestampUtc.ToLocalTime().ToString("g")</MudText>
</MudTooltip>
</MudTd>
<MudTd DataLabel="Niveau">
<MudChip T="string" Size="Size.Small" Color="@GetLogLevelColor(context.Level)">
@context.Level
</MudChip>
</MudTd>
<MudTd DataLabel="Source">
<MudText Typo="Typo.body2" Color="Color.Secondary">@(context.Source ?? "-")</MudText>
</MudTd>
<MudTd DataLabel="Message">
@if (!string.IsNullOrEmpty(context.Exception))
{
<MudTooltip Text="@context.Exception">
<MudText Typo="Typo.body2" Class="logs-message">@context.Message</MudText>
</MudTooltip>
}
else
{
<MudText Typo="Typo.body2" Class="logs-message">@context.Message</MudText>
}
</MudTd>
</RowTemplate>
<NoRecordsContent>
<MudPaper Class="pa-8 text-center" Style="border-radius: 12px;">
<MudIcon Icon="@Icons.Material.Filled.ReceiptLong" Size="Size.Large" Color="Color.Secondary" />
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">Aucun log</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary">
L'agent n'a rien remonté pour ces filtres.
</MudText>
</MudPaper>
</NoRecordsContent>
</MudTable>
<div class="d-flex align-center pa-4 mt-4" Style="border-radius: 8px;">
<MudText Typo="Typo.body2" Class="mr-4">
Page @_logPage sur @_logTotalPages (@_logTotal entrées)
</MudText>
<MudSpacer />
<MudButton Variant="Variant.Outlined" Size="Size.Small" Class="mr-2"
Disabled="@(_logPage <= 1)" OnClick="@(() => GoToLogPage(_logPage - 1))">
← Précédent
</MudButton>
<MudButton Variant="Variant.Outlined" Size="Size.Small"
Disabled="@(_logPage >= _logTotalPages)" OnClick="@(() => GoToLogPage(_logPage + 1))">
Suivant →
</MudButton>
</div>
}
</ChildContent>
<Actions>
<MudSwitch T="bool" Value="@_autoRefresh" ValueChanged="@ToggleAutoRefresh"
Color="Color.Primary" Class="mr-2" AdornmentLabel="Auto-refresh"
Label="Auto-refresh" />
<MudTooltip Text="Rafraîchir">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Size="Size.Small"
OnClick="@(() => LoadLogsAsync(keepPage: true))" aria-label="Actualiser les logs" />
</MudTooltip>
</Actions>
</SectionCard>
<div class="d-flex gap-4 mt-4">
<MudButton Variant="Variant.Outlined" Color="Color.Default"
OnClick="@(() => Nav.NavigateTo($"/sites/{_agent.SiteId}/agents"))">
← Agents du site
</MudButton>
<MudButton Variant="Variant.Text" Color="Color.Default"
OnClick="@(() => Nav.NavigateTo("/admin/agents"))">
← Tous les agents
</MudButton>
</div>
2026-07-17 19:08:17 +00:00
}
@* ─── Delete Confirmation Dialog ─── *@
<MudDialog @bind-Visible="_confirmDeleteVisible" Options="_dialogOptions">
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Warning" Color="Color.Warning" Class="mr-2" />
Confirmer la suppression
</MudText>
</TitleContent>
<DialogContent>
<MudText>Supprimer le réglage <strong>@_deletingKey</strong> pour cet agent ?</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
L'agent sera notifié en temps réel via SignalR et utilisera la valeur globale par défaut.
</MudText>
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteVisible = false)">Annuler</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error"
OnClick="@ExecuteRemoveSettingAsync"
Loading="@_deleting"
Disabled="@_deleting">Supprimer</MudButton>
</DialogActions>
</MudDialog>
@* ─── Add / Edit Dialog ─── *@
<MudDialog @bind-Visible="_showEditDialog" Options="_dialogOptions">
<TitleContent>
<MudText Typo="Typo.h6">@(_editingSetting is null ? "Ajouter un réglage" : "Modifier le réglage")</MudText>
</TitleContent>
<DialogContent>
<MudGrid>
<MudItem xs="12">
<MudTextField Label="Clé"
@bind-Value="_editKey"
Disabled="@(_editingSetting is not null)"
For="@(() => _editKey)"
Required="true"
HelperText="Ex: heartbeat.interval.seconds" />
</MudItem>
<MudItem xs="12">
<MudTextField Label="Valeur"
@bind-Value="_editValue"
For="@(() => _editValue)"
Required="true" />
</MudItem>
</MudGrid>
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="@(() => _showEditDialog = false)">Annuler</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary"
OnClick="@SaveSettingAsync"
Disabled="@_saving"
Loading="@_saving">
@(_editingSetting is null ? "Ajouter" : "Enregistrer")
</MudButton>
</DialogActions>
</MudDialog>
2026-07-17 19:08:17 +00:00
@code {
[Parameter] public Guid Id { get; set; }
private AgentItem? _agent;
private bool _loading = true;
// Settings
private List<AgentSettingItem> _settings = [];
private List<AppSettingItem> _globalSettings = [];
private bool _settingsLoading;
private bool _settingsError;
private bool _saving;
private AgentSettingItem? _editingSetting;
private string _editKey = string.Empty;
private string _editValue = string.Empty;
private bool _showEditDialog;
private bool _confirmDeleteVisible;
private string _deletingKey = string.Empty;
private bool _deleting;
// Logs
private IReadOnlyList<AgentLogItem>? _logs;
private bool _logsLoading;
private bool _logsError;
private int _logPage = 1;
private int _logTotalPages = 1;
private int _logTotal;
private string? _logLevel;
private string? _logSearch;
private bool _autoRefresh;
private CancellationTokenSource? _refreshCts;
private bool _disposed;
private readonly DialogOptions _dialogOptions = new()
{
MaxWidth = MaxWidth.Small,
FullWidth = true,
CloseButton = true
};
2026-07-17 19:08:17 +00:00
protected override async Task OnInitializedAsync()
{
try
{
_agent = await Api.GetAgentAsync(Id);
if (_agent is not null)
{
await LoadSettingsAsync();
await LoadLogsAsync(keepPage: false);
}
2026-07-17 19:08:17 +00:00
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
2026-07-17 19:08:17 +00:00
finally { _loading = false; }
}
private async Task LoadSettingsAsync()
{
_settingsError = false;
_settingsLoading = true;
try
{
_globalSettings = (await Api.GetSettingsAsync())
.Where(s => s.AgentScoped)
.OrderBy(s => s.Category)
.ThenBy(s => s.Key)
.ToList();
_settings = await Api.GetAgentSettingsAsync(Id);
}
catch
{
_settingsError = true;
_settings = [];
_globalSettings = [];
}
finally { _settingsLoading = false; }
}
/// <summary>Returns the effective value for a global setting key (override wins).</summary>
private string EffectiveValue(string key, string globalValue)
=> _settings.FirstOrDefault(s => s.Key == key)?.Value ?? globalValue;
/// <summary>True when the agent overrides this global key.</summary>
private bool IsOverridden(string key)
=> _settings.Any(s => s.Key == key);
private async Task SaveGlobalOverrideAsync(AppSettingItem setting, string value)
{
_saving = true;
try
{
var response = await Api.SetAgentSettingAsync(Id, new SetAgentSettingRequest(setting.Key, value));
if (response.IsSuccessStatusCode)
{
Snackbar.Add($"« {setting.Key} » surchargé pour cet agent — envoyé en temps réel", Severity.Success);
await LoadSettingsAsync();
}
else
{
var error = await response.Content.ReadAsStringAsync();
Snackbar.Add($"Erreur : {error}", Severity.Error);
}
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _saving = false; }
}
private async Task SaveGlobalOverrideBoolAsync(AppSettingItem setting, bool value)
=> await SaveGlobalOverrideAsync(setting, value.ToString().ToLowerInvariant());
private void OpenAddDialog()
{
_editingSetting = null;
_editKey = string.Empty;
_editValue = string.Empty;
_showEditDialog = true;
}
private void OpenEditDialog(AgentSettingItem setting)
{
_editingSetting = setting;
_editKey = setting.Key;
_editValue = setting.Value;
_showEditDialog = true;
}
private async Task SaveSettingAsync()
{
if (string.IsNullOrWhiteSpace(_editKey)) return;
_saving = true;
try
{
var request = new SetAgentSettingRequest(_editKey.Trim(), _editValue);
var response = await Api.SetAgentSettingAsync(Id, request);
if (response.IsSuccessStatusCode)
{
Snackbar.Add("Réglage enregistré et envoyé à l'agent en temps réel", Severity.Success);
_showEditDialog = false;
await LoadSettingsAsync();
}
else
{
var error = await response.Content.ReadAsStringAsync();
Snackbar.Add($"Erreur : {error}", Severity.Error);
}
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _saving = false; }
}
private void ConfirmRemoveSetting(AgentSettingItem setting)
{
_deletingKey = setting.Key;
_confirmDeleteVisible = true;
}
private async Task ExecuteRemoveSettingAsync()
{
_deleting = true;
try
{
var response = await Api.RemoveAgentSettingAsync(Id, _deletingKey);
if (response.IsSuccessStatusCode)
{
_confirmDeleteVisible = false;
Snackbar.Add("Réglage supprimé, agent notifié en temps réel", Severity.Success);
await LoadSettingsAsync();
}
else
{
Snackbar.Add("Erreur lors de la suppression", Severity.Error);
}
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _deleting = false; }
}
private async Task ExecuteRemoveSettingByKey(string key)
{
_deleting = true;
try
{
var response = await Api.RemoveAgentSettingAsync(Id, key);
if (response.IsSuccessStatusCode)
{
Snackbar.Add($"« {key} » réinitialisé à la valeur globale — agent notifié", Severity.Success);
await LoadSettingsAsync();
}
else
{
Snackbar.Add("Erreur lors de la réinitialisation", Severity.Error);
}
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _deleting = false; }
}
private async Task LoadLogsAsync(bool keepPage)
{
if (!keepPage) _logPage = 1;
_logsError = false;
_logsLoading = true;
try
{
var result = await Api.GetAgentLogsAsync(Id, _logLevel, _logSearch, _logPage);
if (result is not null)
{
_logs = result.Items;
_logTotal = result.TotalCount;
_logTotalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize));
}
}
catch
{
_logsError = true;
_logs = [];
}
finally
{
_logsLoading = false;
if (!_disposed) await InvokeAsync(StateHasChanged);
}
}
private async Task GoToLogPage(int page)
{
_logPage = page;
await LoadLogsAsync(keepPage: true);
}
private async Task ToggleAutoRefresh(bool enabled)
{
_autoRefresh = enabled;
_refreshCts?.Cancel();
_refreshCts?.Dispose();
_refreshCts = null;
if (enabled)
{
_refreshCts = new CancellationTokenSource();
_ = AutoRefreshLoopAsync(_refreshCts.Token);
}
}
private async Task AutoRefreshLoopAsync(CancellationToken ct)
{
try
{
while (!ct.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(10), ct);
if (!_disposed && _agent is not null)
await LoadLogsAsync(keepPage: true);
}
}
catch (OperationCanceledException) { /* arrêt volontaire */ }
}
private static Color GetLogLevelColor(string level) => level switch
{
"Critical" or "Error" => Color.Error,
"Warning" => Color.Warning,
"Information" => Color.Info,
_ => Color.Default
};
public void Dispose()
{
_disposed = true;
_refreshCts?.Cancel();
_refreshCts?.Dispose();
_refreshCts = null;
}
2026-07-17 19:08:17 +00:00
private static Color GetStatusColor(string status) => status switch
{
"Online" => Color.Success,
"Offline" => Color.Error,
"Error" => Color.Warning,
_ => Color.Default
};
private static string GetStatusIcon(string status) => status switch
{
"Online" => "●",
"Offline" => "○",
"Error" => "⚠",
_ => "?"
};
private static string FormatMemory(long mb) => mb switch
{
> 102400 => $"{mb / 1024:F0} Go",
> 0 => $"{mb} Mo",
_ => "-"
};
// ─── Settings visual helpers ─────────────────────────────────────
private static Color GetAgentTypeColor(string valueType) => valueType.ToLowerInvariant() switch
{
"boolean" or "bool" => Color.Success,
"number" or "int" or "integer" or "double" => Color.Info,
"select" or "dropdown" => Color.Warning,
_ => Color.Secondary
};
private static string GetAgentTypeIcon(string valueType) => valueType.ToLowerInvariant() switch
{
"boolean" or "bool" => Icons.Material.Filled.ToggleOn,
"number" or "int" or "integer" or "double" => Icons.Material.Filled.Tag,
"select" or "dropdown" => Icons.Material.Filled.ArrowDropDownCircle,
_ => Icons.Material.Filled.TextFields
};
private static string GetAgentCategoryIcon(string category) => category.ToLowerInvariant() switch
{
"detection" => Icons.Material.Filled.Visibility,
"recording" => Icons.Material.Filled.Videocam,
"logging" or "log" => Icons.Material.Filled.BugReport,
"network" => Icons.Material.Filled.Wifi,
"storage" => Icons.Material.Filled.Storage,
"notification" or "notifications" => Icons.Material.Filled.Notifications,
"heartbeat" => Icons.Material.Filled.MonitorHeart,
_ => Icons.Material.Filled.Settings
};
private static string HumanizeAgentKey(string key)
{
var parts = key.Split('.', '_', '-');
return string.Join(' ', parts.Select(p => p.Length <= 2
? p.ToUpperInvariant()
: char.ToUpperInvariant(p[0]) + p[1..]));
}
2026-07-17 19:08:17 +00:00
}