├── src ├── SocketTesting │ ├── SocketDto.Test │ │ ├── GlobalUsings.cs │ │ ├── SocketDtoUnitTest.cs │ │ ├── SystemProcessUnitTest.cs │ │ ├── ResponseProcessListUnitTest.cs │ │ ├── SocketDto.Test.csproj │ │ ├── UpdateGeneralProcessListUnitTest.cs │ │ └── NumberFormatUnitTest.cs │ ├── SocketTest.Client │ │ ├── Assets │ │ │ ├── logo.ico │ │ │ ├── logo.png │ │ │ └── avalonia-logo.ico │ │ ├── Roots.xml │ │ ├── App.axaml │ │ ├── Converters │ │ │ ├── EnumToDescriptionConverter.cs │ │ │ ├── AlarmStatusToForegroundConverter.cs │ │ │ ├── UsageToFormatConverter.cs │ │ │ ├── UsageToForegroundConverter.cs │ │ │ ├── ProcessStatusToForegroundConverter.cs │ │ │ └── ProcessPowerUsageToForegroundConverter.cs │ │ ├── Views │ │ │ ├── MainWindow.axaml.cs │ │ │ └── MainWindow.axaml │ │ ├── App.axaml.cs │ │ ├── Program.cs │ │ ├── app.manifest │ │ ├── Extensions │ │ │ └── RangObservableCollection.cs │ │ ├── SocketTest.Client.csproj │ │ ├── Models │ │ │ └── ProcessItemModel.cs │ │ └── ViewModels │ │ │ └── MainWindowViewModel.cs │ ├── SocketTest.Server │ │ ├── Assets │ │ │ ├── logo.ico │ │ │ ├── logo.png │ │ │ └── avalonia-logo.ico │ │ ├── Roots.xml │ │ ├── App.axaml │ │ ├── Mock │ │ │ ├── MockConst.cs │ │ │ └── MockUtil.cs │ │ ├── Views │ │ │ ├── MainWindow.axaml.cs │ │ │ └── MainWindow.axaml │ │ ├── App.axaml.cs │ │ ├── Program.cs │ │ ├── app.manifest │ │ ├── SocketTest.Server.csproj │ │ └── ViewModels │ │ │ └── MainWindowViewModel.cs │ └── SocketDto │ │ ├── GlobalUsing.cs │ │ ├── AutoCommand │ │ ├── ChangeProcessList.cs │ │ └── UpdateProcessList.cs │ │ ├── Enums │ │ ├── GpuEngine.cs │ │ ├── TerminalType.cs │ │ ├── ProcessType.cs │ │ ├── PowerUsage.cs │ │ ├── ProcessStatus.cs │ │ └── AlarmStatus.cs │ │ ├── Requests │ │ ├── RequestProcessList.cs │ │ ├── RequestServiceInfo.cs │ │ ├── RequestTargetType.cs │ │ ├── RequestUdpAddress.cs │ │ └── RequestProcessIDList.cs │ │ ├── SocketDto.csproj │ │ ├── Response │ │ ├── ResponseTargetType.cs │ │ ├── ResponseProcessIDList.cs │ │ ├── ResponseUdpAddress.cs │ │ ├── ResponseServiceInfo.cs │ │ └── ResponseProcessList.cs │ │ └── Udp │ │ ├── UpdateRealtimeProcessList.cs │ │ └── UpdateGeneralProcessList.cs └── ObjectBinarySerializationTest │ └── SerializationTest │ ├── Models │ ├── RequestOrganizations.cs │ ├── ResponseOrganizations.cs │ ├── Organization.cs │ ├── Department.cs │ ├── Employee.cs │ └── ProcessData.cs │ ├── Program.cs │ ├── SerializeUtils │ ├── ISerializeHelper.cs │ └── Helpers │ │ ├── JsonSerializeHelper.cs │ │ ├── ProtobufSerializeHelper.cs │ │ ├── MessagePackSerializeHelper.cs │ │ └── CustomSerializeHelper.cs │ ├── GlobalUsing.cs │ ├── SerializationTest.csproj │ └── Test │ └── BenchmarkTest.cs ├── imgs ├── client.gif └── server.gif ├── LICENSE ├── SocketTest.sln ├── .gitignore └── README.md /src/SocketTesting/SocketDto.Test/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; 2 | -------------------------------------------------------------------------------- /imgs/client.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/imgs/client.gif -------------------------------------------------------------------------------- /imgs/server.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/imgs/server.gif -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Assets/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketTest.Client/Assets/logo.ico -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketTest.Client/Assets/logo.png -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Assets/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketTest.Server/Assets/logo.ico -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketTest.Server/Assets/logo.png -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto.Test/SocketDtoUnitTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketDto.Test/SocketDtoUnitTest.cs -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto.Test/SystemProcessUnitTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketDto.Test/SystemProcessUnitTest.cs -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Assets/avalonia-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketTest.Client/Assets/avalonia-logo.ico -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Assets/avalonia-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketTest.Server/Assets/avalonia-logo.ico -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto.Test/ResponseProcessListUnitTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet9/CsharpSocketTest/HEAD/src/SocketTesting/SocketDto.Test/ResponseProcessListUnitTest.cs -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/GlobalUsing.cs: -------------------------------------------------------------------------------- 1 | global using CodeWF.EventBus; 2 | global using CodeWF.NetWeaver; 3 | global using CodeWF.NetWeaver.Base; 4 | global using System.ComponentModel; 5 | -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Models/RequestOrganizations.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.Models; 2 | 3 | [ProtoContract] 4 | [MessagePackObject] 5 | public class RequestOrganizations 6 | { 7 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Program.cs: -------------------------------------------------------------------------------- 1 | // 运行基准测试 2 | //BenchmarkRunner.Run(); 3 | 4 | // 普通测试 5 | //BenchmarkTest.Test(); 6 | 7 | BenchmarkTest.TestBit(); 8 | Console.ReadKey(); -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/AutoCommand/ChangeProcessList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.AutoCommand; 2 | 3 | /// 4 | /// 进程结构信息 5 | /// 6 | [NetHead(12, 1)] 7 | public class ChangeProcessList : INetObject 8 | { 9 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Enums/GpuEngine.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Enums; 2 | 3 | /// 4 | /// GPU引擎 5 | /// 6 | public enum GpuEngine 7 | { 8 | [Description("无")] None, 9 | [Description("GPU 0 - 3D")] Gpu03D 10 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Enums/TerminalType.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Enums; 2 | 3 | /// 4 | /// 终端类型 5 | /// 6 | public enum TerminalType 7 | { 8 | [Description("服务端")] Server, 9 | [Description("客户端")] Client 10 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/SerializeUtils/ISerializeHelper.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.SerializeUtils; 2 | 3 | public interface ISerializeHelper 4 | { 5 | byte[] Serialize(T data); 6 | 7 | T? Deserialize(byte[] buffer); 8 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Enums/ProcessType.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Enums; 2 | 3 | /// 4 | /// 进程类型 5 | /// 6 | public enum ProcessType 7 | { 8 | [Description("应用")] Application, 9 | [Description("后台进程")] BackgroundProcess 10 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Requests/RequestProcessList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto; 2 | 3 | /// 4 | /// 请求进程信息 5 | /// 6 | [NetHead(9, 1)] 7 | public class RequestProcessList : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Requests/RequestServiceInfo.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Requests; 2 | 3 | /// 4 | /// 请求基本信息 5 | /// 6 | [NetHead(5, 1)] 7 | public class RequestServiceInfo : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Requests/RequestTargetType.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Requests; 2 | 3 | /// 4 | /// 请求目标类型 5 | /// 6 | [NetHead(1, 1)] 7 | public class RequestTargetType : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Requests/RequestUdpAddress.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Requests; 2 | 3 | /// 4 | /// 请求Udp组播地址 5 | /// 6 | [NetHead(3, 1)] 7 | public class RequestUdpAddress : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Requests/RequestProcessIDList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Requests; 2 | 3 | /// 4 | /// 请求进程ID列表信息 5 | /// 6 | [NetHead(7, 1)] 7 | public class RequestProcessIDList : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Enums/PowerUsage.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Enums; 2 | 3 | /// 4 | /// 电源使用情况 5 | /// 6 | public enum PowerUsage 7 | { 8 | [Description("非常低")] VeryLow, 9 | [Description("低")] Low, 10 | [Description("中")] Moderate, 11 | [Description("高")] High, 12 | [Description("非常高")] VeryHigh 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Roots.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Roots.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Enums/ProcessStatus.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Enums; 2 | 3 | /// 4 | /// 进程运行状态 5 | /// 6 | public enum ProcessStatus 7 | { 8 | [Description("新建状态")] New, 9 | [Description("就绪状态")] Ready, 10 | [Description("运行状态")] Running, 11 | [Description("阻塞状态")] Blocked, 12 | [Description("终止状态")] Terminated 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Enums/AlarmStatus.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Enums; 2 | 3 | /// 4 | /// 进程告警状态(没有意义,只用于测试枚举位域使用) 5 | /// 6 | [Flags] 7 | public enum AlarmStatus 8 | { 9 | [Description("正常")] Normal = 0, 10 | [Description("超时")] Overtime = 1, 11 | [Description("超限")] OverLimit = 2, 12 | [Description("切换用户")] UserChanged = 4 13 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Models/ResponseOrganizations.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.Models; 2 | 3 | [ProtoContract] 4 | [MessagePackObject] 5 | public class ResponseOrganizations 6 | { 7 | /// 8 | /// Id 9 | /// 10 | [ProtoMember(1)] 11 | [Key(0)] 12 | public List? Organizations { get; set; } 13 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/App.axaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/AutoCommand/UpdateProcessList.cs: -------------------------------------------------------------------------------- 1 | using SocketDto.Response; 2 | 3 | namespace SocketDto.AutoCommand; 4 | 5 | /// 6 | /// 更新进程信息 7 | /// 8 | [NetHead(11, 1)] 9 | public class UpdateProcessList : INetObject 10 | { 11 | /// 12 | /// 进程列表 13 | /// 14 | public List? Processes { get; set; } 15 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/SocketDto.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/App.axaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/SerializeUtils/Helpers/JsonSerializeHelper.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.SerializeUtils.Helpers; 2 | 3 | public class JsonSerializeHelper : ISerializeHelper 4 | { 5 | public byte[] Serialize(T data) 6 | { 7 | return JsonSerializer.SerializeToUtf8Bytes(data); 8 | } 9 | 10 | public T? Deserialize(byte[] buffer) 11 | { 12 | return JsonSerializer.Deserialize(buffer); 13 | } 14 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Response/ResponseTargetType.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Response; 2 | 3 | /// 4 | /// 响应目标终端类型 5 | /// 6 | [NetHead(2, 1)] 7 | public class ResponseTargetType : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | 14 | 15 | /// 16 | /// 终端类型,0:Server,1:Client 17 | /// 18 | public byte Type { get; set; } 19 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Response/ResponseProcessIDList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Response; 2 | 3 | /// 4 | /// 响应请求进程ID列表信息 5 | /// 6 | [NetHead(8, 1)] 7 | public class ResponseProcessIDList : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | 14 | /// 15 | /// 进程ID数组,有顺序,更新进程实时数据包需要根据该数组查找进程、更新数据 16 | /// 17 | public int[]? IDList { get; set; } 18 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/GlobalUsing.cs: -------------------------------------------------------------------------------- 1 | global using BenchmarkDotNet.Attributes; 2 | global using LoremNET; 3 | global using MessagePack; 4 | global using ProtoBuf; 5 | global using SerializationTest.Models; 6 | global using SerializationTest.SerializeUtils; 7 | global using SerializationTest.SerializeUtils.Helpers; 8 | global using SerializationTest.Test; 9 | global using System.Diagnostics; 10 | global using System.Reflection; 11 | global using System.Text; 12 | global using System.Text.Json; 13 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Response/ResponseUdpAddress.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Response; 2 | 3 | /// 4 | /// 响应Udp组播地址 5 | /// 6 | [NetHead(4, 1)] 7 | public class ResponseUdpAddress : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | 14 | 15 | /// 16 | /// 组播地址 17 | /// 18 | public string? Ip { get; set; } 19 | 20 | /// 21 | /// 组播端口 22 | /// 23 | public int Port { get; set; } 24 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/SerializeUtils/Helpers/ProtobufSerializeHelper.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.SerializeUtils.Helpers; 2 | 3 | public class ProtoBufSerializeHelper : ISerializeHelper 4 | { 5 | public byte[] Serialize(T data) 6 | { 7 | using var stream = new MemoryStream(); 8 | Serializer.Serialize(stream, data); 9 | return stream.ToArray(); 10 | } 11 | 12 | public T Deserialize(byte[] buffer) 13 | { 14 | using var stream = new MemoryStream(buffer); 15 | return Serializer.Deserialize(stream); 16 | } 17 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Mock/MockConst.cs: -------------------------------------------------------------------------------- 1 | namespace SocketTest.Server.Mock; 2 | 3 | public class MockConst 4 | { 5 | /// 6 | /// 服务端更新UDP数据间隔,单位ms 7 | /// 8 | public const int UdpUpdateMilliseconds = 500; 9 | 10 | /// 11 | /// 服务端发送UDP实时数据间隔,单位ms 12 | /// 13 | public const int UdpSendRealtimeMilliseconds = 500; 14 | 15 | /// 16 | /// 服务端发送UDP一般数据间隔,单位ms 17 | /// 18 | public const int UdpSendGeneralMilliseconds = 1000; 19 | 20 | /// 21 | /// 客户端处理UDP数据间隔,单位ms 22 | /// 23 | public const int UdpDillMilliseconds = 150; 24 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Converters/EnumToDescriptionConverter.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Data.Converters; 2 | using CodeWF.Tools.Extensions; 3 | using System; 4 | using System.Globalization; 5 | 6 | namespace SocketTest.Client.Converters; 7 | 8 | public class EnumToDescriptionConverter : IValueConverter 9 | { 10 | public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 11 | { 12 | if (value is not Enum enumValue) return value; 13 | 14 | return enumValue.GetDescription(); 15 | } 16 | 17 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/SerializationTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net10.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Views/MainWindow.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | using Avalonia.Controls.Notifications; 3 | using Avalonia.Interactivity; 4 | using SocketTest.Client.ViewModels; 5 | 6 | namespace SocketTest.Client.Views; 7 | 8 | public partial class MainWindow : Window 9 | { 10 | public MainWindow() 11 | { 12 | InitializeComponent(); 13 | } 14 | 15 | protected override void OnLoaded(RoutedEventArgs e) 16 | { 17 | base.OnLoaded(e); 18 | var vm = DataContext as MainWindowViewModel; 19 | if (vm is not { NotificationManager: null }) return; 20 | var topLevel = GetTopLevel(this); 21 | vm.NotificationManager = 22 | new WindowNotificationManager(topLevel) { MaxItems = 3 }; 23 | } 24 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Converters/AlarmStatusToForegroundConverter.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Data.Converters; 2 | using Avalonia.Media; 3 | using SocketDto.Enums; 4 | using System; 5 | using System.Globalization; 6 | 7 | namespace SocketTest.Client.Converters; 8 | 9 | public class AlarmStatusToForegroundConverter : IValueConverter 10 | { 11 | public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 12 | { 13 | if (value is not AlarmStatus status) return Brushes.Red; 14 | return status == AlarmStatus.Normal ? Brushes.Green : Brushes.Red; 15 | } 16 | 17 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Converters/UsageToFormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using Avalonia.Data.Converters; 4 | using Avalonia.Media; 5 | 6 | namespace SocketTest.Client.Converters; 7 | 8 | public class UsageToFormatConverter : IValueConverter 9 | { 10 | public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 11 | { 12 | if (value == null || !short.TryParse(value.ToString(), out var bValue)) return Brushes.Green; 13 | 14 | var dValue = bValue * 1.0 / 1000; 15 | return dValue.ToString("P1"); 16 | } 17 | 18 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/App.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls.ApplicationLifetimes; 3 | using Avalonia.Markup.Xaml; 4 | using SocketTest.Client.ViewModels; 5 | using SocketTest.Client.Views; 6 | 7 | namespace SocketTest.Client; 8 | 9 | public class App : Application 10 | { 11 | public override void Initialize() 12 | { 13 | AvaloniaXamlLoader.Load(this); 14 | } 15 | 16 | public override void OnFrameworkInitializationCompleted() 17 | { 18 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 19 | desktop.MainWindow = new MainWindow 20 | { 21 | DataContext = new MainWindowViewModel() 22 | }; 23 | 24 | base.OnFrameworkInitializationCompleted(); 25 | } 26 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Views/MainWindow.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls; 3 | using Avalonia.Controls.Notifications; 4 | using Avalonia.Interactivity; 5 | using Avalonia.Threading; 6 | using SocketTest.Server.ViewModels; 7 | 8 | namespace SocketTest.Server.Views; 9 | 10 | public partial class MainWindow : Window 11 | { 12 | public MainWindow() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | protected override void OnLoaded(RoutedEventArgs e) 18 | { 19 | base.OnLoaded(e); 20 | 21 | var vm = DataContext as MainWindowViewModel; 22 | if (vm is not { NotificationManager: null }) return; 23 | 24 | var topLevel = GetTopLevel(this); 25 | vm.NotificationManager = 26 | new WindowNotificationManager(topLevel) { MaxItems = 3 }; 27 | } 28 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/App.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls; 3 | using Avalonia.Controls.ApplicationLifetimes; 4 | using Avalonia.Controls.Notifications; 5 | using Avalonia.Markup.Xaml; 6 | using SocketTest.Server.ViewModels; 7 | using SocketTest.Server.Views; 8 | 9 | namespace SocketTest.Server; 10 | 11 | public class App : Application 12 | { 13 | public override void Initialize() 14 | { 15 | AvaloniaXamlLoader.Load(this); 16 | } 17 | 18 | public override void OnFrameworkInitializationCompleted() 19 | { 20 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 21 | 22 | { 23 | desktop.MainWindow = new MainWindow(); 24 | desktop.MainWindow.DataContext = new MainWindowViewModel(); 25 | } 26 | 27 | base.OnFrameworkInitializationCompleted(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Converters/UsageToForegroundConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using Avalonia.Data.Converters; 4 | using Avalonia.Media; 5 | 6 | namespace SocketTest.Client.Converters; 7 | 8 | public class UsageToForegroundConverter : IValueConverter 9 | { 10 | public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 11 | { 12 | if (value == null || !short.TryParse(value.ToString(), out var bValue)) return Brushes.Green; 13 | 14 | var dValue = bValue * 1.0 / 10; 15 | return dValue switch 16 | { 17 | < 5 => Brushes.LightGreen, 18 | < 10 => Brushes.Green, 19 | < 20 => Brushes.DarkOrange, 20 | _ => Brushes.Red 21 | }; 22 | } 23 | 24 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 25 | { 26 | throw new NotImplementedException(); 27 | } 28 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Converters/ProcessStatusToForegroundConverter.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Data.Converters; 2 | using Avalonia.Media; 3 | using SocketDto.Enums; 4 | using System; 5 | using System.Globalization; 6 | 7 | namespace SocketTest.Client.Converters; 8 | 9 | public class ProcessStatusToForegroundConverter : IValueConverter 10 | { 11 | public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 12 | { 13 | if (value is ProcessStatus status) 14 | { 15 | return status switch 16 | { 17 | < ProcessStatus.Running => Brushes.CadetBlue, 18 | > ProcessStatus.Running => Brushes.Green, 19 | _ => Brushes.Red 20 | }; 21 | } 22 | 23 | return Brushes.CadetBlue; 24 | } 25 | 26 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avalonia; 3 | using CodeWF.Log.Core; 4 | using ReactiveUI.Avalonia; 5 | 6 | namespace SocketTest.Client; 7 | 8 | internal sealed class Program 9 | { 10 | // Initialization code. Don't use any Avalonia, third-party APIs or any 11 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized 12 | // yet and stuff might break. 13 | [STAThread] 14 | public static void Main(string[] args) 15 | { 16 | Logger.TimeFormat = "yyyy-MM-dd HH:mm:ss.fff"; 17 | BuildAvaloniaApp() 18 | .StartWithClassicDesktopLifetime(args); 19 | } 20 | 21 | // Avalonia configuration, don't remove; also used by visual designer. 22 | public static AppBuilder BuildAvaloniaApp() 23 | { 24 | return AppBuilder.Configure() 25 | .UsePlatformDetect() 26 | .WithInterFont() 27 | .LogToTrace() 28 | .UseReactiveUI(); 29 | } 30 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using ReactiveUI.Avalonia; 3 | using System; 4 | using CodeWF.Log.Core; 5 | 6 | namespace SocketTest.Server; 7 | 8 | internal sealed class Program 9 | { 10 | // Initialization code. Don't use any Avalonia, third-party APIs or any 11 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized 12 | // yet and stuff might break. 13 | [STAThread] 14 | public static void Main(string[] args) 15 | { 16 | Logger.TimeFormat = "yyyy-MM-dd HH:mm:ss.fff"; 17 | BuildAvaloniaApp() 18 | .StartWithClassicDesktopLifetime(args); 19 | } 20 | 21 | // Avalonia configuration, don't remove; also used by visual designer. 22 | public static AppBuilder BuildAvaloniaApp() 23 | { 24 | return AppBuilder.Configure() 25 | .UsePlatformDetect() 26 | .WithInterFont() 27 | .LogToTrace() 28 | .UseReactiveUI(); 29 | } 30 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Converters/ProcessPowerUsageToForegroundConverter.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Data.Converters; 2 | using Avalonia.Media; 3 | using SocketDto.Enums; 4 | using System; 5 | using System.Globalization; 6 | 7 | namespace SocketTest.Client.Converters; 8 | 9 | public class ProcessPowerUsageToForegroundConverter : IValueConverter 10 | { 11 | public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) 12 | { 13 | if (value == null) return Brushes.Green; 14 | 15 | var powerUsageType = 16 | (PowerUsage)Enum.Parse(typeof(PowerUsage), value.ToString()!); 17 | return powerUsageType switch 18 | { 19 | PowerUsage.VeryLow or PowerUsage.Low => Brushes.LightGreen, 20 | PowerUsage.Moderate => Brushes.Green, 21 | PowerUsage.High => Brushes.DarkOrange, 22 | _ => Brushes.Red 23 | }; 24 | } 25 | 26 | public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Dotnet9(dotnet9.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto.Test/SocketDto.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | all 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/Extensions/RangObservableCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Collections.Specialized; 5 | 6 | namespace SocketTest.Client.Extensions; 7 | 8 | public class RangObservableCollection : ObservableCollection 9 | { 10 | private bool SuppressNotification { get; set; } = false; 11 | 12 | protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) 13 | { 14 | if (!SuppressNotification) 15 | { 16 | base.OnCollectionChanged(e); 17 | } 18 | } 19 | 20 | public new void Clear() 21 | { 22 | Items.Clear(); 23 | OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); 24 | } 25 | 26 | public void AddRange(IEnumerable collection) 27 | { 28 | if (collection == null) 29 | { 30 | throw new ArgumentNullException(nameof(collection)); 31 | } 32 | 33 | SuppressNotification = true; 34 | 35 | foreach (var item in collection) 36 | { 37 | Items.Add(item); 38 | } 39 | 40 | SuppressNotification = false; 41 | OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); 42 | } 43 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Udp/UpdateRealtimeProcessList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Udp; 2 | 3 | /// 4 | /// 更新进程变化信息,序列化和反序列不能加压缩,部分双精度因为有效位数太长,可能导致UDP包过大而发送失败,所以UDP包不要加压缩 5 | /// 6 | [NetHead(200, 1)] 7 | public class UpdateRealtimeProcessList : INetObject 8 | { 9 | /// 10 | /// 总数据大小 11 | /// 12 | public int TotalSize { get; set; } 13 | 14 | /// 15 | /// 分页大小 16 | /// 17 | public int PageSize { get; set; } 18 | 19 | /// 20 | /// 总页数 21 | /// 22 | public int PageCount { get; set; } 23 | 24 | /// 25 | /// 页索引 26 | /// 27 | public int PageIndex { get; set; } 28 | 29 | /// 30 | /// 一个进程占2字节(short) 31 | /// 32 | public byte[] Cpus { get; set; } = null!; 33 | 34 | /// 35 | /// 一个进程占2字节(short) 36 | /// 37 | [NetFieldOffset(10, 10)] 38 | public byte[] Memories { get; set; } = null!; 39 | 40 | /// 41 | /// 一个进程占2字节(short) 42 | /// 43 | [NetFieldOffset(20, 10)] 44 | public byte[] Disks { get; set; } = null!; 45 | 46 | /// 47 | /// 一个进程占2字节(short) 48 | /// 49 | [NetFieldOffset(30, 10)] 50 | public byte[] Networks { get; set; } = null!; 51 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Response/ResponseServiceInfo.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Response; 2 | 3 | /// 4 | /// 响应基本信息 5 | /// 6 | [NetHead(6, 1)] 7 | public class ResponseServiceInfo : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | 14 | /// 15 | /// 操作系统名称 16 | /// 17 | public string? OS { get; set; } 18 | 19 | /// 20 | /// 系统内存大小(单位GB) 21 | /// 22 | public byte MemorySize { get; set; } 23 | 24 | /// 25 | /// 处理器个数 26 | /// 27 | public byte ProcessorCount { get; set; } 28 | 29 | /// 30 | /// 硬盘总容量(单位GB) 31 | /// 32 | public short DiskSize { get; set; } 33 | 34 | /// 35 | /// 网络带宽(单位Mbps) 36 | /// 37 | public short NetworkBandwidth { get; set; } 38 | 39 | /// 40 | /// 服务器IP地址,多个地址以“,”分隔 41 | /// 42 | public string? Ips { get; set; } 43 | 44 | /// 45 | /// 通信对象时间戳起始年份,比如:2023,表示2023年1月1号开始计算时间戳,后面的时间戳都以这个字段计算为准,精确到0.1s,即100ms,主要用于节约网络对象传输大小 46 | /// 47 | public int TimestampStartYear { get; set; } 48 | 49 | /// 50 | /// 最后更新时间 51 | /// 52 | public uint LastUpdateTime { get; set; } 53 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto.Test/UpdateGeneralProcessListUnitTest.cs: -------------------------------------------------------------------------------- 1 | using SocketDto.Enums; 2 | 3 | namespace SocketDto.Test; 4 | 5 | public class UpdateGeneralProcessListUnitTest 6 | { 7 | [Fact] 8 | public void Test_SerializeProcessItemData_Success() 9 | { 10 | Assert.Equal(0, (int)AlarmStatus.Normal); 11 | Assert.Equal(1, (int)AlarmStatus.Overtime); 12 | Assert.Equal(2, (int)AlarmStatus.OverLimit); 13 | Assert.Equal(3, (int)(AlarmStatus.Overtime | AlarmStatus.OverLimit)); 14 | Assert.Equal(4, (int)AlarmStatus.UserChanged); 15 | Assert.Equal(5, (int)(AlarmStatus.Overtime | AlarmStatus.UserChanged)); 16 | Assert.Equal(6, (int)(AlarmStatus.OverLimit | AlarmStatus.UserChanged)); 17 | Assert.Equal(7, 18 | (int)(AlarmStatus.Overtime | AlarmStatus.OverLimit | AlarmStatus.UserChanged)); 19 | Assert.Equal(7, 20 | (int)(AlarmStatus.Overtime | AlarmStatus.Overtime | AlarmStatus.Overtime | AlarmStatus.OverLimit | 21 | AlarmStatus.Overtime | AlarmStatus.UserChanged)); 22 | const AlarmStatus status = AlarmStatus.Overtime | AlarmStatus.OverLimit | AlarmStatus.UserChanged; 23 | Assert.Equal((int)AlarmStatus.Overtime, (int)(AlarmStatus.Overtime & status)); 24 | Assert.Equal((int)AlarmStatus.OverLimit, (int)(AlarmStatus.OverLimit & status)); 25 | Assert.Equal((int)AlarmStatus.UserChanged, (int)(AlarmStatus.UserChanged & status)); 26 | } 27 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto.Test/NumberFormatUnitTest.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Test; 2 | 3 | public class NumberFormatUnitTest 4 | { 5 | private const int Max = 10000; 6 | private const double Min = 0.0001; 7 | 8 | [Fact] 9 | public void Test_NumberToString_Success() 10 | { 11 | var strIntMax = NumberToString(20000); 12 | var strIntCenter = NumberToString(999); 13 | var strIntZero = NumberToString(0); 14 | var strDoubleMax = NumberToString(32983.33223); 15 | var strDoubleCenter = NumberToString(32.358953); 16 | var strDoubleZero = NumberToString(0.00); 17 | var strDoubleSmallThan1 = NumberToString(0.330); 18 | var strDoubleGegative1 = NumberToString(-0.32853); 19 | var strDoubleGegative2 = NumberToString(-0.0001); 20 | var strDoubleGegative3 = NumberToString(-0.00001); 21 | var strDoubleGegative4 = NumberToString(-0.000003235); 22 | 23 | Assert.Equal("0", strIntZero); 24 | } 25 | 26 | 27 | string NumberToString(int number) 28 | { 29 | if (Math.Abs(number) > Max) 30 | { 31 | return number.ToString("0.00e+00"); 32 | } 33 | 34 | return $"{number}"; 35 | } 36 | 37 | string NumberToString(double number) 38 | { 39 | if (number != 0.0 && (Math.Abs(number) > Max || Math.Abs(number) < Min)) 40 | { 41 | return number.ToString("0.00e+00"); 42 | } 43 | 44 | return $"{number}"; 45 | } 46 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Models/Organization.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.Models; 2 | 3 | /// 4 | /// 组织 5 | /// 6 | [ProtoContract] 7 | [MessagePackObject] 8 | public class Organization 9 | { 10 | /// 11 | /// Id 12 | /// 13 | [ProtoMember(1)] 14 | [Key(0)] 15 | public int Id { get; set; } 16 | 17 | /// 18 | /// 名称 19 | /// 20 | [ProtoMember(2)] 21 | [Key(1)] 22 | public string? Name { get; set; } 23 | 24 | /// 25 | /// 标签 26 | /// 27 | [ProtoMember(3)] 28 | [Key(2)] 29 | public List? Tags { get; set; } 30 | 31 | /// 32 | /// 地址 33 | /// 34 | [ProtoMember(4)] 35 | [Key(3)] 36 | public string? Address { get; set; } 37 | 38 | /// 39 | /// 员工总数 40 | /// 41 | [ProtoMember(5)] 42 | [Key(4)] 43 | public int EmployeeCount { get; set; } 44 | 45 | /// 46 | /// 部门列表 47 | /// 48 | [ProtoMember(6)] 49 | [Key(5)] 50 | public List? Departments { get; set; } 51 | 52 | /// 53 | /// 年度预算 54 | /// 55 | [ProtoMember(7)] 56 | [Key(6)] 57 | public decimal AnnualBudget { get; set; } 58 | 59 | /// 60 | /// 成立日期,时间戳,单位ms 61 | /// 62 | [ProtoMember(8)] 63 | [Key(7)] 64 | public long FoundationDate { get; set; } 65 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Udp/UpdateGeneralProcessList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Udp; 2 | 3 | /// 4 | /// 更新进程变化信息,序列化和反序列不能加压缩,部分双精度因为有效位数太长,可能导致UDP包过大而发送失败,所以UDP包不要加压缩 5 | /// 6 | [NetHead(201, 1)] 7 | public class UpdateGeneralProcessList : INetObject 8 | { 9 | /// 10 | /// 总数据大小 11 | /// 12 | public int TotalSize { get; set; } 13 | 14 | /// 15 | /// 分页大小 16 | /// 17 | public int PageSize { get; set; } 18 | 19 | /// 20 | /// 总页数 21 | /// 22 | public int PageCount { get; set; } 23 | 24 | /// 25 | /// 页索引 26 | /// 27 | public int PageIndex { get; set; } 28 | 29 | /// 30 | /// 进程状态,一个进程占1字节(byte) 31 | /// 32 | public byte[] ProcessStatuses { get; set; } = null!; 33 | 34 | /// 35 | /// 告警状态,一个进程占1字节(byte) 36 | /// 37 | public byte[] AlarmStatuses { get; set; } = null!; 38 | 39 | /// 40 | /// 一个进程占2字节(short) 41 | /// 42 | public byte[] Gpus { get; set; } = null!; 43 | 44 | /// 45 | /// 一个进程占1字节(byte) 46 | /// 47 | public byte[] GpuEngine { get; set; } = null!; 48 | 49 | /// 50 | /// 一个进程占1字节(byte) 51 | /// 52 | public byte[] PowerUsage { get; set; } = null!; 53 | 54 | /// 55 | /// 一个进程占1字节(byte) 56 | /// 57 | public byte[] PowerUsageTrend { get; set; } = null!; 58 | 59 | /// 60 | /// 一个进程占4字节(byte) 61 | /// 62 | public byte[] UpdateTimes { get; set; } = null!; 63 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Models/Department.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.Models; 2 | 3 | /// 4 | /// 部门 5 | /// 6 | [ProtoContract] 7 | [MessagePackObject] 8 | public class Department 9 | { 10 | /// 11 | /// Id 12 | /// 13 | [ProtoMember(1)] 14 | [Key(0)] 15 | public int Id { get; set; } 16 | 17 | /// 18 | /// 部门编码 19 | /// 20 | [ProtoMember(2)] 21 | [Key(1)] 22 | public string? Code { get; set; } 23 | 24 | /// 25 | /// 名称 26 | /// 27 | [ProtoMember(3)] 28 | [Key(2)] 29 | public string? Name { get; set; } 30 | 31 | /// 32 | /// 描述 33 | /// 34 | [ProtoMember(4)] 35 | [Key(3)] 36 | public string? Description { get; set; } 37 | 38 | /// 39 | /// 位置 40 | /// 41 | [ProtoMember(5)] 42 | [Key(4)] 43 | public string? Location { get; set; } 44 | 45 | /// 46 | /// 员工数量 47 | /// 48 | [ProtoMember(6)] 49 | [Key(5)] 50 | public int EmployeeCount { get; set; } 51 | 52 | /// 53 | /// 员工列表 54 | /// 55 | [ProtoMember(7)] 56 | [Key(6)] 57 | public List? Employees { get; set; } 58 | 59 | /// 60 | /// 预算 61 | /// 62 | [ProtoMember(8)] 63 | [Key(7)] 64 | public decimal Budget { get; set; } 65 | 66 | /// 67 | /// 未知 68 | /// 69 | [ProtoMember(9)] 70 | [Key(8)] 71 | public double Value { get; set; } 72 | 73 | /// 74 | /// 创建时间 75 | /// 76 | [ProtoMember(10)] 77 | [Key(9)] 78 | public long CreateTime { get; set; } 79 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.Models; 2 | 3 | /// 4 | /// 员工 5 | /// 6 | [ProtoContract] 7 | [MessagePackObject] 8 | public class Employee 9 | { 10 | /// 11 | /// Id 12 | /// 13 | [ProtoMember(1)] 14 | [Key(0)] 15 | public int Id { get; set; } 16 | 17 | 18 | /// 19 | /// 编码 20 | /// 21 | [ProtoMember(2)] 22 | [Key(1)] 23 | public string? Code { get; set; } 24 | 25 | /// 26 | /// 名 27 | /// 28 | [ProtoMember(3)] 29 | [Key(2)] 30 | public string? FirstName { get; set; } 31 | 32 | /// 33 | /// 姓 34 | /// 35 | [ProtoMember(4)] 36 | [Key(3)] 37 | public string? LastName { get; set; } 38 | 39 | /// 40 | /// 昵称 41 | /// 42 | [ProtoMember(5)] 43 | [Key(4)] 44 | public string? NickName { get; set; } 45 | 46 | /// 47 | /// 出生日期 48 | /// 49 | [ProtoMember(6)] 50 | [Key(5)] 51 | public long BirthDate { get; set; } 52 | 53 | /// 54 | /// 备注 55 | /// 56 | [ProtoMember(7)] 57 | [Key(6)] 58 | public string? Description { get; set; } 59 | 60 | /// 61 | /// 地址 62 | /// 63 | [ProtoMember(8)] 64 | [Key(7)] 65 | public string? Address { get; set; } 66 | 67 | /// 68 | /// 邮件 69 | /// 70 | [ProtoMember(9)] 71 | [Key(8)] 72 | public string? Email { get; set; } 73 | 74 | /// 75 | /// 电话号码 76 | /// 77 | [ProtoMember(10)] 78 | [Key(9)] 79 | public string? PhoneNumber { get; set; } 80 | 81 | /// 82 | /// 工资 83 | /// 84 | [ProtoMember(11)] 85 | [Key(10)] 86 | public decimal Salary { get; set; } 87 | 88 | /// 89 | /// 部门Id 90 | /// 91 | [ProtoMember(12)] 92 | [Key(11)] 93 | public decimal DepartmentId { get; set; } 94 | 95 | /// 96 | /// 入职时间 97 | /// 98 | [ProtoMember(13)] 99 | [Key(12)] 100 | public long EntryTime { get; set; } 101 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/SocketTest.Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | WinExe 4 | net10.0;net10.0-windows 5 | enable 6 | true 7 | app.manifest 8 | true 9 | true 10 | true 11 | true 12 | Socket测试服务端 13 | Assets\logo.ico 14 | 15 | 16 | true 17 | true 18 | 19 | 20 | true 21 | true 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Client/SocketTest.Client.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | WinExe 4 | net10.0;net10.0-windows 5 | enable 6 | true 7 | app.manifest 8 | true 9 | true 10 | true 11 | Socket测试客户端 12 | Assets\logo.ico 13 | 14 | 15 | true 16 | true 17 | 18 | 19 | true 20 | true 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/SerializeUtils/Helpers/MessagePackSerializeHelper.cs: -------------------------------------------------------------------------------- 1 | using MessagePack.Resolvers; 2 | 3 | namespace SerializationTest.SerializeUtils.Helpers; 4 | 5 | /// 6 | /// 标准带压缩:这种方式需要在类和字段上添加特性 7 | /// 8 | public class MessagePackStandardWithCompressionSerializeHelper : ISerializeHelper 9 | { 10 | private readonly MessagePackSerializerOptions _options = 11 | MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray); 12 | 13 | public byte[] Serialize(T data) 14 | { 15 | return MessagePackSerializer.Serialize(data, _options); 16 | } 17 | 18 | public T Deserialize(byte[] buffer) 19 | { 20 | return MessagePackSerializer.Deserialize(buffer, _options); 21 | } 22 | } 23 | 24 | /// 25 | /// 标准不带压缩:这种方式需要在类和字段上添加特性 26 | /// 27 | public class MessagePackStandardWithOutCompressionSerializeHelper : ISerializeHelper 28 | { 29 | private readonly MessagePackSerializerOptions _options = MessagePackSerializerOptions.Standard; 30 | 31 | public byte[] Serialize(T data) 32 | { 33 | return MessagePackSerializer.Serialize(data, _options); 34 | } 35 | 36 | public T Deserialize(byte[] buffer) 37 | { 38 | return MessagePackSerializer.Deserialize(buffer, _options); 39 | } 40 | } 41 | 42 | /// 43 | /// 新推功能带压缩:这种方式不需要给传输对象添加特性 44 | /// 45 | public class MessagePackContractlessStandardResolverWithCompressionSerializeHelper : ISerializeHelper 46 | { 47 | private readonly MessagePackSerializerOptions _options = 48 | ContractlessStandardResolver.Options.WithCompression(MessagePackCompression 49 | .Lz4BlockArray); 50 | 51 | public byte[] Serialize(T data) 52 | { 53 | return MessagePackSerializer.Serialize(data, _options); 54 | } 55 | 56 | public T Deserialize(byte[] buffer) 57 | { 58 | return MessagePackSerializer.Deserialize(buffer, _options); 59 | } 60 | } 61 | 62 | /// 63 | /// 新推功能不带压缩:这种方式不需要给传输对象添加特性 64 | /// 65 | public class MessagePackContractlessStandardResolverWithOutCompressionSerializeHelper : ISerializeHelper 66 | { 67 | private readonly MessagePackSerializerOptions _options = 68 | ContractlessStandardResolver.Options; 69 | 70 | public byte[] Serialize(T data) 71 | { 72 | return MessagePackSerializer.Serialize(data, _options); 73 | } 74 | 75 | public T Deserialize(byte[] buffer) 76 | { 77 | return MessagePackSerializer.Deserialize(buffer, _options); 78 | } 79 | } -------------------------------------------------------------------------------- /src/ObjectBinarySerializationTest/SerializationTest/Models/ProcessData.cs: -------------------------------------------------------------------------------- 1 | namespace SerializationTest.Models; 2 | 3 | public record ProcessData 4 | { 5 | /// 6 | /// 占10bit, CPU(所有内核的总处理利用率),最后一位表示小数位,比如253表示25.3% 7 | /// 8 | public short Cpu { get; set; } 9 | 10 | /// 11 | /// 占10bit, 内存(进程占用的物理内存),最后一位表示小数位,比如253表示25.3%,值可根据基本信息计算 12 | /// 13 | public short Memory { get; set; } 14 | 15 | /// 16 | /// 占10bit, 磁盘(所有物理驱动器的总利用率),最后一位表示小数位,比如253表示25.3%,值可根据基本信息计算 17 | /// 18 | public short Disk { get; set; } 19 | 20 | /// 21 | /// 占10bit, 网络(当前主要网络上的网络利用率),最后一位表示小数位,比如253表示25.3%,值可根据基本信息计算 22 | /// 23 | public short Network { get; set; } 24 | 25 | /// 26 | /// 占10bit, GPU(所有GPU引擎的最高利用率),最后一位表示小数位,比如253表示25.3 27 | /// 28 | public short Gpu { get; set; } 29 | 30 | /// 31 | /// 占1bit,GPU引擎,0:无,1:GPU 0 - 3D 32 | /// 33 | public byte GpuEngine { get; set; } 34 | 35 | /// 36 | /// 占3bit,电源使用情况(CPU、磁盘和GPU对功耗的影响),0:非常低,1:低,2:中,3:高,4:非常高 37 | /// 38 | public byte PowerUsage { get; set; } 39 | 40 | /// 41 | /// 占3bit,电源使用情况趋势(一段时间内CPU、磁盘和GPU对功耗的影响),0:非常低,1:低,2:中,3:高,4:非常高 42 | /// 43 | public byte PowerUsageTrend { get; set; } 44 | 45 | /// 46 | /// 占1bit,进程类型,0:应用,1:后台进程 47 | /// 48 | public byte Type { get; set; } 49 | 50 | /// 51 | /// 占1bit,进程状态,0:正常运行,1:效率模式,2:挂起 52 | /// 53 | public byte Status { get; set; } 54 | 55 | public byte[] Serialize() 56 | { 57 | var bytes = new byte[8]; 58 | 59 | // Cpu 60 | bytes[0] = (byte)(Cpu >> 2); 61 | bytes[1] = (byte)(((Cpu & 0x03) << 6) | (Cpu >> 4)); 62 | 63 | // Memory 64 | bytes[2] = (byte)(((Memory & 0x0F) << 4) | (Memory >> 6)); 65 | 66 | // Disk 67 | bytes[3] = (byte)(((Disk & 0x3F) << 2) | (Disk >> 8)); 68 | 69 | // Network 70 | bytes[4] = (byte)(Network & 0xFF); 71 | 72 | // Gpu 73 | bytes[5] = (byte)(Gpu >> 2); 74 | bytes[6] = (byte)((Gpu & 0x03) << 6); 75 | 76 | return bytes; 77 | } 78 | 79 | public static ProcessData Deserialize(byte[] buffer) 80 | { 81 | return new ProcessData 82 | { 83 | Cpu = (short)((buffer[0] << 2) | (buffer[1] >> 6)), 84 | Memory = (short)(((buffer[1] & 0x3F) << 4) | (buffer[2] >> 4)), 85 | Disk = (short)(((buffer[2] & 0x0F) << 6) | (buffer[3] >> 2)), 86 | Network = (short)(((buffer[3] & 0x03) << 8) | buffer[4]), 87 | Gpu = (short)((buffer[5] << 2) | (buffer[6] >> 6)) 88 | }; 89 | } 90 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketDto/Response/ResponseProcessList.cs: -------------------------------------------------------------------------------- 1 | namespace SocketDto.Response; 2 | 3 | /// 4 | /// 响应请求进程信息 5 | /// 6 | [NetHead(10, 1)] 7 | public class ResponseProcessList : INetObject 8 | { 9 | /// 10 | /// 任务Id 11 | /// 12 | public int TaskId { get; set; } 13 | 14 | /// 15 | /// 总数据大小 16 | /// 17 | public int TotalSize { get; set; } 18 | 19 | /// 20 | /// 分页大小 21 | /// 22 | public int PageSize { get; set; } 23 | 24 | /// 25 | /// 总页数 26 | /// 27 | public int PageCount { get; set; } 28 | 29 | /// 30 | /// 页索引 31 | /// 32 | public int PageIndex { get; set; } 33 | 34 | /// 35 | /// 进程列表 36 | /// 37 | public List? Processes { get; set; } 38 | } 39 | 40 | /// 41 | /// 操作系统进程信息 42 | /// 43 | public record ProcessItem 44 | { 45 | /// 46 | /// 进程ID 47 | /// 48 | public int Pid { get; set; } 49 | 50 | /// 51 | /// 进程名称 52 | /// 53 | public string? Name { get; set; } 54 | 55 | /// 56 | /// 进程类型,0:应用,1:后台进程 57 | /// 58 | public byte Type { get; set; } 59 | 60 | /// 61 | /// 进程状态,0:新建状态,1:就绪状态,2:运行状态,3:阻塞状态,4:终止状态 62 | /// 63 | public byte ProcessStatus { get; set; } 64 | 65 | /// 66 | /// 告警状态,没有特别意义,可组合位域状态,0:正常,1:超时,2:超限,切换用户 67 | /// 68 | public byte AlarmStatus { get; set; } 69 | 70 | /// 71 | /// 发布者 72 | /// 73 | public string? Publisher { get; set; } 74 | 75 | /// 76 | /// 命令行 77 | /// 78 | public string? CommandLine { get; set; } 79 | 80 | /// 81 | /// Cpu(所有内核的总处理利用率),最后一位表示小数位,比如253表示25.3% 82 | /// 83 | public short Cpu { get; set; } 84 | 85 | /// 86 | /// 内存(进程占用的物理内存),最后一位表示小数位,比如253表示25.3%,值可根据基本信息计算 87 | /// 88 | public short Memory { get; set; } 89 | 90 | /// 91 | /// 磁盘(所有物理驱动器的总利用率),最后一位表示小数位,比如253表示25.3%,值可根据基本信息计算 92 | /// 93 | public short Disk { get; set; } 94 | 95 | /// 96 | /// 网络(当前主要网络上的网络利用率),最后一位表示小数位,比如253表示25.3%,值可根据基本信息计算 97 | /// 98 | public short Network { get; set; } 99 | 100 | /// 101 | /// GPU(所有GPU引擎的最高利用率),最后一位表示小数位,比如253表示25.3 102 | /// 103 | public short Gpu { get; set; } 104 | 105 | /// 106 | /// GPU引擎,0:无,1:GPU 0 - 3D 107 | /// 108 | public byte GpuEngine { get; set; } 109 | 110 | /// 111 | /// 电源使用情况(CPU、磁盘和GPU对功耗的影响),0:非常低,1:低,2:中,3:高,4:非常高 112 | /// 113 | public byte PowerUsage { get; set; } 114 | 115 | /// 116 | /// 电源使用情况趋势(一段时间内CPU、磁盘和GPU对功耗的影响),0:非常低,1:低,2:中,3:高,4:非常高 117 | /// 118 | public byte PowerUsageTrend { get; set; } 119 | 120 | /// 121 | /// 上次更新时间(当天时间戳:当日0点0分0秒计算的时间戳,单位ms) 122 | /// 123 | public uint LastUpdateTime { get; set; } 124 | 125 | /// 126 | /// 更新时间(当天时间戳:当日0点0分0秒计算的时间戳,单位ms) 127 | /// 128 | public uint UpdateTime { get; set; } 129 | } -------------------------------------------------------------------------------- /src/SocketTesting/SocketTest.Server/Views/MainWindow.axaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 16 | 20 | 23 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 69 |