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

HaloPixelToolBox

【WinUI3】基于USB HID通讯的花再音响工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using HaloPixelToolBox.Core.Models.User;
using HaloPixelToolBox.Server.Profiles.Data;
using HaloPixelToolBox.Server.Profiles.Manage;
using HaloPixelToolBox.Server.Services.Data;
using XFEExtension.NetCore.ServerInteractive.Interfaces;
using XFEExtension.NetCore.ServerInteractive.Utilities.Extensions;
using XFEExtension.NetCore.ServerInteractive.Utilities.Server;

SaveProfiles();

var server = XFEServerBuilder.CreateBuilder()
                             .UseXFEServer()
                             .AddServerCore(XFEServerCoreBuilder.CreateBuilder()
                                                                .UseXFEStandardServerCore<MyUserFaceInfo>(options =>
                                                                {
                                                                    options.GetUserFunction = static () => UserDataProfile.MyUserTable;
                                                                    options.AddUserFunction = static userInfo => UserDataProfile.MyUserTable.Add(userInfo);
                                                                    options.GetEncryptedUserLoginModelFunction = static () => UserDataProfile.EncryptedUserLoginModelTable;
                                                                    options.AddEncryptedUserLoginModelFunction = UserDataProfile.EncryptedUserLoginModelTable.Add;
                                                                    options.RemoveEncryptedUserLoginModelFunction = UserDataProfile.EncryptedUserLoginModelTable.Remove;
                                                                    options.GetLoginKeepDays = static () => 2;
                                                                    options.LoginResultConvertFunction = static user => MyUserFaceInfo.FromUser((IUserInfo)user);
                                                                })
                                                                .AddService<AddressResolverService>()
                                                                .AddParameter("EditAddressPermission", (int)UserRole.管理员)
                                                                .AddParameter("GetPermission", (int)UserRole.管理员)
                                                                .AddParameter("AddPermission", (int)UserRole.管理员)
                                                                .AddParameter("RemovePermission", (int)UserRole.管理员)
                                                                .Build(options =>
                                                                {
                                                                    options.ServerCoreName = "HaloPixelToolBoxServer";
                                                                    options.MainEntryPoint = "api";
                                                                    options.GetIPFunction = static args => args.RequestHeaders["X-Forwarded-For"] ?? args.ClientIP;
                                                                    options.BindIP(ServerProfile.ServerBindingIpAddress);
                                                                }))
                             .Build();

await server.Start();

void SaveProfiles()
{
    ServerProfile.SaveProfile();
    UserDataProfile.SaveProfile();
    MainDataProfile.SaveProfile();
}