A:调整工具函数和JSON整理逻辑

This commit is contained in:
jimmy committed 2025-07-03 13:26:43 +08:00
1 parent 96e60137b2
commit 475fcdd2c0
8 files changed
+212 -60

No files matched your search

@@ -6,6 +6,7 @@ using Common.Logger;
using Common.Net.WebSocketConn;
using Common.Utils;
using Infrastructure.Models;
using Infrastructure.utils;
using Utils.ETW.Etw;
namespace Shell;
@@ -168,7 +169,7 @@ public class DispatchEngine
{
Success = true,
Data = serialize,
Message = "数据发送123",
Message = "程序信息发送",
Timestamp = AppInfoLastSendTime[keyValuePair.Key],
Type = AppConfig.ApplicationInfoSubscribe
};
@@ -225,7 +226,7 @@ public class DispatchEngine
public List<int> MonitorProcessList = new List<int>();
/// <summary>
/// 软件信息分发
/// 进行信息分发
/// </summary>
public void ProcessInfoDistribute()
{
@@ -236,31 +237,114 @@ public class DispatchEngine
return;
}
// 获取信息
/*
用户 A 订阅了 1、2、3 进程
用户 B 订阅了 5、6、7 进程
不同的的订阅的内容将进行不同的分发
*/
// 用户订阅的内容
foreach (var processDispatchModel in ProcessInfoDispatch)
{
// 获取所有信息
var connectionInfos =
GlobalNetworkMonitor.Instance.GetAllConnection(processDispatchModel.Value.ProcessIds);
// 检查是否发送,如果不发送,则跳过数据获取
// 间隔时间
var interval = processDispatchModel.Value.Interval;
// 上一次是否发送
var isHasLast = AppInfoLastSendTime.TryGetValue(processDispatchModel.Key, out DateTime lastSendTime);
// 上行总数据
long allBytesSent = 0;
// 下行总数据
long allBytesReceived = 0;
// 上行网速总数据
double allSendSpeed = 0;
// 下行网速总数据
double allReceiveSpeed = 0;
foreach (var connectionInfo in connectionInfos)
// 本次是否应该发送
var isShouldSend = false;
// 具有上一次,检查时间
if (isHasLast)
{
// 数据发送量
allBytesSent += connectionInfo.BytesSent;
allBytesReceived += connectionInfo.BytesReceived;
var intervalTime = (DateTime.Now - lastSendTime).TotalMilliseconds;
// 网速数据
allSendSpeed += connectionInfo.CurrentSendSpeed;
allReceiveSpeed += connectionInfo.CurrentReceiveSpeed;
isShouldSend = intervalTime >= interval;
}
// 没有上一次,直接发送
else
{
isShouldSend = true;
}
if (!isShouldSend)
{
continue;
}
// 获取用户的订阅信息
var dispatchModel = processDispatchModel.Value;
if (dispatchModel.ProcessIds == null || dispatchModel.ProcessIds.Count == 0)
{
continue;
}
List<ProcessType> pts = new List<ProcessType>();
foreach (var processId in dispatchModel.ProcessIds)
{
var connection = GlobalNetworkMonitor.Instance.GetConnection(processId);
var inspectProcess = SysInfoUtils.InspectProcess(processId);
if (inspectProcess == null)
{
continue;
}
ProcessType pt = new ProcessType();
// 上行总数据
long allBytesSent = 0;
// 下行总数据
long allBytesReceived = 0;
// 上行网速总数据
double allSendSpeed = 0;
// 下行网速总数据
double allReceiveSpeed = 0;
// 软件启动时间
var startTime = DateTime.Now;
// 统计所有连接的信息
foreach (var connectionInfo in connection)
{
// 数据发送量
allBytesSent += connectionInfo.BytesSent;
allBytesReceived += connectionInfo.BytesReceived;
// 网速数据
allSendSpeed += connectionInfo.CurrentSendSpeed;
allReceiveSpeed += connectionInfo.CurrentReceiveSpeed;
}
pt.ProcessName = inspectProcess.ProcessName;
pt.ProcessId = inspectProcess.ProcessId;
pt.StartTime = inspectProcess.StartTime;
pt.HasExited = inspectProcess.HasExited;
pt.ExitTime = inspectProcess.ExitTime;
pt.ExitCode = inspectProcess.ExitCode;
pt.UseMemory = inspectProcess.UseMemory;
pt.ThreadCount = inspectProcess.ThreadCount;
pt.MainModulePath = inspectProcess.MainModulePath;
pt.MainModuleName = inspectProcess.MainModuleName;
pt.TotalUploaded = allBytesSent;
pt.TotalDownloaded = allBytesReceived;
pt.UploadSpeed = allSendSpeed;
pt.DownloadSpeed = allReceiveSpeed;
pt.Connections = connection;
pts.Add(pt);
}
// 数据整理完毕,开始分发内容
var json = JsonHelper.ToJson(pts);
AppInfoLastSendTime[processDispatchModel.Key] = DateTime.Now;
var rm = new ResponseMessage
{
Success = true,
Data = json,
Message = "进程信息发送",
Timestamp = AppInfoLastSendTime[processDispatchModel.Key],
Type = AppConfig.ProcessInfoSubscribe
};
WebSocketManager.Instance.SendToClient(processDispatchModel.Key, rm);
}
}, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
}
@@ -285,7 +369,7 @@ public class DispatchModel
public class ProcessDispatchModel : DispatchModel
{
// 订阅的进程列表
public List<int> ProcessIds { get; set; }
public List<int>? ProcessIds { get; set; }
}
/// <summary>
@@ -293,6 +377,15 @@ public class ProcessDispatchModel : DispatchModel
/// </summary>
public class SubscriptionInfo
{
public string SubscriptionType { get; set; }
public int Interval { get; set; }
public string SubscriptionType { get; set; }
public int Interval { get; set; }
}
/// <summary>
/// 进程订阅信息
/// </summary>
public class SubscriptionProcessInfo : SubscriptionInfo
{
// 订阅的进程列表
public List<int> ProcessIds { get; set; }
}
@@ -354,7 +354,7 @@ public class WebSocketManager
}
else
{
Log.Error4Ctx("无法获取有效客户端 uuid !");
Log.Error4Ctx($"无法获取有效客户端 uuid !, uuid: {uuid}, socketId: {socketId}");
}
return ans;
@@ -1,4 +1,6 @@
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Common.Utils;
@@ -7,7 +9,8 @@ public static class JsonHelper
public static readonly JsonSerializerOptions CamelCaseOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
WriteIndented = true,
Converters = { new IpAddressConverter() }
};
public static string ToJson<T>(T value) =>
@@ -16,3 +19,21 @@ public static class JsonHelper
public static T? FromJson<T>(string json) =>
JsonSerializer.Deserialize<T>(json, CamelCaseOptions);
}
/*
IPAddress.ScopeId 属性在某些情况下(如 IPv4 类型)是不被支持的,会抛出异常。
这是 .NET 的设计问题,访问 ScopeId 只有在 IPv6 地址中才有意义,在 IPv4 中访问它就会抛出这个 10045 错误。
*/
public class IpAddressConverter : JsonConverter<IPAddress>
{
public override IPAddress Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var ipString = reader.GetString() ?? String.Empty;
return IPAddress.Parse(ipString);
}
public override void Write(Utf8JsonWriter writer, IPAddress value, JsonSerializerOptions options)
{
writer.WriteStringValue(value?.ToString());
}
}
@@ -68,11 +68,39 @@ public static class SysInfoUtils
/// <param name="pid"></param>
/// <returns></returns>
/// <exception cref="ExceptionExpand"></exception>
public static ProgramInfo InspectProcess(int pid)
public static ProgramInfo? InspectProcess(int pid)
{
try
{
var proc = Process.GetProcessById(pid);
// 1. 预检查:验证进程是否存在
Process proc;
try
{
proc = Process.GetProcessById(pid);
}
catch (ArgumentException)
{
Log.Information($"进程 {pid} 不存在");
return null; // 返回 null 而不是抛异常
}
// 2. 检查进程是否已退出
bool hasExited = false;
try
{
hasExited = proc.HasExited;
}
catch (Exception ex)
{
Log.Information($"无法检查进程 {pid} 状态: {ex.Message}");
return null; // 如果连状态都无法检查,直接返回 null
}
if (hasExited)
{
Log.Information($"进程 {pid} 已退出");
return null; // 或者返回一个标记为已退出的 ProgramInfo 对象
}
#region 检查缓存
@@ -104,7 +132,7 @@ public static class SysInfoUtils
exeInfo.StartTime = DateTime.MinValue;
}
// 安全获取退出状态
// 安全获取退出状态(再次检查,因为状态可能在执行过程中改变)
try
{
exeInfo.HasExited = proc.HasExited;
@@ -161,7 +189,6 @@ public static class SysInfoUtils
}
catch (Exception ex)
{
// 如果仍然无法获取退出信息,记录日志但不抛出异常
Log.Information($"无法获取进程 {pid} 的退出信息: {ex.Message}");
exeInfo.ExitTime = null;
exeInfo.ExitCode = null;
@@ -169,12 +196,11 @@ public static class SysInfoUtils
}
else
{
// 对于正在运行的进程,设置默认值
exeInfo.ExitTime = null; // 或者 DateTime.MinValue,取决于 ProgramInfo.ExitTime 的类型
exeInfo.ExitCode = null; // 或者 0,取决于 ProgramInfo.ExitCode 的类型
exeInfo.ExitTime = null;
exeInfo.ExitCode = null;
}
// MainModule 是一个涉及 native 调用的属性,不建议频繁调用,尤其在枚举大量进程时可能影响性能。
// 获取版本信息
if (exeInfo.MainModulePath != null)
{
try
@@ -193,7 +219,7 @@ public static class SysInfoUtils
}
}
// 获取软件 Icon 【不一定存在】
// 获取软件 Icon
try
{
var iconBase64 = IconHelper.GetIconBase64(exeInfo.MainModulePath);
@@ -209,31 +235,36 @@ public static class SysInfoUtils
ProcessCache.Instance.Set(pck, exeInfo);
return exeInfo;
}
// 捕获各种可能的异常
// 3. 关键改进:捕获异常但不再抛出,而是返回 null
catch (ArgumentException ex)
{
Log.Information($"获取进程信息失败:{ex.Message}");
throw ExceptionEnum.ProcessGetException;
Log.Warning($"获取进程信息失败:{ex.Message}"); // 改为 Warning 级别
return null; // 返回 null 而不是抛异常
}
catch (InvalidOperationException ex)
{
Log.Information($"进程 {pid} 已退出或无法访问:{ex.Message}");
throw ExceptionEnum.ProcessGetException;
Log.Warning($"进程 {pid} 已退出或无法访问:{ex.Message}");
return null;
}
catch (System.ComponentModel.Win32Exception ex)
{
Log.Information($"无权限访问进程 {pid}:{ex.Message}");
throw ExceptionEnum.ProcessGetException;
Log.Warning($"无权限访问进程 {pid}:{ex.Message}");
return null;
}
catch (UnauthorizedAccessException ex)
{
Log.Information($"拒绝访问进程 {pid}:{ex.Message}");
throw ExceptionEnum.ProcessGetException;
Log.Warning($"拒绝访问进程 {pid}:{ex.Message}");
return null;
}
catch (Exception ex)
{
Log.Information($"获取进程 {pid} 信息时发生未知错误:{ex.Message}");
throw ExceptionEnum.ProcessGetException;
Log.Error($"获取进程 {pid} 信息时发生未知错误:{ex.Message}"); // 未知错误用 Error 级别
return null;
}
finally
{
// 4. 添加资源清理(如果需要)
// proc?.Dispose(); // 注意:Process 对象通常不需要手动释放,GC 会处理
}
}
@@ -12,6 +12,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fcca5cfb955e146648d91eb22ffe4627a84930_003Fae_003Fc940e3b4_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AETWTraceEventSource_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25b12134b1124ffbab73641db2e54e5b310830_003F01_003F4bae5ee3_003FETWTraceEventSource_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AETWTraceEventSource_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25b12134b1124ffbab73641db2e54e5b310830_003F01_003F4bae5ee3_003FETWTraceEventSource_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fbd1d5c50194fea68ff3559c160230b0ab50f5acf4ce3061bffd6d62958e2182_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExecutionContext_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F9eda537f15ea23cdfae523c19e87eb303a3ded88937ae7e55919387a43f70_003FExecutionContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileVersionInfo_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F7fad91e527c1434bb313ddbc78144605b8a0_003F3f_003F911bc64d_003FFileVersionInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFile_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F211e6f3b24fa438a92f1815153647ce2c8f908_003F71_003F40854420_003FFile_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -24,6 +25,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIWebSocketConnectionInfo_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa7d96aff8e344c1d9aa8042f229d493cae00_003F54_003Ff0e67f89_003FIWebSocketConnectionInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIWebSocketConnection_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa7d96aff8e344c1d9aa8042f229d493cae00_003Fc1_003Fb154f2eb_003FIWebSocketConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIWebSocketConnection_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa7d96aff8e344c1d9aa8042f229d493cae00_003Fc1_003Fb154f2eb_003FIWebSocketConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AJsonConverter_00601_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F315ee97d207b44bebef0c3c849c1e3fa9fb18_003F65_003Fdcbd50cc_003FJsonConverter_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKernelTraceEventParser_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25b12134b1124ffbab73641db2e54e5b310830_003F24_003Fd19d02f2_003FKernelTraceEventParser_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKernelTraceEventParser_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25b12134b1124ffbab73641db2e54e5b310830_003F24_003Fd19d02f2_003FKernelTraceEventParser_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALazy_00601_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F211e6f3b24fa438a92f1815153647ce2c8f908_003F74_003F173162e6_003FLazy_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -39,6 +41,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AReadOnlyCollectionBase_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4c1fd115dbe5414db1b4da1de3e96c5819910_003F04_003Fcae9fe22_003FReadOnlyCollectionBase_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASemaphoreSlim_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F211e6f3b24fa438a92f1815153647ce2c8f908_003Fe9_003F4d4110fd_003FSemaphoreSlim_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F211e6f3b24fa438a92f1815153647ce2c8f908_003Ff1_003F7b5a67e3_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5aeb6167299d4cfba30c86624130edbcc90938_003Fac_003F9cba3bcf_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATask_002Ecs_002Fl_003AC_0021_003FUsers_003Fyllyo_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fa77b231cea33ff338c41dc7869d6c493d4dae137ff51e342173efa61d933_003FTask_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATcpIpConnectTraceData_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25b12134b1124ffbab73641db2e54e5b310830_003F93_003Fd6e6c065_003FTcpIpConnectTraceData_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATcpIpSendTraceData_002Ecs_002Fl_003AC_0021_003FUsers_003Fcharlatans_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F25b12134b1124ffbab73641db2e54e5b310830_003F28_003Fce7c9cfa_003FTcpIpSendTraceData_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -7,6 +7,7 @@ using Common;
using Common.Logger;
using Common.Net;
using Common.Net.WebSocketConn;
using Common.Utils;
using Infrastructure.utils;
using Utils.ETW;
using Utils.ETW.Core;
@@ -87,7 +88,7 @@ public partial class WebPanel : UserControl
string json = args.WebMessageAsJson;
// 反序列化为 C# 对象
var msg = JsonSerializer.Deserialize<JsMessage>(json);
var msg = JsonHelper.FromJson<JsMessage>(json);
Log.Information(json);
Log.Information(msg?.Channel);
@@ -165,8 +166,8 @@ public partial class WebPanel : UserControl
public class JsMessage
{
[JsonPropertyName("channel")] public string Channel { get; set; }
[JsonPropertyName("payload")] public JsData Payload { get; set; }
public string Channel { get; set; }
public JsData Payload { get; set; }
public override string ToString()
{
@@ -176,8 +177,8 @@ public class JsMessage
public class JsData
{
[JsonPropertyName("title")] public string Title { get; set; }
[JsonPropertyName("content")] public string Content { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public override string ToString()
{
@@ -273,14 +273,16 @@ public class EnhancedEtwNetworkManager : IDisposable
{
// 获取进程详细信息
var inspectProcess = SysInfoUtils.InspectProcess(processInfo.ProcessId);
if (inspectProcess != null)
{
// 更新应用程序信息
GlobalNetworkMonitor.Instance.UpdateApplicationInfo(
processInfo.ProcessId,
inspectProcess
);
// 更新应用程序信息
GlobalNetworkMonitor.Instance.UpdateApplicationInfo(
processInfo.ProcessId,
inspectProcess
);
processInfo.NeedsUpdate = false;
processInfo.NeedsUpdate = false;
}
}
catch (Exception ex)
{
@@ -1,5 +1,6 @@
using System.Runtime.CompilerServices;
using System.Text.Json;
using Common.Utils;
using Utils.ETW.Core;
namespace Utils.ETW.Etw;
@@ -57,7 +58,7 @@ public class NetworkMonitorUsageExample
// 获取网络监控快照
var snapshot = GlobalNetworkMonitor.Instance.GetSnapshot();
var serialize = JsonSerializer.Serialize(snapshot);
var serialize = JsonHelper.ToJson(snapshot);
Console.WriteLine("=================================================");
Console.WriteLine(serialize);
Console.WriteLine("=================================================");
@@ -182,7 +183,7 @@ public class NetworkMonitorUsageExample
// };
//
// // 序列化为JSON
// var json = JsonSerializer.Serialize(pushData);
// var json = JsonHelper.ToJson(pushData);
//
// // 这里应该通过WebSocket发送数据
// // await websocketClient.SendAsync(json);