将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。

This commit is contained in:
QI Mingxuan
2026-04-16 17:31:13 +08:00
parent 6ec4c3ddaa
commit 2bd6e566c3
581 changed files with 74600 additions and 222 deletions
@@ -0,0 +1,50 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
namespace XP.Hardware.PLC.Sentry.Converters
{
/// <summary>
/// 连接状态文本到指示灯颜色转换器 | Connection status text to indicator color converter
/// 已连接→绿色,重连中→黄色,其他→灰色 | Connected→Green, Reconnecting→Yellow, Others→Gray
/// </summary>
public class ConnectionStatusToColorConverter : IMultiValueConverter
{
/// <summary>
/// 已连接颜色(绿色)| Connected color (green)
/// </summary>
private static readonly SolidColorBrush ConnectedBrush = new(Color.FromRgb(0x4C, 0xAF, 0x50));
/// <summary>
/// 重连中颜色(黄色)| Reconnecting color (yellow)
/// </summary>
private static readonly SolidColorBrush ReconnectingBrush = new(Color.FromRgb(0xFF, 0xC1, 0x07));
/// <summary>
/// 未连接颜色(灰色)| Disconnected color (gray)
/// </summary>
private static readonly SolidColorBrush DisconnectedBrush = new(Color.FromRgb(0xBD, 0xBD, 0xBD));
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length >= 2 && values[0] is bool isConnected && values[1] is string statusText)
{
if (isConnected)
return ConnectedBrush;
// 检查状态文本是否包含"重连"关键字 | Check if status text contains reconnecting keyword
if (statusText != null &&
(statusText.Contains("重连") || statusText.Contains("Reconnect", StringComparison.OrdinalIgnoreCase)))
return ReconnectingBrush;
}
return DisconnectedBrush;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,34 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using XP.Hardware.PLC.Sentry.Models;
namespace XP.Hardware.PLC.Sentry.Converters
{
/// <summary>
/// 日志级别到前景色转换器 | Log level to foreground color converter
/// </summary>
public class LogLevelToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is SentryLogLevel level)
{
return level switch
{
SentryLogLevel.Info => new SolidColorBrush(Color.FromRgb(0x33, 0x33, 0x33)),
SentryLogLevel.Warning => new SolidColorBrush(Color.FromRgb(0xFF, 0x8F, 0x00)),
SentryLogLevel.Error => new SolidColorBrush(Color.FromRgb(0xD3, 0x2F, 0x2F)),
_ => new SolidColorBrush(Color.FromRgb(0x33, 0x33, 0x33))
};
}
return new SolidColorBrush(Color.FromRgb(0x33, 0x33, 0x33));
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace XP.Hardware.PLC.Sentry.Converters
{
/// <summary>
/// 将 null 或空字符串转换为 Collapsed,非空字符串转换为 Visible | Converts null/empty string to Collapsed, non-empty to Visible
/// </summary>
public class NullOrEmptyToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.IsNullOrEmpty(value as string) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}