|
@@ -9,7 +9,8 @@ using System.Text.Json.Nodes;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text.RegularExpressions;
|
|
using System.Management;
|
|
using System.Management;
|
|
using IES.ExamServer.Models;
|
|
using IES.ExamServer.Models;
|
|
-
|
|
|
|
|
|
+using System.CodeDom.Compiler;
|
|
|
|
+
|
|
namespace IES.ExamServer.Services
|
|
namespace IES.ExamServer.Services
|
|
{
|
|
{
|
|
public static class IndexService
|
|
public static class IndexService
|
|
@@ -20,38 +21,65 @@ namespace IES.ExamServer.Services
|
|
string os = RuntimeInformation.OSDescription;
|
|
string os = RuntimeInformation.OSDescription;
|
|
//获取当前客户端的服务端口
|
|
//获取当前客户端的服务端口
|
|
string currentUserName = Environment.UserName;
|
|
string currentUserName = Environment.UserName;
|
|
-
|
|
|
|
|
|
+ string MachineName =Environment.MachineName;
|
|
|
|
+ //var s = Environment;
|
|
ServerDevice device = new ServerDevice { name =hostName, userName=currentUserName, os= os,region=region,remote=remote };
|
|
ServerDevice device = new ServerDevice { name =hostName, userName=currentUserName, os= os,region=region,remote=remote };
|
|
int CpuCoreCount = 0;
|
|
int CpuCoreCount = 0;
|
|
long MenemorySize = 0;
|
|
long MenemorySize = 0;
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
{
|
|
{
|
|
|
|
+ CpuCoreCount = Environment.ProcessorCount;
|
|
|
|
+ MenemorySize = MemoryInfo.GetTotalPhysicalMemory();
|
|
|
|
+ //using (PerformanceCounter pc = new PerformanceCounter("Memory", "Available Bytes"))
|
|
|
|
+ //{
|
|
|
|
+ // // 获取可用内存
|
|
|
|
+ // AvailableMemory = (long)pc.NextValue();
|
|
|
|
+
|
|
|
|
+ //}
|
|
|
|
+ //using (PerformanceCounter pc = new PerformanceCounter("Memory", "Committed Bytes"))
|
|
|
|
+ //{
|
|
|
|
+ // // 获取可用内存
|
|
|
|
+ // CommittedMemory= (long)pc.NextValue();
|
|
|
|
+
|
|
|
|
+ //}
|
|
|
|
+ //MenemorySize=AvailableMemory+CommittedMemory;
|
|
|
|
+ //
|
|
|
|
+
|
|
// 获取CPU核心数
|
|
// 获取CPU核心数
|
|
//int processorCount = Environment.ProcessorCount;
|
|
//int processorCount = Environment.ProcessorCount;
|
|
//Console.WriteLine("CPU 核心数: " + processorCount);
|
|
//Console.WriteLine("CPU 核心数: " + processorCount);
|
|
- using (ManagementClass managementClass = new ManagementClass("Win32_Processor"))
|
|
|
|
- {
|
|
|
|
- using (ManagementObjectCollection managementObjectCollection = managementClass.GetInstances())
|
|
|
|
- {
|
|
|
|
- foreach (ManagementObject managementObject in managementObjectCollection)
|
|
|
|
- {
|
|
|
|
- CpuCoreCount += Convert.ToInt32(managementObject.Properties["NumberOfLogicalProcessors"].Value);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- using (ManagementClass mc = new ManagementClass("Win32_ComputerSystem"))
|
|
|
|
- {
|
|
|
|
- using (ManagementObjectCollection moc = mc.GetInstances())
|
|
|
|
- {
|
|
|
|
- foreach (ManagementObject mo in moc)
|
|
|
|
- {
|
|
|
|
- if (mo["TotalPhysicalMemory"]!= null)
|
|
|
|
- {
|
|
|
|
- MenemorySize = Convert.ToInt64(mo["TotalPhysicalMemory"]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //using (ManagementClass managementClass = new ManagementClass("Win32_Processor"))
|
|
|
|
+ //{
|
|
|
|
+ // using (ManagementObjectCollection managementObjectCollection = managementClass.GetInstances())
|
|
|
|
+ // {
|
|
|
|
+ // foreach (ManagementObject managementObject in managementObjectCollection)
|
|
|
|
+ // {
|
|
|
|
+ // CpuCoreCount += Convert.ToInt32(managementObject.Properties["NumberOfLogicalProcessors"].Value);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //using (ManagementObjectSearcher searcher1 = new ManagementObjectSearcher("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem"))
|
|
|
|
+ //{
|
|
|
|
+ // foreach (ManagementObject obj in searcher1.Get())
|
|
|
|
+ // {
|
|
|
|
+ // long MenemorySizes1 = Convert.ToInt64(obj["TotalPhysicalMemory"]);
|
|
|
|
+ // break; // 只需要第一个结果
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ //using (ManagementClass mc = new ManagementClass("Win32_ComputerSystem"))
|
|
|
|
+ //{
|
|
|
|
+ // using (ManagementObjectCollection moc = mc.GetInstances())
|
|
|
|
+ // {
|
|
|
|
+ // foreach (ManagementObject mo in moc)
|
|
|
|
+ // {
|
|
|
|
+ // if (mo["TotalPhysicalMemory"]!= null)
|
|
|
|
+ // {
|
|
|
|
+ // MenemorySize = Convert.ToInt64(mo["TotalPhysicalMemory"]);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
if (Environment.Is64BitOperatingSystem)
|
|
if (Environment.Is64BitOperatingSystem)
|
|
{
|
|
{
|
|
device.bit="64";
|
|
device.bit="64";
|
|
@@ -60,15 +88,18 @@ namespace IES.ExamServer.Services
|
|
{
|
|
{
|
|
device.bit="32";
|
|
device.bit="32";
|
|
}
|
|
}
|
|
- ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, MaxClockSpeed FROM Win32_Processor");
|
|
|
|
- foreach (ManagementObject mo in searcher.Get())
|
|
|
|
- {
|
|
|
|
- string? cpuName = mo["Name"].ToString();
|
|
|
|
- string? clockSpeed = mo["MaxClockSpeed"].ToString();
|
|
|
|
- //Console.WriteLine($"CPU 名称: {cpuName}");
|
|
|
|
- //Console.WriteLine($"CPU 主频: {clockSpeed} MHz");
|
|
|
|
- device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
|
|
|
|
- }
|
|
|
|
|
|
+ //ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, MaxClockSpeed FROM Win32_Processor");
|
|
|
|
+ //foreach (ManagementObject mo in searcher.Get())
|
|
|
|
+ //{
|
|
|
|
+ // string? cpuName = mo["Name"].ToString();
|
|
|
|
+ // string? clockSpeed = mo["MaxClockSpeed"].ToString();
|
|
|
|
+ // //Console.WriteLine($"CPU 名称: {cpuName}");
|
|
|
|
+ // //Console.WriteLine($"CPU 主频: {clockSpeed} MHz");
|
|
|
|
+ // device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
|
|
|
|
+ //}
|
|
|
|
+ string cpuName = MemoryInfo.GetCpuName();
|
|
|
|
+ var clockSpeed = MemoryInfo.GetCpuSpeed();
|
|
|
|
+ device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = $"{clockSpeed}" });
|
|
}
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
{
|