From 37938485ba5f51fd1db18a7f132f9fae090e8388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sat, 2 Sep 2023 23:35:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=98=9F=E5=B0=98=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=9C=8D=E5=8A=A1StarService=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0SetServer=EF=BC=8C=E5=9C=A8StarAgent=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=94=AF=E6=8C=81=E6=9C=AC=E5=9C=B0=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=8E=A5=E5=8F=A3=E8=AE=BE=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StarAgent/StarService.cs | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/StarAgent/StarService.cs b/StarAgent/StarService.cs index de676116..3a96851b 100644 --- a/StarAgent/StarService.cs +++ b/StarAgent/StarService.cs @@ -1,5 +1,7 @@ using NewLife; +using NewLife.Agent; using NewLife.Log; +using NewLife.Model; using NewLife.Net; using NewLife.Remoting; using NewLife.Serialization; @@ -71,27 +73,9 @@ protected override void Dispose(Boolean disposing) [Api(nameof(Info))] public AgentInfo Info(AgentInfo info) { - //using var span = Manager?.Tracer?.NewSpan("ApiInfo"); XTrace.WriteLine("Info<={0}", info.ToJson()); var set = StarSetting; - //// 使用对方送过来的星尘服务端地址 - //if (set.Server.IsNullOrEmpty() && !info.Server.IsNullOrEmpty()) - //{ - // set.Server = info.Server; - // set.Save(); - - // XTrace.WriteLine("StarAgent使用应用[{0}]送过来的星尘服务端地址:{1}", info.ProcessId, info.Server); - - // if (Provider?.GetService() is MyService svc) - // { - // ThreadPool.QueueUserWorkItem(s => - // { - // svc.StartFactory(); - // svc.StartClient(); - // }); - // } - //} var ai = _agentInfo ??= AgentInfo.GetLocal(true); ai.Server = set.Server; @@ -101,6 +85,34 @@ public AgentInfo Info(AgentInfo info) return ai; } + /// 设置星尘服务端地址 + /// + [Api(nameof(SetServer))] + public String SetServer(String server) + { + var set = StarSetting; + if (set.Server.IsNullOrEmpty() && !server.IsNullOrEmpty()) + { + set.Server = server; + set.Save(); + + XTrace.WriteLine("StarAgent使用[{0}]送过来的星尘服务端地址:{1}", Session, server); + + if (Provider?.GetService() is MyService svc) + { + ThreadPool.QueueUserWorkItem(s => + { + Thread.Sleep(1000); + + svc.StartFactory(); + svc.StartClient(); + }); + } + } + + return set.Server; + } + private void DoRefreshLocal(Object state) { var ai = AgentInfo.GetLocal(true);