コード例 #1
0
        /// <summary>
        /// 获取硬件基本信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetBaseInfo()
        {
            var cpuInfo   = SystemInfo.GetCpuInfo();
            var ramInfo   = SystemInfo.GetRamInfo();
            var osVersion = Windows.GetOsVersion();
            var mac       = SystemInfo.GetMacAddress();
            var ips       = SystemInfo.GetLocalIPs().OrderBy(u => u.Address.AddressFamily != AddressFamily.InterNetwork).Select(a => a.Address.ToString()).ToList();
            var diskTotal = SystemInfo.DiskTotalSpace().Select(kv => kv.Key + kv.Value).Join(" | ");
            var diskFree  = SystemInfo.DiskFree().Select(kv => kv.Key + kv.Value).Join(" | ");
            var diskUsage = SystemInfo.DiskUsage().Select(kv => kv.Key + kv.Value.ToString("P")).Join(" | ");
            var span      = DateTime.Now - CommonHelper.StartupTime;
            var boot      = DateTime.Now - SystemInfo.BootTime();

            return(Json(new
            {
                runningTime = $"{span.Days}天{span.Hours}小时{span.Minutes}分钟",
                bootTime = $"{boot.Days}天{boot.Hours}小时{boot.Minutes}分钟",
                cpuInfo,
                ramInfo,
                osVersion,
                diskInfo = new
                {
                    total = diskTotal,
                    free = diskFree,
                    usage = diskUsage
                },
                netInfo = new
                {
                    mac,
                    ips
                }
            }));
        }
コード例 #2
0
ファイル: SystemUtils.cs プロジェクト: hjh1126123/Jeno.Server
 /// <summary>
 /// 获取性能相关信息
 /// </summary>
 /// <returns></returns>
 public Model.ComputedInfo GetComputedInfo()
 {
     return(new Model.ComputedInfo
     {
         CpuInfos = SystemInfo.GetCpuInfo(),
         MemoryPData = SystemInfo.GetMemoryPData(),
         MemoryVData = SystemInfo.GetMemoryVData(),
         DiskTotal = SystemInfo.DiskTotalSpace(),
         FreeDisk = SystemInfo.DiskFree(),
         AllLocalIP = SystemInfo.GetLocalIPs(),
         NetData = SystemInfo.GetNetData(NetData.ReceivedAndSent)
     });
 }
コード例 #3
0
        public async Task <ActionResult> GetBaseInfo()
        {
            List <CpuInfo> cpuInfo   = SystemInfo.GetCpuInfo();
            RamInfo        ramInfo   = SystemInfo.GetRamInfo();
            string         osVersion = SystemInfo.GetOsVersion();
            var            total     = new StringBuilder();
            var            free      = new StringBuilder();
            var            usage     = new StringBuilder();

            SystemInfo.DiskTotalSpace().ForEach(kv => { total.Append(kv.Key + kv.Value + " | "); });
            SystemInfo.DiskFree().ForEach(kv => free.Append(kv.Key + kv.Value + " | "));
            SystemInfo.DiskUsage().ForEach(kv => usage.Append(kv.Key + kv.Value.ToString("P") + " | "));
            IList <string> mac  = SystemInfo.GetMacAddress();
            IList <string> ips  = SystemInfo.GetIPAddress();
            var            span = DateTime.Now - CommonHelper.StartupTime;
            var            boot = DateTime.Now - SystemInfo.BootTime();

            return(Content(await new { runningTime = $"{span.Days}天{span.Hours}小时{span.Minutes}分钟", bootTime = $"{boot.Days}天{boot.Hours}小时{boot.Minutes}分钟", cpuInfo, ramInfo, osVersion, diskInfo = new { total = total.ToString(), free = free.ToString(), usage = usage.ToString() }, netInfo = new { mac, ips } }.ToJsonStringAsync().ConfigureAwait(false), "application/json"));
        }