|
@@ -1,86 +0,0 @@
|
|
|
-using System;
|
|
|
|
|
-using System.Collections.Generic;
|
|
|
|
|
-using System.Data.Entity.Core.Objects;
|
|
|
|
|
-using System.Diagnostics;
|
|
|
|
|
-using System.IO;
|
|
|
|
|
-using System.Linq;
|
|
|
|
|
-using System.Management;
|
|
|
|
|
-using System.Text;
|
|
|
|
|
-using System.Threading.Tasks;
|
|
|
|
|
-
|
|
|
|
|
-namespace OHV.Vehicle
|
|
|
|
|
-{
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// CPU/RAM Monitor
|
|
|
|
|
- /// </summary>
|
|
|
|
|
- public class DeskTopInfo
|
|
|
|
|
- {
|
|
|
|
|
- private PerformanceCounter cpu, ram;
|
|
|
|
|
-
|
|
|
|
|
- public const int GB = 1024;
|
|
|
|
|
-
|
|
|
|
|
- public double totalMemory { get; }
|
|
|
|
|
- public float cpuResult { get; set; }
|
|
|
|
|
- public double cDriveCapacity { get; set; }
|
|
|
|
|
-
|
|
|
|
|
- public DeskTopInfo()
|
|
|
|
|
- {
|
|
|
|
|
- this.ram = new PerformanceCounter("Memory", "Available MBytes");
|
|
|
|
|
- this.cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");
|
|
|
|
|
-
|
|
|
|
|
- totalMemory = GetPhysicalMemory();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private double GetPhysicalMemory()
|
|
|
|
|
- {
|
|
|
|
|
- System.Management.ObjectQuery winQuery = new System.Management.ObjectQuery( "SELECT * FROM Win32_OperatingSystem");
|
|
|
|
|
- ManagementObjectSearcher searcher = new ManagementObjectSearcher(winQuery);
|
|
|
|
|
- ManagementObjectCollection queryCollection = searcher.Get();
|
|
|
|
|
-
|
|
|
|
|
- double before = 0;
|
|
|
|
|
- ulong memory = 0;
|
|
|
|
|
-
|
|
|
|
|
- foreach (ManagementObject item in queryCollection)
|
|
|
|
|
- {
|
|
|
|
|
- memory = ulong.Parse(item["TotalVisibleMemorySize"].ToString());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- before = memory / GB;
|
|
|
|
|
-
|
|
|
|
|
- return Math.Round(before / GB, 1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public float GetCpuUsage()
|
|
|
|
|
- {
|
|
|
|
|
- return cpuResult = cpu.NextValue();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public double GetRamUsage()
|
|
|
|
|
- {
|
|
|
|
|
- return totalMemory - (ram.NextValue() / GB);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- [System.Runtime.InteropServices.DllImport( "kernel32.dll" , SetLastError = true , CharSet = System.Runtime.InteropServices.CharSet.Auto )]
|
|
|
|
|
- [return: System.Runtime.InteropServices.MarshalAs( System.Runtime.InteropServices.UnmanagedType.Bool )]
|
|
|
|
|
- static extern bool GetDiskFreeSpaceEx( string lpDirectoryName ,
|
|
|
|
|
- out ulong lpFreeBytesAvailable , out ulong lpTotalNumberOfBytes ,
|
|
|
|
|
- out ulong lpTotalNumberOfFreeBytes );
|
|
|
|
|
-
|
|
|
|
|
- public double GetDrive()
|
|
|
|
|
- {
|
|
|
|
|
- ulong available, total, free;
|
|
|
|
|
-
|
|
|
|
|
- GetDiskFreeSpaceEx( "C:\\" , out available , out total , out free );
|
|
|
|
|
-
|
|
|
|
|
- return 100d * free / total;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public double GetCDrive()
|
|
|
|
|
- {
|
|
|
|
|
- var drive = new DriveInfo("C");
|
|
|
|
|
-
|
|
|
|
|
- //return 100 * drive.TotalFreeSpace / drive.TotalSize;
|
|
|
|
|
- return ( ( ( drive.TotalSize / 1024 ) / 1024 ) / 1024);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|