硬件信息获取添加异常拦截
This commit is contained in:
@@ -15,7 +15,7 @@ namespace ThingsGateway.Web.Foundation
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class HardwareInfoService : ISingleton
|
public class HardwareInfoService : ISingleton
|
||||||
{
|
{
|
||||||
private readonly Hardware.Info.HardwareInfo hardwareInfo = new();
|
private readonly Hardware.Info.HardwareInfo hardwareInfo;
|
||||||
|
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
|
|
||||||
@@ -27,28 +27,44 @@ namespace ThingsGateway.Web.Foundation
|
|||||||
var loggerFactory = scope.ServiceProvider.GetRequiredService<ILoggerFactory>();
|
var loggerFactory = scope.ServiceProvider.GetRequiredService<ILoggerFactory>();
|
||||||
_logger = loggerFactory.CreateLogger(nameof(HardwareInfoService));
|
_logger = loggerFactory.CreateLogger(nameof(HardwareInfoService));
|
||||||
});
|
});
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hardwareInfo = new();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
hardwareInfo.RefreshMemoryStatus();
|
try
|
||||||
hardwareInfo.RefreshMemoryList();
|
|
||||||
hardwareInfo.RefreshDriveList();
|
|
||||||
hardwareInfo.RefreshNetworkAdapterList();
|
|
||||||
hardwareInfo.RefreshCPUList();
|
|
||||||
aPPInfo = new()
|
|
||||||
{
|
{
|
||||||
HostName = Environment.MachineName, // 主机名称
|
|
||||||
SystemOs = RuntimeInformation.OSDescription, // 操作系统
|
|
||||||
OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(), // 系统架构
|
hardwareInfo?.RefreshMemoryStatus();
|
||||||
RemoteIp = await GetIpFromOnlineAsync(), // 外网地址
|
hardwareInfo?.RefreshMemoryList();
|
||||||
FrameworkDescription = RuntimeInformation.FrameworkDescription, // NET框架
|
hardwareInfo?.RefreshDriveList();
|
||||||
Environment = App.HostEnvironment.IsDevelopment() ? "Development" : "Production",
|
hardwareInfo?.RefreshNetworkAdapterList();
|
||||||
Stage = App.HostEnvironment.IsStaging() ? "Stage" : "非Stage", // 是否Stage环境
|
hardwareInfo?.RefreshCPUList();
|
||||||
};
|
aPPInfo = new()
|
||||||
await Task.Delay(5000);
|
{
|
||||||
|
HostName = Environment.MachineName, // 主机名称
|
||||||
|
SystemOs = RuntimeInformation.OSDescription, // 操作系统
|
||||||
|
OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(), // 系统架构
|
||||||
|
RemoteIp = await GetIpFromOnlineAsync(), // 外网地址
|
||||||
|
FrameworkDescription = RuntimeInformation.FrameworkDescription, // NET框架
|
||||||
|
Environment = App.HostEnvironment.IsDevelopment() ? "Development" : "Production",
|
||||||
|
Stage = App.HostEnvironment.IsStaging() ? "Stage" : "非Stage", // 是否Stage环境
|
||||||
|
};
|
||||||
|
await Task.Delay(5000);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -63,7 +79,7 @@ namespace ThingsGateway.Web.Foundation
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 硬件信息获取
|
/// 硬件信息获取
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TGHardwareInfo HardwareInfo => hardwareInfo.Adapt<TGHardwareInfo>();
|
public TGHardwareInfo HardwareInfo => hardwareInfo?.Adapt<TGHardwareInfo>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IP地址信息
|
/// IP地址信息
|
||||||
|
Reference in New Issue
Block a user