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.System.Dtos;
using DS.WMS.Core.System.Interface;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.System.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;
///
///
///
///
public AdminService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
IhttpContext = _serviceProvider.GetRequiredService();
_environment = _serviceProvider.GetRequiredService();
}
#region 获取服务器信息
///
/// 获取服务器信息
///
///
public DataResult 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.Success(data);
}
#endregion 获取服务器信息
}