This commit is contained in:
owenchen committed 2026-09-21 13:05:20 +08:00
1 parent f40f6e9923
commit 9e79a6a67c
16 files changed
+382

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
CloudBuilder.Topshelf/.vs
CloudBuilder.Topshelf/obj
CloudBuilder.Topshelf/bin
@@ -0,0 +1,85 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Lib\**" />
<Compile Remove="mp3\**" />
<Compile Remove="mp3_new1\**" />
<Compile Remove="mp3_new\**" />
<EmbeddedResource Remove="Lib\**" />
<EmbeddedResource Remove="mp3\**" />
<EmbeddedResource Remove="mp3_new1\**" />
<EmbeddedResource Remove="mp3_new\**" />
<None Remove="Lib\**" />
<None Remove="mp3\**" />
<None Remove="mp3_new1\**" />
<None Remove="mp3_new\**" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.50.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Fido2" Version="4.0.1" />
<PackageReference Include="Fido2.AspNet" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Policy\" />
<Folder Include="Utility\" />
</ItemGroup>
<ItemGroup>
<Reference Include="CloudBuilder.Core">
<HintPath>Lib\CloudBuilder.Core.dll</HintPath>
</Reference>
<Reference Include="CloudBuilder.Master">
<HintPath>Lib\CloudBuilder.Master.dll</HintPath>
</Reference>
<Reference Include="CloudBuilder.Master.Service">
<HintPath>Lib\CloudBuilder.Master.Service.dll</HintPath>
</Reference>
<Reference Include="CloudBuilder.Request">
<HintPath>Lib\CloudBuilder.Request.dll</HintPath>
</Reference>
<Reference Include="CloudBuilder.Security">
<HintPath>Lib\CloudBuilder.Security.dll</HintPath>
</Reference>
<Reference Include="CloudBuilder.Security.Service">
<HintPath>Lib\CloudBuilder.Security.Service.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\Docker\CloudBuilder.Topshelf\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudBuilder.Topshelf", "CloudBuilder.Topshelf.csproj", "{63EB47F6-A616-4C64-B850-85ED294E2524}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudBuilder.Request", "..\CloudBuilder\CloudBuilder.Request\CloudBuilder.Request.csproj", "{8A0A5461-7F04-B87A-CE03-309E1D186FEC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{63EB47F6-A616-4C64-B850-85ED294E2524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63EB47F6-A616-4C64-B850-85ED294E2524}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63EB47F6-A616-4C64-B850-85ED294E2524}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63EB47F6-A616-4C64-B850-85ED294E2524}.Release|Any CPU.Build.0 = Release|Any CPU
{8A0A5461-7F04-B87A-CE03-309E1D186FEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A0A5461-7F04-B87A-CE03-309E1D186FEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A0A5461-7F04-B87A-CE03-309E1D186FEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A0A5461-7F04-B87A-CE03-309E1D186FEC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {24F7770A-0647-4A47-B147-80AFD34ACB87}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+158
View File
@@ -0,0 +1,158 @@
using CloudBuilder;
using CloudBuilder.Core.Authorization;
using CloudBuilder.Core.DatabaseAccessor;
using CloudBuilder.Core.DatabaseAccessor.Entity;
using CloudBuilder.Core.DependencyInjection.Form;
using CloudBuilder.Core.DependencyInjection.Request;
using CloudBuilder.Core.DependencyInjection.Task;
using CloudBuilder.Core.Policy;
using CloudBuilder.Core.Service;
using CloudBuilder.Request.Security;
using CloudBuilder.Security.Data;
using CloudBuilder.Security.Policy;
using CloudBuilder.Topshelf.Task;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using System.Text;
public partial class Program
{
/// <summary>
/// request:Y 要求调用webApi参数
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
try
{
// 设置控制台编码为UTF-8,解决中文乱码问题
Console.OutputEncoding = Encoding.UTF8;
Console.InputEncoding = Encoding.UTF8;
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
string taskName = null;
Dictionary<string, string> bodyDict = new Dictionary<string, string>();
File.AppendAllText("log.txt", "Main:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
if (args != null && args.Length > 0)
{
var services = new ServiceCollection();
services.Initialize();
var serviceProvider = services.BuildServiceProvider();
ApplicationServiceContext applicationServiceContext = serviceProvider.GetService<ApplicationServiceContext>()!;
string key = null;
string[] temp = null;
foreach (string s in args)
{
temp = s.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
if (temp.Length <= 1) continue;
if (temp[1] == null || temp[1].Trim() == string.Empty) continue;
key = temp[0].Trim();
if (key == "task")
{
taskName = temp[1];// config.TaskMappings.Where(x => x.Task == temp[1]).FirstOrDefault();
if (taskName == null) continue;
continue;
}
if (bodyDict.ContainsKey(key)) continue;
bodyDict.Add(key, temp[1]);
}
if (string.IsNullOrEmpty(taskName)) return;
try
{
IApplicationService applicationService = serviceProvider.GetService<IApplicationService>();
applicationService.UserId = applicationService.Configuration["IApplicationService:UserId"];
//如果有传入用户ID,则使用传入的用户ID
if (bodyDict.ContainsKey("user_id"))
{
applicationService.UserId = bodyDict["user_id"];
}
IEnumerable<IScheduleTask> tasks = serviceProvider.GetServices<IScheduleTask>();
foreach (var task in tasks)
{
if (task.GetType().Name.ToLower() != taskName.ToLower()) continue;
if (bodyDict.ContainsKey("request") && bodyDict["request"].ToUpper().Trim() == "Y") Login(applicationService);
task.Run(bodyDict);
}
}
catch (Exception ex)
{
Console.WriteLine($"[{ex.Message}]");
}
finally
{
Environment.Exit(0);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
static void Login(IApplicationService applicationService)
{
#region 系统用户登录
try
{
LoginData loginData = new LoginData();
//从容器获取请求对象
AuthRequest authRequest = ServiceHelper.GetTypeService<AuthRequest>();
//获取RSA公钥
string pubKey = authRequest.GetRsaPublicKey();
//加密用户密码
string psw = applicationService.Configuration["CloudBuilder:SecurityUser:UserPassword"]!;
loginData.Guid = psw.Substring(0, 36);
var rsa = new RSA(pubKey, true);
loginData.UserMobile = applicationService.Configuration["CloudBuilder:SecurityUser:UserMobile"]!;
loginData.RsaUserPassword = rsa.Encode(psw);
//设置当前文化
loginData.Culture = CulturePolicy.ZH_CN;
LoginProfile loginProfile;
loginProfile = authRequest.Login(loginData);
IContext loginContext = ServiceHelper.GetInterfaceService<IContext>()!;
//登录成功后设置登录上下文
loginContext.Requestor = loginProfile.Username;
loginContext.SetPermissionInfo(loginProfile.PermissionInfo);
loginContext.SetToken(loginProfile.Token.AccessToken);
loginContext.LoginDate = DateTime.Now;
}
catch (Exception ex)
{
throw ex;
}
//ISecurityMasterService securityMasterService = service.ServiceProvider.GetService<ISecurityMasterService>();
//SecurityMasterEntityKey key = new SecurityMasterEntityKey();
//key.MasterCodeItem = "default_work_shift";
//key.MasterCategory = "CloudBuilder.Hr.Policy.Master";
//key.MasterSubcategory = "StaffWorkShiftPolicy";
//SecurityMasterEntity securityMaster = securityMasterService.FindByKey(key);
#endregion
}
}
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0\publish\linux-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<History>True|2026-09-21T03:59:35.1020536Z||;True|2026-09-21T11:50:47.8944224+08:00||;True|2026-09-21T11:30:52.9019631+08:00||;True|2026-09-21T10:47:01.8026331+08:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
@@ -0,0 +1,8 @@
{
"profiles": {
"CloudBuilder.Topshelf": {
"commandName": "Project",
"commandLineArgs": "task:RunTask request:Y"
}
}
}
+34
View File
@@ -0,0 +1,34 @@
using CloudBuilder.Core.DatabaseAccessor.Entity;
using CloudBuilder.Core.DependencyInjection.Task;
using Microsoft.Extensions.Configuration;
namespace CloudBuilder.Topshelf.Task
{
//task:RunTask param_name:param_value
public class RunTask : IScheduleTask
{
private readonly IApplicationService service;
private readonly IConfiguration config;
public RunTask(IApplicationService service, IConfiguration config)
{
this.service = service;
this.config = config;
}
public void Run(Dictionary<string, string> bodyDict)
{
File.AppendAllText("log.txt", "RunTask:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
try
{
new FileLog(config).WriteToFile("RunTask");
}
catch (Exception ex)
{
File.AppendAllText("log.txt", "RunTask:" + ex.Message);
throw;
}
}
}
}
+33
View File
@@ -0,0 +1,33 @@
{
"Logging": {
"LogFileDirectory": "D:\\Net8\\FileServer\\Log",
"MaxFileSizeMB": 20
},
"CloudBuilder": {
"Culture": "zh-cn",
"DbContexts": {
"MasterDbContext": {
"DbContextTypeName": "MasterDbContext",
"ConnectionString": "server=nas.youjiala.com;port=3307;database=builder;uid=root;pwd=Root@1237890;CharSet=utf8mb4;",
"DatabaseType": "MySql",
"LazyLoadingProxiesEnabled": true,
"AuditEntityEnabled": true,
"AutoMigrationEnabled": true
}
},
"ServiceRequest": {
"BaseAddress": "https://uat.youjiala.com", //通过Request是需要用户权限及服务器支持
"DefaultRequestHeaders": {
"Accept": "application/json"
}
},
"SecurityUser": {
"UserPassword": "1b457798-6d49-4b37-93a4-a6e105cce84b202cb962ac59075b964b07152d234b70",
"UserMobile": "13560851330"
}
},
"IApplicationService": {
"UserId": "000003" //通过Service是不需要用户权限而直接调用
},
"AllowedHosts": "*"
}