Skip to content

Commit

Permalink
是否引用了星尘SDK的APP。这类APP自带性能上报,无需Deploy上报
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 25, 2024
1 parent fced733 commit 20a3357
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
1 change: 0 additions & 1 deletion Stardust/Deployment/ZipDeploy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Xml.Serialization;
using NewLife;
using NewLife.Log;
using Stardust.Models;
Expand Down
62 changes: 44 additions & 18 deletions Stardust/Managers/ServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ internal class ServiceController : DisposeBase
/// <summary>事件客户端</summary>
public IEventProvider? EventProvider { get; set; }

/// <summary>是否引用了星尘SDK的APP。这类APP自带性能上报,无需Deploy上报</summary>
public Boolean IsStarApp { get; set; }

private String? _fileName;
private String? _workdir;
private TimerX? _timer;
Expand Down Expand Up @@ -148,24 +151,29 @@ public Boolean Start()
case ServiceModes.Multiple:
break;
case ServiceModes.Extract:
WriteLog("解压后不运行,外部主机(如IIS)将托管应用");
Extract(src, args, workDir, false);
Running = true;
return true;
{
WriteLog("解压后不运行,外部主机(如IIS)将托管应用");
var deploy = Extract(src, args, workDir, false);
CheckStarApp(deploy.Shadow, workDir);
Running = true;
return true;
}
case ServiceModes.ExtractAndRun:
WriteLog("解压后在工作目录运行");
var deploy = Extract(src, args, workDir, false);
if (deploy == null) throw new Exception("解压缩失败");

//file ??= deploy.ExecuteFile;
var runfile = deploy.FindExeFile(workDir);
file = runfile?.FullName;
if (file.IsNullOrEmpty()) throw new Exception("无法找到启动文件");

args = deploy.Arguments;
//_fileName = deploy.ExecuteFile;
isZip = false;
break;
{
WriteLog("解压后在工作目录运行");
var deploy = Extract(src, args, workDir, false);
if (deploy == null) throw new Exception("解压缩失败");

//file ??= deploy.ExecuteFile;
var runfile = deploy.FindExeFile(workDir);
file = runfile?.FullName;
if (file.IsNullOrEmpty()) throw new Exception("无法找到启动文件");

args = deploy.Arguments;
//_fileName = deploy.ExecuteFile;
isZip = false;
break;
}
case ServiceModes.RunOnce:
//service.Enable = false;
break;
Expand All @@ -181,6 +189,7 @@ public Boolean Start()
if (p == null) return false;

WriteLog("启动成功 PID={0}/{1}", p.Id, p.ProcessName);
CheckStarApp(Path.GetDirectoryName(_fileName), workDir);

if (service.Mode == ServiceModes.RunOnce)
{
Expand Down Expand Up @@ -244,6 +253,7 @@ public Boolean Start()
//deploy.Extract(workDir);
// 要解压缩到影子目录,否则可能会把appsettings.json等配置文件覆盖。用完后删除
var shadow = deploy.CreateShadow($"{deploy.Name}-{DateTime.Now:yyyyMMddHHmmss}");
deploy.Shadow = shadow;
deploy.Extract(shadow, CopyModes.ClearBeforeCopy, CopyModes.SkipExists, CopyModes.Overwrite);
try
{
Expand Down Expand Up @@ -437,6 +447,22 @@ public Boolean Start()
return p;
}

private void CheckStarApp(String exeDir, String workDir)
{
// 是否引用了星尘SDK的APP。这类APP自带性能上报,无需Deploy上报
IsStarApp = false;
var starFile = exeDir.CombinePath("Stardust.dll").GetFullPath();
if (File.Exists(starFile))
{
IsStarApp = true;
}
else
{
starFile = workDir.CombinePath("Stardust.dll").GetFullPath();
if (File.Exists(starFile)) IsStarApp = true;
}
}

/// <summary>停止应用,等待一会确认进程已退出</summary>
/// <param name="reason"></param>
public void Stop(String reason)
Expand Down Expand Up @@ -602,7 +628,7 @@ public Boolean Check()

// 检测并上报性能
p = Process;
if (p != null && EventProvider is StarClient client)
if (p != null && EventProvider is StarClient client && !IsStarApp)
{
if (_appInfo == null || _appInfo.Id != p.Id)
_appInfo = new AppInfo(p) { AppName = inf.Name };
Expand Down

0 comments on commit 20a3357

Please sign in to comment.