You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.2 KiB
C#
85 lines
3.2 KiB
C#
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.Core.Helpers;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.Sys.Dtos;
|
|
using DS.WMS.Core.Sys.Interface;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Sys.Method;
|
|
|
|
public class AdminService:IAdminService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
private readonly ISaasDbService saasService;
|
|
private readonly IHttpContextAccessor IhttpContext;
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public AdminService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
IhttpContext = _serviceProvider.GetRequiredService<IHttpContextAccessor>();
|
|
_environment = _serviceProvider.GetRequiredService<IWebHostEnvironment>();
|
|
}
|
|
|
|
#region 获取服务器信息
|
|
|
|
/// <summary>
|
|
/// 获取服务器信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataResult<dynamic> GetServerInfo()
|
|
{
|
|
//核心数
|
|
int cpuNum = Environment.ProcessorCount;
|
|
string computerName = Environment.MachineName;
|
|
string osName = RuntimeInformation.OSDescription;
|
|
string osArch = RuntimeInformation.OSArchitecture.ToString();
|
|
string version = RuntimeInformation.FrameworkDescription;
|
|
string appRAM = ((double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB";
|
|
string startTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
string sysRunTime = ComputerHelper.GetRunTime();
|
|
string serverIP = IhttpContext.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":"
|
|
+ IhttpContext.HttpContext.Connection.LocalPort; //获取服务器IP
|
|
|
|
var programStartTime = Process.GetCurrentProcess().StartTime;
|
|
string programRunTime =
|
|
DateTimeHelper.FormatTime((DateTime.Now - programStartTime).TotalMilliseconds.ToString().Split('.')[0]
|
|
.ParseToLong());
|
|
var data = new
|
|
{
|
|
cpu = ComputerHelper.GetComputerInfo(),
|
|
disk = ComputerHelper.GetDiskInfos(),
|
|
sys = new { cpuNum, computerName, osName, osArch, serverIP, runTime = sysRunTime },
|
|
app = new
|
|
{
|
|
name = _environment.EnvironmentName,
|
|
rootPath = _environment.ContentRootPath,
|
|
webRootPath = _environment.WebRootPath,
|
|
version,
|
|
appRAM,
|
|
startTime,
|
|
runTime = programRunTime,
|
|
host = serverIP
|
|
},
|
|
};
|
|
return DataResult<dynamic>.Success(data);
|
|
}
|
|
|
|
#endregion 获取服务器信息
|
|
} |