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
README.md

XFEExtension.NetCore.ServerInteractive

描述

ServerInteractive是一个C#的DLL库,其负责搭建以XFEExtension.NetCore提供的CyberComm网络架构,让使用者可以快速构建服务器和客户端网络框架

示例(使用前记得进行相应的引用)


搭建服务器端网络框架

使用XFE标准网络架构

var server = XFEServerBuilder.CreateBuilder() // 创建服务器构建器
    .UseXFEServer()                           // 使用XFE服务器架构
    .AddServerCore(                           // 添加核心服务器
                   XFEServerCoreBuilder.CreateBuilder()                // 创建核心服务器构建器
                                       .UseXFEStandardServerCore<IUserFaceInfo>(options =>
                                       {                               // 使用XFE标准服务器核心
                                           options.GetUserFunction = static () => UserProfile.UserTable;                                                         // 获取用户表的方法
                                           options.GetEncryptedUserLoginModelFunction = static () => UserProfile.EncryptedUserLoginModelTable;                   // 获取用户加密模型的方法
                                           options.AddEncryptedUserLoginModelFunction = UserProfile.EncryptedUserLoginModelTable.Add;                            // 添加用户加密模型的方法
                                           options.RemoveEncryptedUserLoginModelFunction = static user => UserProfile.EncryptedUserLoginModelTable.Remove(user); // 移除用户加密模型的方法
                                           options.GetLoginKeepDays = static () => 7;                                                                            // 获取登录维持天数方法
                                           options.LoginResultConvertFunction = static user => (IUserFaceInfo)user;                                              // 登录结果转换方法
                                           options.DataTableManagerBuilder = XFEDataTableManagerBuilder.CreateBuilder()                                          // 创建DataTable管理器构建器
                                               .AddTable<Person, DataProfile>("人物", (int)UserRole.业务员, (int)UserRole.经理, (int)UserRole.业务员, (int)UserRole.业务员) // 添加名为人物的格,   Person 类    型,      AutoConfig为     DataProfile。添加更改获取权限为业务员,移除权限为经理
                                               .AddTable<Order, DataProfile>("订单", (int)UserRole.业务员, (int)UserRole.经理, (int)UserRole.业务员, (int)UserRole.业务员)  // 添加名为订单的表格Order    类   型,     AutoConfig   为      DataProfile。添加更改获取权限为业务员,移除权限为经理
                                               .AddTable<User, UserProfile>("用户", (int)UserRole.经理, (int)UserRole.经理, (int)UserRole.经理, (int)UserRole.业务员);      // 添加名为用户的表格User类    型,       AutoConfig为         UserProfile。获取权限为业务员,添加移除更改权限为经理
                                       })
                                       .AddStandardService<TestCoreService>("test")
                                       .Build()) // 构建核心服务器
    .Build(); // 构建服务器
await server.Start(); // 启动服务

添加自定义服务

var server = XFEServerBuilder.CreateBuilder()
                             .AddInitializer<MyInitilizerService>() // 自定义初始化服务
                             .AddService<MyService>()               // 自定义服务
                             .AddAsyncService<MyAsyncService>()     // 自定义异步服务
                             .Build();

搭建客户端请求器

使用XFE标准请求器

var xFEClientRequester = XFEClientRequesterBuilder.CreateBuilder("http://localhost:8080/", string.Empty, DeviceHelper.GetUniqueHardwareId()) // 服务器IP地址,用户Session以及硬件编码
                                                  .UseXFEStandardRequest() // 使用XFE标准请求器
                                                  .Build();                // 构建客户端请求器

var result = await xFEClientRequester.Request<(string session, DateTime expireDate)>("login", account, password); // 调用login方法
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
    Console.WriteLine(result.Result.session);
    Console.WriteLine(result.Result.expireDate);
}
else
{
    Console.WriteLine(result.StatusCode);
    Console.WriteLine(result.Message);
}
LICENSE.txt MIT

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.