XFEExtension.NetCore.ServerInteractive
[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig
关注
0
Fork
0
Star
0
返回提交历史
Added
XFEExtension.NetCore.ServerInteractive/Exceptions/XFERequesterException.cs
+16
-0
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Requester/XFEClientRequester.cs
+16
-8
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Requester/XFEClientRequesterBuilder.cs
+31
-5
XFEstudio/XFEExtension.NetCore.ServerInteractive
添加部分逻辑
12ffeed
代码差异
3 个文件
+63
-13
@@ -0,0 +1,16 @@
1
using System.Runtime.Serialization;
2
3
namespace XFEExtension.NetCore.ServerInteractive.Exceptions;
4
5
/// <summary>
6
/// XFE请求器异常
7
/// </summary>
8
public class XFERequesterException : Exception
9
{
10
/// <inheritdoc/>
11
public XFERequesterException() { }
12
/// <inheritdoc/>
13
public XFERequesterException(string? message) : base(message) { }
14
/// <inheritdoc/>
15
public XFERequesterException(string? message, Exception? innerException) : base(message, innerException) { }
16
}
@@ -1,6 +1,7 @@
1
1
using System.Text.Json;
2
2
using XFEExtension.NetCore.AutoImplement;
3
3
using XFEExtension.NetCore.DelegateExtension;
4
using XFEExtension.NetCore.ServerInteractive.Exceptions;
4
5
using XFEExtension.NetCore.ServerInteractive.Interfaces.Requester;
5
6
using XFEExtension.NetCore.ServerInteractive.Models.RequesterModels;
6
7
using XFEExtension.NetCore.ServerInteractive.Utilities.JsonConverter;
@@ -14,14 +15,8 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Requester;
14
15
public abstract class XFEClientRequester
15
16
{
16
17
readonly JsonSerializerOptions jsonSerializerOptions = new();
17
/// <summary>
18
/// 请求服务
19
/// </summary>
20
public List<IRequestService> RequestServices { get; set; } = [];
21
/// <summary>
22
/// XFE请求服务
23
/// </summary>
24
public List<IXFERequestService> XFERequestServices { get; set; } = [];
18
internal Dictionary<string, IRequestService> requestServiceDictionary = [];
19
internal Dictionary<string, IXFERequestService> xFERequestServiceDictionary = [];
25
20
/// <summary>
26
21
/// 请求消息返回事件
27
22
/// </summary>
@@ -41,4 +36,17 @@ public abstract class XFEClientRequester
41
36
}
42
37
43
38
private void TableRequester_MessageReceived(object? sender, ServerInteractiveEventArgs e) => MessageReceived?.Invoke(sender, e);
39
40
public async Task<T> Request<T>(string serviceName, params object[] parameters)
41
{
42
if (requestServiceDictionary.TryGetValue(serviceName, out var service))
43
{
44
return await service.Request<T>();
45
}
46
else if (xFERequestServiceDictionary.TryGetValue(serviceName, out var xFEService))
47
{
48
49
}
50
throw new XFERequesterException();
51
}
44
52
}
@@ -11,6 +11,8 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Requester;
11
11
public abstract class XFEClientRequesterBuilder
12
12
{
13
13
readonly Dictionary<string, object> parameterDictionary = [];
14
readonly Dictionary<string, IRequestService> requestServiceDictionary = [];
15
readonly Dictionary<string, IXFERequestService> xFERequestServiceDictionary = [];
14
16
/// <summary>
15
17
/// 创建构建器
16
18
/// </summary>
@@ -18,20 +20,44 @@ public abstract class XFEClientRequesterBuilder
18
20
public static XFEClientRequesterBuilder CreateBuilder() => new XFEClientRequesterBuilderImpl();
19
21
20
22
/// <summary>
21
/// 添加服务
23
/// 添加请求
22
24
/// </summary>
25
/// <param name="serviceName">请求名称</param>
23
26
/// <param name="requestService">请求服务对象</param>
24
27
/// <returns></returns>
25
public XFEClientRequesterBuilder AddService(IRequestService requestService)
28
public XFEClientRequesterBuilder AddRequest(string serviceName, IRequestService requestService)
26
29
{
27
30
BuilderHelper.ApplyParameter(parameterDictionary, requestService);
31
requestServiceDictionary.Add(serviceName, requestService);
28
32
return this;
29
33
}
30
34
31
35
/// <summary>
32
/// 添加服务
36
/// 添加请求
33
37
/// </summary>
34
/// <typeparam name="T">服务泛型</typeparam>
38
/// <typeparam name="T">请求服务泛型</typeparam>
39
/// <param name="serviceName">请求名称</param>
35
40
/// <returns></returns>
36
public XFEClientRequesterBuilder AddService<T>() where T : IRequestService, new() => AddService(new T());
41
public XFEClientRequesterBuilder AddRequest<T>(string serviceName) where T : IRequestService, new() => AddRequest(serviceName, new T());
42
43
/// <summary>
44
/// 添加XFE请求器
45
/// </summary>
46
/// <param name="serviceName">请求服务名称</param>
47
/// <param name="xFERequestService">请求服务对象</param>
48
/// <returns></returns>
49
public XFEClientRequesterBuilder AddXFERequest(string serviceName, IXFERequestService xFERequestService)
50
{
51
BuilderHelper.ApplyParameter(parameterDictionary, xFERequestService);
52
xFERequestServiceDictionary.Add(serviceName, xFERequestService);
53
return this;
54
}
55
56
/// <summary>
57
/// 添加XFE请求器
58
/// </summary>
59
/// <typeparam name="T">请求服务泛型</typeparam>
60
/// <param name="serviceName">请求服务名称</param>
61
/// <returns></returns>
62
public XFEClientRequesterBuilder AddXFERequest<T>(string serviceName) where T : IXFERequestService, new() => AddXFERequest(serviceName, new T());
37
63
}