You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
314 lines
8.5 KiB
314 lines
8.5 KiB
namespace LTEMvcApp.Models
|
|
{
|
|
/// <summary>
|
|
/// 日志状态管理类
|
|
/// </summary>
|
|
public class LogState
|
|
{
|
|
/// <summary>
|
|
/// 日志列表
|
|
/// </summary>
|
|
public List<LTELog> Logs { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// 客户端列表
|
|
/// </summary>
|
|
public List<LTEClient> ClientList { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// 新日志列表
|
|
/// </summary>
|
|
public List<LTELog> NewLogs { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// 是否重置元数据
|
|
/// </summary>
|
|
public bool ResetMetadata { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 检测到的最小日志级别
|
|
/// </summary>
|
|
public int MinLevelDetected { get; set; } = 10;
|
|
|
|
/// <summary>
|
|
/// 是否启用过滤器
|
|
/// </summary>
|
|
public bool Filter { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 是否更新网格
|
|
/// </summary>
|
|
public bool UpdateGrid { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 是否跟随最新日志
|
|
/// </summary>
|
|
public bool Follow { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 过滤器锁定状态
|
|
/// </summary>
|
|
public string FilterLock { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 日志总数
|
|
/// </summary>
|
|
public int LogCount => Logs.Count;
|
|
|
|
/// <summary>
|
|
/// 客户端总数
|
|
/// </summary>
|
|
public int ClientCount => ClientList.Count;
|
|
|
|
/// <summary>
|
|
/// 新日志数量
|
|
/// </summary>
|
|
public int NewLogCount => NewLogs.Count;
|
|
|
|
/// <summary>
|
|
/// 启用的客户端数量
|
|
/// </summary>
|
|
public int EnabledClientCount => ClientList.Count(c => c.State == ClientState.Connected || c.State == ClientState.Start);
|
|
|
|
/// <summary>
|
|
/// 添加日志
|
|
/// </summary>
|
|
/// <param name="log">日志对象</param>
|
|
public void AddLog(LTELog log)
|
|
{
|
|
Logs.Add(log);
|
|
NewLogs.Add(log);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加客户端
|
|
/// </summary>
|
|
/// <param name="client">客户端对象</param>
|
|
public void AddClient(LTEClient client)
|
|
{
|
|
ClientList.Add(client);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除客户端
|
|
/// </summary>
|
|
/// <param name="client">客户端对象</param>
|
|
/// <returns>是否成功移除</returns>
|
|
public bool RemoveClient(LTEClient client)
|
|
{
|
|
var removed = ClientList.Remove(client);
|
|
if (removed)
|
|
{
|
|
// 移除该客户端的日志
|
|
Logs.RemoveAll(log => log.Client == client);
|
|
NewLogs.RemoveAll(log => log.Client == client);
|
|
}
|
|
return removed;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清除所有日志
|
|
/// </summary>
|
|
public void ClearLogs()
|
|
{
|
|
Logs.Clear();
|
|
NewLogs.Clear();
|
|
ResetMetadata = true;
|
|
UpdateGrid = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清除新日志
|
|
/// </summary>
|
|
public void ClearNewLogs()
|
|
{
|
|
NewLogs.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置状态
|
|
/// </summary>
|
|
public void Reset()
|
|
{
|
|
Logs.Clear();
|
|
NewLogs.Clear();
|
|
ResetMetadata = true;
|
|
MinLevelDetected = 10;
|
|
Filter = false;
|
|
UpdateGrid = false;
|
|
Follow = false;
|
|
FilterLock = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取指定客户端的日志
|
|
/// </summary>
|
|
/// <param name="client">客户端对象</param>
|
|
/// <returns>日志列表</returns>
|
|
public List<LTELog> GetLogsByClient(LTEClient client)
|
|
{
|
|
return Logs.Where(log => log.Client == client).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取启用的客户端
|
|
/// </summary>
|
|
/// <returns>启用的客户端列表</returns>
|
|
public List<LTEClient> GetEnabledClients()
|
|
{
|
|
return ClientList.Where(c => c.State == ClientState.Connected || c.State == ClientState.Start).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取错误状态的客户端
|
|
/// </summary>
|
|
/// <returns>错误状态的客户端列表</returns>
|
|
public List<LTEClient> GetErrorClients()
|
|
{
|
|
return ClientList.Where(c => c.State == ClientState.Error).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取连接状态的客户端
|
|
/// </summary>
|
|
/// <returns>连接状态的客户端列表</returns>
|
|
public List<LTEClient> GetConnectedClients()
|
|
{
|
|
return ClientList.Where(c => c.State == ClientState.Connected).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查是否有实时客户端
|
|
/// </summary>
|
|
/// <returns>是否有实时客户端</returns>
|
|
public bool HasRealTimeClients()
|
|
{
|
|
return ClientList.Any(c => c.State == ClientState.Connected);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取日志统计信息
|
|
/// </summary>
|
|
/// <returns>统计信息</returns>
|
|
public LogStatistics GetStatistics()
|
|
{
|
|
return new LogStatistics
|
|
{
|
|
TotalLogs = LogCount,
|
|
NewLogs = NewLogCount,
|
|
TotalClients = ClientCount,
|
|
EnabledClients = EnabledClientCount,
|
|
ConnectedClients = GetConnectedClients().Count,
|
|
ErrorClients = GetErrorClients().Count,
|
|
MinLevel = MinLevelDetected,
|
|
HasRealTime = HasRealTimeClients()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新最小日志级别
|
|
/// </summary>
|
|
/// <param name="level">日志级别</param>
|
|
public void UpdateMinLevel(int level)
|
|
{
|
|
if (level < MinLevelDetected)
|
|
{
|
|
MinLevelDetected = level;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置过滤器状态
|
|
/// </summary>
|
|
/// <param name="enabled">是否启用</param>
|
|
public void SetFilter(bool enabled)
|
|
{
|
|
Filter = enabled;
|
|
if (enabled)
|
|
{
|
|
UpdateGrid = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 锁定过滤器
|
|
/// </summary>
|
|
/// <param name="lockName">锁定名称</param>
|
|
public void LockFilter(string lockName)
|
|
{
|
|
FilterLock = lockName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解锁过滤器
|
|
/// </summary>
|
|
public void UnlockFilter()
|
|
{
|
|
FilterLock = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查过滤器是否被锁定
|
|
/// </summary>
|
|
/// <returns>是否被锁定</returns>
|
|
public bool IsFilterLocked()
|
|
{
|
|
return !string.IsNullOrEmpty(FilterLock);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日志统计信息
|
|
/// </summary>
|
|
public class LogStatistics
|
|
{
|
|
/// <summary>
|
|
/// 总日志数
|
|
/// </summary>
|
|
public int TotalLogs { get; set; }
|
|
|
|
/// <summary>
|
|
/// 新日志数
|
|
/// </summary>
|
|
public int NewLogs { get; set; }
|
|
|
|
/// <summary>
|
|
/// 总客户端数
|
|
/// </summary>
|
|
public int TotalClients { get; set; }
|
|
|
|
/// <summary>
|
|
/// 启用的客户端数
|
|
/// </summary>
|
|
public int EnabledClients { get; set; }
|
|
|
|
/// <summary>
|
|
/// 连接的客户端数
|
|
/// </summary>
|
|
public int ConnectedClients { get; set; }
|
|
|
|
/// <summary>
|
|
/// 错误的客户端数
|
|
/// </summary>
|
|
public int ErrorClients { get; set; }
|
|
|
|
/// <summary>
|
|
/// 最小日志级别
|
|
/// </summary>
|
|
public int MinLevel { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否有实时客户端
|
|
/// </summary>
|
|
public bool HasRealTime { get; set; }
|
|
|
|
/// <summary>
|
|
/// 获取统计信息字符串
|
|
/// </summary>
|
|
/// <returns>统计信息字符串</returns>
|
|
public override string ToString()
|
|
{
|
|
return $"日志: {TotalLogs} (新: {NewLogs}), 客户端: {EnabledClients}/{TotalClients} (连接: {ConnectedClients}, 错误: {ErrorClients}), 最小级别: {MinLevel}";
|
|
}
|
|
}
|
|
}
|