junction/src/Junction.App/Converters/StatusKindToBrushConverter.cs
dtrentin cf394bab31 refactor: v0.2.1 refinements — HttpClient lifetime, disconnection UX, DataGrid
Post-v0.2 polish (no behavior regressions; 127 tests + 2 docker integration green).

- MTConnect: shared static HttpClient (Timeout=Infinite) + per-request timeout
  via linked CancellationTokenSource. Fixes socket-exhaustion risk from
  new-HttpClient-per-driver on config edits / dynamic monitor reload.
- Disconnection UX: dashboard + detail show connection state with color
  (green/red/grey dot + badge) via StatusKindToBrush converter; LastSeen
  timestamp preserved across disconnects. VMs stay framework-agnostic.
- Delete confirm: VM-driven overlay naming the machine (replaces two-state
  button) to prevent accidental deletion.
- Dashboard table: switched to DataGrid — aligned columns + Details gets its
  own column (fixes row misalignment). Adds Avalonia.Controls.DataGrid 11.3.10.

PAUL: roadmap re-sequenced — v0.3 Data-Item Selection + UX, OPC UA → v0.4,
Fanuc → v0.5, History → v0.6.

Touches: Junction.Protocols.MTConnect, Junction.App, tests, .paul/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 00:09:48 +02:00

37 lines
1.4 KiB
C#

using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
namespace Junction.App.Converters
{
/// <summary>
/// Maps a <see cref="ViewModels.MachineRowViewModel.StatusKind"/> token
/// ("online"/"offline"/"unknown") to a status brush. Keeps view-models free of
/// UI-framework types: the color decision lives entirely in the view layer.
/// </summary>
public sealed class StatusKindToBrushConverter : IValueConverter
{
public static readonly StatusKindToBrushConverter Instance = new StatusKindToBrushConverter();
private static readonly IBrush Online = new SolidColorBrush(Color.FromRgb(0x2E, 0x7D, 0x32)); // green
private static readonly IBrush Offline = new SolidColorBrush(Color.FromRgb(0xC6, 0x28, 0x28)); // red
private static readonly IBrush Unknown = new SolidColorBrush(Color.FromRgb(0x9E, 0x9E, 0x9E)); // grey
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
switch (value as string)
{
case "online":
return Online;
case "offline":
return Offline;
default:
return Unknown;
}
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
}