星尘发布架构图;DeployAgent支持作为节点向服务端心跳智能大石头 authored at 2025-04-17 00:51:12
diff --git a/DeployAgent/DeployAgent.csproj b/DeployAgent/DeployAgent.csproj
index 9f7b2ac..8c4be7e 100644
--- a/DeployAgent/DeployAgent.csproj
+++ b/DeployAgent/DeployAgent.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFrameworks>net461;net8.0;net9.0</TargetFrameworks>
+ <TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<AssemblyTitle>星尘发布</AssemblyTitle>
<Description>自动下载代码,编译后打包输出并推送发布中心。</Description>
<Company>新生命开发团队</Company>
diff --git a/DeployAgent/DeploySetting.cs b/DeployAgent/DeploySetting.cs
new file mode 100644
index 0000000..c65e5d6
--- /dev/null
+++ b/DeployAgent/DeploySetting.cs
@@ -0,0 +1,24 @@
+using System.ComponentModel;
+using NewLife.Configuration;
+using NewLife.Remoting.Clients;
+
+namespace DeployAgent;
+
+/// <summary>配置</summary>
+[Config("DeployAgent")]
+public class DeploySetting : Config<DeploySetting>, IClientSetting
+{
+ #region 属性
+ /// <summary>服务端地址</summary>
+ [Description("服务端地址")]
+ public String Server { get; set; } = "http://localhost:6600";
+
+ /// <summary>客户端编码</summary>
+ [Description("客户端编码")]
+ public String Code { get; set; }
+
+ /// <summary>客户端密钥</summary>
+ [Description("客户端密钥")]
+ public String Secret { get; set; }
+ #endregion
+}
\ No newline at end of file
diff --git a/DeployAgent/DeployWorker.cs b/DeployAgent/DeployWorker.cs
index 4967792..44366ef 100644
--- a/DeployAgent/DeployWorker.cs
+++ b/DeployAgent/DeployWorker.cs
@@ -1,4 +1,5 @@
-using NewLife;
+using NewLife;
+using NewLife.Log;
using NewLife.Model;
using NewLife.Remoting.Clients;
using NewLife.Serialization;
@@ -7,24 +8,49 @@ using Stardust.Models;
namespace DeployAgent;
-public class DeployWorker : IHostedService
+public class DeployWorker(StarFactory factory) : IHostedService
{
- private readonly StarFactory _factory;
+ private StarClient _client;
- public DeployWorker(StarFactory factory)
+ public Task StartAsync(CancellationToken cancellationToken)
{
- _factory = factory;
+ XTrace.WriteLine("开始Deploy客户端");
+
+ var set = DeploySetting.Current;
+
+ // 产品编码、产品密钥从IoT管理平台获取,设备编码支持自动注册
+ var client = new StarClient(factory.Server)
+ {
+ Code = set.Code,
+ Secret = set.Secret,
+ ProductCode = factory.AppId,
+ Setting = set,
+
+ Tracer = factory.Tracer,
+ Log = XTrace.Log,
+ };
+
+ // 禁用客户端特性
+ client.Features &= ~Features.Upgrade;
+
+ client.Open();
+
+ Host.RegisterExit(() => client.Logout("ApplicationExit"));
+
+ _client = client;
+
+ client.RegisterCommand("deploy/compile", OnCompile);
+
+ return Task.CompletedTask;
}
- public Task StartAsync(CancellationToken cancellationToken)
+ public Task StopAsync(CancellationToken cancellationToken)
{
- _factory.App.RegisterCommand("deploy/compile", OnCompile);
+ _client.TryDispose();
return Task.CompletedTask;
}
- public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
-
private String OnCompile(String args)
{
if (args.IsNullOrEmpty()) throw new ArgumentNullException(nameof(args));
diff --git "a/Doc/\346\230\237\345\260\230\345\217\221\345\270\203.emmx" "b/Doc/\346\230\237\345\260\230\345\217\221\345\270\203.emmx"
new file mode 100644
index 0000000..02f6b17
Binary files /dev/null and "b/Doc/\346\230\237\345\260\230\345\217\221\345\270\203.emmx" differ
diff --git "a/Doc/\346\230\237\345\260\230\345\217\221\345\270\203.png" "b/Doc/\346\230\237\345\260\230\345\217\221\345\270\203.png"
new file mode 100644
index 0000000..d45e0a3
Binary files /dev/null and "b/Doc/\346\230\237\345\260\230\345\217\221\345\270\203.png" differ