From d8794dd24e668addd236148065682357f97b6534 Mon Sep 17 00:00:00 2001 From: hyh Date: Tue, 24 Jun 2025 11:34:22 +0800 Subject: [PATCH] 1111232 --- LTEMvcApp/Models/LogLayerConfig.cs | 91 +++++++++++++++++++++++++++++- LTEMvcApp/Models/LogsManager.cs | 69 +++++----------------- 2 files changed, 105 insertions(+), 55 deletions(-) diff --git a/LTEMvcApp/Models/LogLayerConfig.cs b/LTEMvcApp/Models/LogLayerConfig.cs index 2fe66c9..b9fa754 100644 --- a/LTEMvcApp/Models/LogLayerConfig.cs +++ b/LTEMvcApp/Models/LogLayerConfig.cs @@ -76,6 +76,12 @@ namespace LTEMvcApp.Models /// public static class LogLayerTypes { + // 方向值缓存,避免重复计算 + private static readonly Dictionary _directionCache = new(); + + // 层配置缓存,避免重复创建字典 + private static readonly Dictionary _layerConfigsCache = new(); + public const string PHY = "PHY"; public const string MAC = "MAC"; public const string RLC = "RLC"; @@ -173,7 +179,14 @@ namespace LTEMvcApp.Models /// 层配置字典 public static Dictionary GetLayerConfigs() { - return new Dictionary + // 如果缓存已存在,直接返回 + if (_layerConfigsCache.Count > 0) + { + return _layerConfigsCache; + } + + // 初始化层配置 + var configs = new Dictionary { [PHY] = new() { Color = "#606070", Direction = new() { ["UE"] = 2, ["PROBE"] = 3, ["ENB"] = 1 }, Debug = new() { Level = "debug", MaxSize = 1 } }, [MAC] = new() { Color = "#10A0FF", Direction = new() { ["UE"] = 2, ["PROBE"] = 3, ["ENB"] = 1 }, Debug = new() { Level = "debug", MaxSize = 1 } }, @@ -225,6 +238,14 @@ namespace LTEMvcApp.Models [OTS] = new() { Color = "#8080FF", Direction = new() { } }, [ERROR] = new() { Color = "#ff0000", Direction = new() { } } }; + + // 缓存配置 + foreach (var kvp in configs) + { + _layerConfigsCache[kvp.Key] = kvp.Value; + } + + return _layerConfigsCache; } /// @@ -238,6 +259,57 @@ namespace LTEMvcApp.Models return configs.TryGetValue(layerName, out var config) ? config : null; } + /// + /// 根据方向值获取匹配的层名称数组 + /// + /// 方向值 + /// 包含指定方向值的层名称数组 + public static string[] GetLayersByDirectionValue(int directionValue) + { + // 使用静态缓存避免重复创建字典 + var configs = GetLayerConfigs(); + + return configs + .Where(kvp => kvp.Value.Direction.ContainsValue(directionValue)) + .Select(kvp => kvp.Key) + .ToArray(); + } + + /// + /// 根据方向值获取匹配的层名称数组(带缓存版本) + /// + /// 方向值 + /// 包含指定方向值的层名称数组 + public static string[] GetLayersByDirectionValueCached(int directionValue) + { + // 使用静态字典缓存结果,避免重复计算 + if (_directionCache.TryGetValue(directionValue, out var cachedResult)) + { + return cachedResult; + } + + var configs = GetLayerConfigs(); + var result = configs + .Where(kvp => kvp.Value.Direction.ContainsValue(directionValue)) + .Select(kvp => kvp.Key) + .ToArray(); + + _directionCache[directionValue] = result; + return result; + } + + /// + /// 获取所有可用的方向值 + /// + /// 所有方向值的集合 + public static HashSet GetAllDirectionValues() + { + var configs = GetLayerConfigs(); + return configs + .SelectMany(kvp => kvp.Value.Direction.Values) + .ToHashSet(); + } + /// /// 验证层名称是否有效 /// @@ -247,5 +319,22 @@ namespace LTEMvcApp.Models { return AllLayers.Contains(layerName); } + + /// + /// 清除所有缓存 + /// + public static void ClearCache() + { + _layerConfigsCache.Clear(); + _directionCache.Clear(); + } + + /// + /// 清除方向值缓存 + /// + public static void ClearDirectionCache() + { + _directionCache.Clear(); + } } } \ No newline at end of file diff --git a/LTEMvcApp/Models/LogsManager.cs b/LTEMvcApp/Models/LogsManager.cs index b771576..3047b25 100644 --- a/LTEMvcApp/Models/LogsManager.cs +++ b/LTEMvcApp/Models/LogsManager.cs @@ -40,59 +40,6 @@ namespace LTEMvcApp.Models { "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 实例字段 @@ -900,7 +847,21 @@ namespace LTEMvcApp.Models /// 层配置字典 public Dictionary GetLayerConfig() { - return layerConfig; + var configs= LogLayerTypes.GetLayerConfigs(); + var result = new Dictionary(); + foreach (var kvp in configs) + { + var config = kvp.Value; + result[kvp.Key] = new + { + color = config.Color, + dir = config.Direction, + debug = config.Debug != null ? new { level = config.Debug.Level, max_size = config.Debug.MaxSize } : null, + epc = config.EPC, + max = config.Max != null ? new { max_size = config.Max.MaxSize } : null + }; + } + return result; } #endregion