From 0d57e72bbf9468a7f9fe8a0344bfddfd992aee71 Mon Sep 17 00:00:00 2001 From: Kimdiego2098 <2248356998@qq.com> Date: Thu, 26 Oct 2023 10:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A1=AC=E4=BB=B6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20=E7=9B=B8=E5=85=B3json=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Workers/HardwareInfo/HardwareInfoWorker.cs | 13 +++++++++---- .../ThingsGateway.Web.Core/Configuration/App.json | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs b/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs index 5ec7a0471..b50cffcd9 100644 --- a/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs +++ b/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs @@ -102,23 +102,28 @@ public class HardwareInfoWorker : BackgroundService string currentPath = Directory.GetCurrentDirectory(); DriveInfo drive = new(Path.GetPathRoot(currentPath)); + var remoteIpEnable = App.GetConfig("HardwareInfo:RemoteIpEnable") ?? true; + var enable = App.GetConfig("HardwareInfo:Enable") ?? true; + var timeInterval = App.GetConfig("HardwareInfo:TimeInterval") ?? 10000; + if (timeInterval < 5000) timeInterval = 5000; APPInfo.DriveInfo = drive; APPInfo.HostName = Environment.MachineName; // 主机名称 APPInfo.SystemOs = RuntimeInformation.OSDescription; // 操作系统 APPInfo.OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(); // 系统架构 - APPInfo.RemoteIp = await GetIpFromOnlineAsync(); // 外网地址 + if (remoteIpEnable) + APPInfo.RemoteIp = await GetIpFromOnlineAsync(); // 外网地址 APPInfo.FrameworkDescription = RuntimeInformation.FrameworkDescription; // NET框架 APPInfo.Environment = App.HostEnvironment.IsDevelopment() ? "Development" : "Production"; APPInfo.Stage = App.HostEnvironment.IsStaging() ? "Stage" : "非Stage"; // 是否Stage环境 APPInfo.UpdateTime = DateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(); - var enable = App.GetConfig("HardwareInfo:Enable") ?? true; while (!stoppingToken.IsCancellationRequested) { try { APPInfo.UpdateTime = DateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(); - APPInfo.RemoteIp = await GetIpFromOnlineAsync(); + if (remoteIpEnable) + APPInfo.RemoteIp = await GetIpFromOnlineAsync(); if (enable) { HardwareInfo?.RefreshMemoryStatus(); @@ -127,7 +132,7 @@ public class HardwareInfoWorker : BackgroundService HardwareInfo?.RefreshCPUList(); } //10秒更新一次 - await Task.Delay(10000, stoppingToken); + await Task.Delay(timeInterval, stoppingToken); } catch (TaskCanceledException) { diff --git a/framework/Web/ThingsGateway.Web.Core/Configuration/App.json b/framework/Web/ThingsGateway.Web.Core/Configuration/App.json index 55d32b2c1..32eecd059 100644 --- a/framework/Web/ThingsGateway.Web.Core/Configuration/App.json +++ b/framework/Web/ThingsGateway.Web.Core/Configuration/App.json @@ -21,7 +21,9 @@ }, "HardwareInfo": { - "Enable": true //启用硬件信息获取,部分系统/硬件不支持相关方法,设为false + "Enable": true, //启用硬件信息获取, 部分系统/硬件不支持相关方法,设为false + "RemoteIpEnable": true, //是否获取外网IP地址 + "TimeInterval": 10000 //更新间隔ms }, //动态API设备