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

初步优化代码

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

代码差异

3 个文件 +79 -18
Modified XFEExtension.NetCore.ServerInteractive.TServer/Program.cs +23 -18
@@ -7,21 +7,26 @@ using XFEExtension.NetCore.ServerInteractive.Utilities;
7 7 using XFEExtension.NetCore.ServerInteractive.Utilities.DataTable;
8 8 using XFEExtension.NetCore.ServerInteractive.Utilities.Server;
9 9
10 var server = XFEServerBuilder.CreateBuilder() // 创建服务器构建器
11 .UseXFEServer() // 使用XFE服务器架构
12 .AddServerCore( // 添加核心服务器
13 XFEServerCoreBuilder.CreateBuilder() // 创建核心服务器构建器
14 .UseXFEStandardServerCore( // 使用XFE标准服务器核心
15 static () => UserProfile.UserTable, // 获取用户表的方法
16 static () => UserProfile.EncryptedUserLoginModelTable, // 获取用户加密模型的方法
17 UserProfile.EncryptedUserLoginModelTable.Add, // 添加用户加密模型的方法
18 static user => UserProfile.EncryptedUserLoginModelTable.Remove(user), // 移除用户加密模型的方法
19 static () => 7, // 获取登录维持天数方法
20 static user => (IUserFaceInfo)user, // 登录结果转换方法
21 XFEDataTableManagerBuilder.CreateBuilder() // 创建DataTable管理器构建器
22 .AddTable<Person, DataProfile>("人物", (int)UserRole.业务员, (int)UserRole.经理, (int)UserRole.业务员, (int)UserRole.业务员) // 添加名为人物的表格,Person类型,AutoConfig为DataProfile。添加更改获取权限为业务员,移除权限为经理
23 .AddTable<Order, DataProfile>("订单", (int)UserRole.业务员, (int)UserRole.经理, (int)UserRole.业务员, (int)UserRole.业务员) // 添加名为订单的表格,Order类型,AutoConfig为DataProfile。添加更改获取权限为业务员,移除权限为经理
24 .AddTable<User, UserProfile>("用户", (int)UserRole.经理, (int)UserRole.经理, (int)UserRole.经理, (int)UserRole.业务员)) // 添加名为用户的表格,User类型,AutoConfig为UserProfile。获取权限为业务员,添加移除更改权限为经理
25 .Build()) // 构建核心服务器
26 .Build(); // 构建服务器
27 await server.Start(); // 启动服务
10 var options = new XFEStandardServerCoreOptions<IUserFaceInfo>
11 {
12 GetUserFunction = static () => UserProfile.UserTable,
13 GetEncryptedUserLoginModelFunction = static () => UserProfile.EncryptedUserLoginModelTable,
14 AddEncryptedUserLoginModelFunction = UserProfile.EncryptedUserLoginModelTable.Add,
15 RemoveEncryptedUserLoginModelFunction = static user => UserProfile.EncryptedUserLoginModelTable.Remove(user),
16 GetLoginKeepDays = static () => 7,
17 LoginResultConvertFunction = static user => (IUserFaceInfo)user,
18 DataTableManagerBuilder = XFEDataTableManagerBuilder.CreateBuilder()
19 .AddTable<Person, DataProfile>("人物", (int)UserRole.业务员, (int)UserRole.经理, (int)UserRole.业务员, (int)UserRole.业务员)
20 .AddTable<Order, DataProfile>("订单", (int)UserRole.业务员, (int)UserRole.经理, (int)UserRole.业务员, (int)UserRole.业务员)
21 .AddTable<User, UserProfile>("用户", (int)UserRole.经理, (int)UserRole.经理, (int)UserRole.经理, (int)UserRole.业务员)
22 };
23
24 var server = XFEServerBuilder.CreateBuilder()
25 .UseXFEServer()
26 .AddServerCore(
27 XFEServerCoreBuilder.CreateBuilder()
28 .UseXFEStandardServerCore(options)
29 .Build())
30 .Build();
31
32 await server.Start();
Modified XFEExtension.NetCore.ServerInteractive/Utilities/XFEServerCoreBuilderExtensions.cs +17 -0
@@ -113,4 +113,21 @@ public static class XFEServerCoreBuilderExtensions
113 113 .AddStandardLoginService<T>()
114 114 .AddServerLogService()
115 115 .AddIpBannerService();
116
117 /// <summary>
118 /// 使用XFE标准服务器核心(Options)
119 /// </summary>
120 public static XFEServerCoreBuilder UseXFEStandardServerCore<T>(this XFEServerCoreBuilder xFEServerCoreBuilder, XFEStandardServerCoreOptions<T> options) where T : class
121 {
122 ArgumentNullException.ThrowIfNull(options);
123 var dataTableBuilder = options.DataTableManagerBuilder ?? XFEDataTableManagerBuilder.CreateBuilder();
124 return xFEServerCoreBuilder.UseXFEStandardServerCore(
125 options.GetUserFunction ?? throw new ArgumentNullException(nameof(options.GetUserFunction)),
126 options.GetEncryptedUserLoginModelFunction ?? throw new ArgumentNullException(nameof(options.GetEncryptedUserLoginModelFunction)),
127 options.AddEncryptedUserLoginModelFunction ?? throw new ArgumentNullException(nameof(options.AddEncryptedUserLoginModelFunction)),
128 options.RemoveEncryptedUserLoginModelFunction ?? throw new ArgumentNullException(nameof(options.RemoveEncryptedUserLoginModelFunction)),
129 options.GetLoginKeepDays ?? throw new ArgumentNullException(nameof(options.GetLoginKeepDays)),
130 options.LoginResultConvertFunction ?? throw new ArgumentNullException(nameof(options.LoginResultConvertFunction)),
131 dataTableBuilder);
132 }
116 133 }
Added XFEExtension.NetCore.ServerInteractive/Utilities/XFEStandardServerCoreOptions.cs +39 -0
@@ -0,0 +1,39 @@
1 using XFEExtension.NetCore.ServerInteractive.Models.UserModels;
2 using XFEExtension.NetCore.ServerInteractive.Utilities.DataTable;
3
4 namespace XFEExtension.NetCore.ServerInteractive.Utilities;
5
6 /// <summary>
7 /// XFE服务器核心服务选项
8 /// </summary>
9 public class XFEStandardServerCoreOptions<T> where T : class
10 {
11 /// <summary>
12 /// 获取用户函数
13 /// </summary>
14 public Func<IEnumerable<User>>? GetUserFunction { get; set; }
15 /// <summary>
16 /// 获取加密用户登录模型函数
17 /// </summary>
18 public Func<IEnumerable<EncryptedUserLoginModel>>? GetEncryptedUserLoginModelFunction { get; set; }
19 /// <summary>
20 /// 添加加密用户登录模型函数
21 /// </summary>
22 public Action<EncryptedUserLoginModel>? AddEncryptedUserLoginModelFunction { get; set; }
23 /// <summary>
24 /// 删除加密用户登录模型函数
25 /// </summary>
26 public Action<EncryptedUserLoginModel>? RemoveEncryptedUserLoginModelFunction { get; set; }
27 /// <summary>
28 /// 获取登录保持天数函数
29 /// </summary>
30 public Func<int>? GetLoginKeepDays { get; set; }
31 /// <summary>
32 /// 登录结果转换函数(将用户模型转换为要返回给客户端的登录结果模型)
33 /// </summary>
34 public Func<object, T>? LoginResultConvertFunction { get; set; }
35 /// <summary>
36 /// 数据表管理器构建器(用于构建数据表管理器,数据表管理器用于处理与数据表相关的请求)
37 /// </summary>
38 public XFEDataTableManagerBuilder? DataTableManagerBuilder { get; set; }
39 }