using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace LTEMvcApp.Models
{
///
/// 日志管理器 - 从JavaScript logs.js迁移
///
public class LogsManager
{
#region 常量定义
public const int DIR_NONE = 0;
public const int DIR_UL = 1;
public const int DIR_DL = 2;
public const int DIR_FROM = 3;
public const int DIR_TO = 4;
#endregion
#region 静态字段
private static readonly string[] modelList = { "RUE", "UE", "PROBE", "ENB", "N3IWF", "MBMSGW", "MME", "IMS", "LICENSE", "MONITOR" };
private static readonly Dictionary modelConfig = new()
{
{ "RUE", new { icon = "icon-ue2" } },
{ "UE", new { icon = "icon-ue" } },
{ "PROBE", new { } },
{ "ENB", new { icon = "icon-air", modelHint = "enb|gnb|bbu", title = "RAN" } },
{ "N3IWF", new { icon = "icon-air", modelHint = "n3iwf", title = "N3IWF" } },
{ "MME", new { icon = "icon-server", modelHint = "epc|mme|amf", title = "CN" } },
{ "MBMSGW", new { icon = "icon-download", modelHint = "mbms" } },
{ "IMS", new { icon = "icon-dial" } },
{ "MONITOR", new { icon = "icon-monitor" } },
{ "LICENSE", new { icon = "icon-file" } }
};
private static readonly Dictionary layerConfig = new()
{
{ "PHY", new { color = "#606070", dir = new Dictionary { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "MAC", new { color = "#10A0FF", dir = new Dictionary { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "RLC", new { color = "#FFFF80", dir = new Dictionary { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } } } },
{ "PDCP", new { color = "#B0D0B0", dir = new Dictionary { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } } } },
{ "RRC", new { color = "#00FF60", dir = new Dictionary { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "NAS", new { color = "#90FFC0", dir = new Dictionary { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 3 }, { "N3IWF", 3 }, { "MME", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "GTPU", new { color = "#FF80FF", dir = new Dictionary { { "ENB", 2 }, { "N3IWF", 2 }, { "MME", 1 }, { "MBMSGW", 1 }, { "UE", 1 }, { "RUE", 2 } }, epc = true, max = new { max_size = 32 } } },
{ "GTPC", new { color = "#FFC0FF", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "IP", new { color = "#E0E0E0", dir = new Dictionary { { "RUE", 2 }, { "UE", 2 }, { "N3IWF", 3 }, { "PROBE", 3 }, { "MME", 3 } }, max = new { max_size = 32 } } },
{ "S1AP", new { color = "#80FF00", dir = new Dictionary { { "ENB", 2 }, { "MME", 1 } }, epc = true, debug = new { level = "debug", max_size = 1 } } },
{ "NGAP", new { color = "#5DD122", dir = new Dictionary { { "ENB", 2 }, { "MME", 1 }, { "N3IWF", 2 } }, epc = true, debug = new { level = "debug", max_size = 1 } } },
{ "X2AP", new { color = "#FF8000", dir = new Dictionary { { "ENB", 2 } } } },
{ "XnAP", new { color = "#FFB020", dir = new Dictionary { { "ENB", 2 } } } },
{ "M2AP", new { color = "#7F675B", dir = new Dictionary { { "ENB", 2 }, { "MBMSGW", 1 } }, epc = true } },
{ "IMS", new { color = "#C0FF80", dir = new Dictionary { { "MME", 2 }, { "IMS", 1 } }, debug = new { level = "debug", max_size = 1 }, epc = true } },
{ "CX", new { color = "#F49542", dir = new Dictionary { { "MME", 2 }, { "IMS", 1 } }, epc = true } },
{ "RX", new { color = "#D4A190", dir = new Dictionary { { "MME", 2 }, { "IMS", 1 } }, epc = true } },
{ "COM", new { color = "#C000FF", dir = new Dictionary { { "*", 2 } } } },
{ "SIP", new { color = "#C080FF", dir = new Dictionary { { "IMS", 1 } }, epc = true, debug = new { level = "debug", max_size = 1 } } },
{ "MEDIA", new { color = "#800040", dir = new Dictionary { { "IMS", 1 } }, epc = true } },
{ "RTP", new { color = "#FF00C0", dir = new Dictionary { { "IMS", 1 } }, epc = true } },
{ "PROD", new { color = "#80C0FF", dir = new Dictionary { } } },
{ "S6", new { color = "#F44B42", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "S13", new { color = "#D6F953", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "SGsAP", new { color = "#FF7DB8", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "SBcAP", new { color = "#8FA00F", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "N8", new { color = "#106020", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "N12", new { color = "#602020", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "N13", new { color = "#202060", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "N17", new { color = "#D6F953", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "N50", new { color = "#8FA00F", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "MMS", new { color = "#B4D98F", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "HTTP2", new { color = "#644824", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "LCSAP", new { color = "#cfd50d", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "LPPa", new { color = "#0dcfd5", dir = new Dictionary { { "ENB", 2 }, { "MME", 3 } }, epc = true } },
{ "NL1", new { color = "#d040cf", dir = new Dictionary { { "MME", 2 } }, epc = true } },
{ "NRPPa", new { color = "#0dd5cf", dir = new Dictionary { { "ENB", 2 }, { "MME", 3 } }, epc = true } },
{ "IKEV2", new { color = "#C0B732", dir = new Dictionary { { "UE", 2 }, { "MME", 1 }, { "N3IWF", 1 } } } },
{ "SWU", new { color = "#101080", dir = new Dictionary { { "UE", 2 }, { "MME", 1 } } } },
{ "NWU", new { color = "#2080B8", dir = new Dictionary { { "UE", 2 }, { "MME", 1 } } } },
{ "IPSEC", new { color = "#F04010", dir = new Dictionary { { "UE", 2 }, { "IMS", 1 }, { "N3IWF", 1 }, { "MME", 1 } }, epc = true, max = new { max_size = 32 } } },
{ "N3IWF", new { color = "#C080C0", dir = new Dictionary { { "UE", 2 }, { "N3IWF", 1 } } } },
{ "TRX", new { color = "#42C0a0", dir = new Dictionary { { "UE", 2 }, { "ENB", 1 } }, debug = new { level = "debug" } } },
{ "MON", new { color = "#C0C080", dir = new Dictionary { } } },
{ "EVENT", new { color = "#80C0FF", dir = new Dictionary { } } },
{ "ALARM", new { color = "#FF8040", dir = new Dictionary { } } },
{ "LIC", new { color = "#ff80c0", dir = new Dictionary { { "LICENSE", 1 } } } },
{ "OTS", new { color = "#8080FF", dir = new Dictionary { } } },
{ "ERROR", new { color = "#ff0000", dir = new Dictionary { } } }
};
#endregion
#region 实例字段
private readonly Dictionary _logs = new();
private readonly int _logDefaultLevel = 0; // localStorage.debug >> 0
private readonly string[] _logsMethods = { "error", "warn", "info", "debug", "prof" };
private readonly long _startDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
private readonly Dictionary _stringIDs = new();
private readonly List _stringList = new();
private readonly Dictionary _eventListeners = new();
private int _eventListenerId = 0;
#endregion
#region 属性
public string Mode { get; set; } = "web";
public string FontDef { get; set; } = "13px helvetica, arial, verdana, sans-serif";
public int LastClientId { get; set; } = 0;
public int LogsMax { get; set; } = 100000;
public List LogsRange { get; set; } = new();
public List LogsInfo { get; set; } = new();
public List LogsLayers { get; set; } = new();
public string ExportTimeFormat { get; set; } = "HH:mm:ss.fff";
#endregion
#region 构造函数
public LogsManager()
{
Init();
}
#endregion
#region 初始化方法
public void Init()
{
// 初始化通道定义
var def = new Dictionary();
var ids = new Dictionary();
// 这里可以添加通道定义的初始化逻辑
// 对应JavaScript中的_channelsDef.forEach逻辑
}
#endregion
#region 日志相关方法
public void SetLogger(string name, object instance)
{
var module = new { level = _logDefaultLevel, list = new List