XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.ServerInteractive

[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.ServerInteractive

路由匹配优化与错误提示增强,版本升级至3.0.2

- TestCoreService 路由支持通配符,返回内容更丰富,便于调试 - Program.cs 批量注释 SMTest,调整测试路由与服务端一致 - RouteMatchHelper 移除长度限制,提升通配符路由灵活性 - ServerCoreExceptionProcessService 针对未注册路由返回更友好错误信息 - 项目版本号升级至 3.1.0,标志重要功能完善

3c8b991
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

5 个文件 +41 -44
Modified XFEExtension.NetCore.ServerInteractive.TServer/Services/TestCoreService.cs +7 -6
@@ -5,10 +5,11 @@ namespace XFEExtension.NetCore.ServerInteractive.TServer.Services;
5 5
6 6 public partial class TestCoreService : ServerCoreStandardServiceBase
7 7 {
8 [EntryPoint("test")]
9 public async Task TestEntryPoint()
10 {
11 Console.Write($"收到测试请求");
12 await Close("完成");
13 }
8 [EntryPoint("v1/test/*")]
9 public async Task TestEntryPoint() => await Close($"""
10 Hello from {XFEServerCore.ServerCoreName}:
11 Your route is {Route};
12 Your IP is {ClientIP};
13 Your headers are {string.Join(',', Args.Request.Headers)}
14 """);
14 15 }
Modified XFEExtension.NetCore.ServerInteractive.Test/Program.cs +26 -26
@@ -70,7 +70,7 @@ internal class Program
70 70 {
71 71 BaseAddress = new Uri("http://localhost:3305/api/")
72 72 };
73 var response = await client.GetAsync("test");
73 var response = await client.GetAsync("v1/test/myTest/test2");
74 74 if (response.IsSuccessStatusCode)
75 75 {
76 76 var content = await response.Content.ReadAsStringAsync();
@@ -86,7 +86,7 @@ internal class Program
86 86 /// <summary>
87 87 /// 测试基本的test端点请求
88 88 /// </summary>
89 [SMTest]
89 //[SMTest]
90 90 public static async Task Test()
91 91 {
92 92 var result = await s_xFEClientRequester.Request<string>("test");
@@ -104,7 +104,7 @@ internal class Program
104 104 /// <summary>
105 105 /// 测试连接检查端点
106 106 /// </summary>
107 [SMTest]
107 //[SMTest]
108 108 public static async Task Check()
109 109 {
110 110 try
@@ -133,7 +133,7 @@ internal class Program
133 133 /// <summary>
134 134 /// 测试用户登录功能
135 135 /// </summary>
136 [SMTest("Admin", "123456")]
136 //[SMTest("Admin", "123456")]
137 137 public static async Task Login(string account, string password)
138 138 {
139 139 var result = await s_xFEClientRequester.Request<UserLoginResult<UserFaceInfo>>("login", account, password);
@@ -158,7 +158,7 @@ internal class Program
158 158 /// <summary>
159 159 /// 测试无效用户登录(错误密码)
160 160 /// </summary>
161 [SMTest("Admin", "wrong_password")]
161 //[SMTest("Admin", "wrong_password")]
162 162 public static async Task LoginWithWrongPassword(string account, string password)
163 163 {
164 164 var result = await s_xFEClientRequester.Request<UserLoginResult<UserFaceInfo>>("login", account, password);
@@ -169,7 +169,7 @@ internal class Program
169 169 /// <summary>
170 170 /// 测试无效用户登录(不存在的用户)
171 171 /// </summary>
172 [SMTest("NonExistentUser", "123456")]
172 //[SMTest("NonExistentUser", "123456")]
173 173 public static async Task LoginWithNonExistentUser(string account, string password)
174 174 {
175 175 var result = await s_xFEClientRequester.Request<UserLoginResult<UserFaceInfo>>("login", account, password);
@@ -180,7 +180,7 @@ internal class Program
180 180 /// <summary>
181 181 /// 测试重新登录功能
182 182 /// </summary>
183 [SMTest]
183 //[SMTest]
184 184 public static async Task ReLogin()
185 185 {
186 186 var result = await s_xFEClientRequester.Request<UserFaceInfo>("relogin");
@@ -204,7 +204,7 @@ internal class Program
204 204 /// <summary>
205 205 /// 测试Echo服务:发送消息并验证原样返回
206 206 /// </summary>
207 [SMTest]
207 //[SMTest]
208 208 public static async Task EchoTest()
209 209 {
210 210 var result = await s_xFEClientRequester.Request<string>("echo", "Hello, XFE!");
@@ -221,7 +221,7 @@ internal class Program
221 221 /// <summary>
222 222 /// 测试Echo服务:发送空消息
223 223 /// </summary>
224 [SMTest]
224 //[SMTest]
225 225 public static async Task EchoEmptyTest()
226 226 {
227 227 var result = await s_xFEClientRequester.Request<string>("echo", string.Empty);
@@ -238,7 +238,7 @@ internal class Program
238 238 /// <summary>
239 239 /// 测试Echo服务:发送中文消息
240 240 /// </summary>
241 [SMTest]
241 //[SMTest]
242 242 public static async Task EchoChineseTest()
243 243 {
244 244 var result = await s_xFEClientRequester.Request<string>("echo", "你好,世界!");
@@ -259,7 +259,7 @@ internal class Program
259 259 /// <summary>
260 260 /// 测试加法运算
261 261 /// </summary>
262 [SMTest]
262 //[SMTest]
263 263 public static async Task MathAddTest()
264 264 {
265 265 var result = await s_xFEClientRequester.Request<string>("math/add", 3.0, 5.0);
@@ -276,7 +276,7 @@ internal class Program
276 276 /// <summary>
277 277 /// 测试乘法运算
278 278 /// </summary>
279 [SMTest]
279 //[SMTest]
280 280 public static async Task MathMultiplyTest()
281 281 {
282 282 var result = await s_xFEClientRequester.Request<string>("math/multiply", 4.0, 7.0);
@@ -293,7 +293,7 @@ internal class Program
293 293 /// <summary>
294 294 /// 测试加法运算:负数
295 295 /// </summary>
296 [SMTest]
296 //[SMTest]
297 297 public static async Task MathAddNegativeTest()
298 298 {
299 299 var result = await s_xFEClientRequester.Request<string>("math/add", -10.0, 3.0);
@@ -310,7 +310,7 @@ internal class Program
310 310 /// <summary>
311 311 /// 测试乘法运算:零
312 312 /// </summary>
313 [SMTest]
313 //[SMTest]
314 314 public static async Task MathMultiplyZeroTest()
315 315 {
316 316 var result = await s_xFEClientRequester.Request<string>("math/multiply", 42.0, 0.0);
@@ -327,7 +327,7 @@ internal class Program
327 327 /// <summary>
328 328 /// 测试加法运算:小数
329 329 /// </summary>
330 [SMTest]
330 //[SMTest]
331 331 public static async Task MathAddDecimalTest()
332 332 {
333 333 var result = await s_xFEClientRequester.Request<string>("math/add", 1.5, 2.3);
@@ -348,7 +348,7 @@ internal class Program
348 348 /// <summary>
349 349 /// 测试服务器状态端点
350 350 /// </summary>
351 [SMTest]
351 //[SMTest]
352 352 public static async Task StatusTest()
353 353 {
354 354 var result = await s_xFEClientRequester.Request<string>("status");
@@ -369,7 +369,7 @@ internal class Program
369 369 /// <summary>
370 370 /// 测试问候服务:正常名称
371 371 /// </summary>
372 [SMTest]
372 //[SMTest]
373 373 public static async Task GreetTest()
374 374 {
375 375 var result = await s_xFEClientRequester.Request<string>("greet", "XFEstudio");
@@ -386,7 +386,7 @@ internal class Program
386 386 /// <summary>
387 387 /// 测试问候服务:空名称(应返回错误)
388 388 /// </summary>
389 [SMTest]
389 //[SMTest]
390 390 public static async Task GreetEmptyNameTest()
391 391 {
392 392 var result = await s_xFEClientRequester.Request<string>("greet");
@@ -401,7 +401,7 @@ internal class Program
401 401 /// <summary>
402 402 /// 测试服务器时间端点
403 403 /// </summary>
404 [SMTest]
404 //[SMTest]
405 405 public static async Task TimeTest()
406 406 {
407 407 var result = await s_xFEClientRequester.Request<string>("time");
@@ -422,7 +422,7 @@ internal class Program
422 422 /// <summary>
423 423 /// 压力测试:并行发送10000个请求
424 424 /// </summary>
425 [SMTest]
425 //[SMTest]
426 426 public static async Task TestBench()
427 427 {
428 428 await Parallel.ForEachAsync(Enumerable.Range(0, 10000), async (_, _) =>
@@ -447,7 +447,7 @@ internal class Program
447 447 /// <summary>
448 448 /// 测试获取服务器日志
449 449 /// </summary>
450 [SMTest]
450 //[SMTest]
451 451 public static async Task GetLog()
452 452 {
453 453 var result = await s_xFEClientRequester.Request<string>("get_log", DateTime.MinValue, DateTime.MaxValue);
@@ -469,7 +469,7 @@ internal class Program
469 469 /// <summary>
470 470 /// 测试Order模型序列化
471 471 /// </summary>
472 [SMTest]
472 //[SMTest]
473 473 public static string ConvertOrder()
474 474 {
475 475 var order = new Order
@@ -483,7 +483,7 @@ internal class Program
483 483 /// <summary>
484 484 /// 测试添加订单
485 485 /// </summary>
486 [SMTest]
486 //[SMTest]
487 487 public static async Task<bool> AddOrder() => await TableRequester.Add<Order>(new()
488 488 {
489 489 Description = "测试订单的描述",
@@ -493,7 +493,7 @@ internal class Program
493 493 /// <summary>
494 494 /// 测试获取订单列表
495 495 /// </summary>
496 [SMTest]
496 //[SMTest]
497 497 public static async Task GetOrder()
498 498 {
499 499 var result = await TableRequester.Get<Order>();
@@ -506,7 +506,7 @@ internal class Program
506 506 /// <summary>
507 507 /// 测试修改订单
508 508 /// </summary>
509 [SMTest]
509 //[SMTest]
510 510 public static async Task ChangeOrder()
511 511 {
512 512 var result = await TableRequester.Get<Order>();
@@ -520,7 +520,7 @@ internal class Program
520 520 /// <summary>
521 521 /// 测试获取修改后的订单列表
522 522 /// </summary>
523 [SMTest]
523 //[SMTest]
524 524 public static async Task GetOrder2()
525 525 {
526 526 var result = await TableRequester.Get<Order>();
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Helpers/RouteMatchHelper.cs +0 -3
@@ -31,9 +31,6 @@ internal static class RouteMatchHelper
31 31 var patternSegments = pattern.Split('/');
32 32 var routeSegments = route.Split('/');
33 33
34 if (patternSegments.Length != routeSegments.Length)
35 return false;
36
37 34 return !patternSegments.Where((t, i) => t != "*" && t != routeSegments[i]).Any();
38 35 }
39 36
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/ServerCoreExceptionProcessService.cs +1 -1
@@ -44,7 +44,7 @@ public class ServerCoreExceptionProcessService : ServerCoreOriginalServiceBase
44 44 errorMessage += $":{currentException.Message}";
45 45 currentException = currentException.InnerException;
46 46 }
47 errorInfo = "服务器内部异常";
47 errorInfo = errorMessage.Contains("请求的路由未注册") ? "路由未找到" : "服务器内部异常";
48 48 Console.WriteLine();
49 49 Console.WriteLine($"[WARN]【{errorInfo}】{errorMessage}");
50 50 if (e.ServerException?.InnerException?.StackTrace is not null)
Modified XFEExtension.NetCore.ServerInteractive/XFEExtension.NetCore.ServerInteractive.csproj +7 -8
@@ -5,7 +5,7 @@
5 5 <ImplicitUsings>enable</ImplicitUsings>
6 6 <Nullable>enable</Nullable>
7 7 <GenerateDocumentationFile>True</GenerateDocumentationFile>
8 <Version>3.0.2-preview.1.26046.8</Version>
8 <Version>3.0.2</Version>
9 9 <Title>XFEExtension.NetCore.ServerInteractive</Title>
10 10 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.ServerInteractive</RepositoryUrl>
11 11 <AnalysisLevel>latest</AnalysisLevel>
@@ -21,15 +21,14 @@
21 21 <PackageReleaseNotes>
22 22 ## 调整
23 23
24 Wildcard Route Matching and Registration:
24 路由匹配优化与错误提示增强,版本升级至3.0.2
25 25
26 Added support for registering and matching wildcard routes on the client side, ensuring the most specific pattern is chosen for requests, and preventing ambiguous aliasing to wildcard routes. This includes changes in both the builder (XFEClientRequesterBuilder) and the requester (XFEClientRequester). [1] [2] [3] [4] [5] [6]
27 Request Context Modernization:
26 - TestCoreService 路由支持通配符,返回内容更丰富,便于调试
27 - Program.cs 批量注释 SMTest,调整测试路由与服务端一致
28 - RouteMatchHelper 移除长度限制,提升通配符路由灵活性
29 - ServerCoreExceptionProcessService 针对未注册路由返回更友好错误信息
30 - 项目版本号升级至 3.1.0,标志重要功能完善
28 31
29 Replaced the use of HttpListenerRequest with the more general CyberCommRequestEventArgs in core service interfaces and implementations, providing a compatibility shim for legacy access to the request object. [1] [2] [3] [4] [5] [6] [7]
30 Server Configuration Enhancements:
31
32 Enabled support for GET, POST, and non-standard JSON requests in the server's API entry point configuration.
33 32 ## 新增
34 33
35 34