|
| 1 | +using PLP_SystemInfo.Collections; |
| 2 | +using System; |
| 3 | +using System.Collections.ObjectModel; |
| 4 | +using System.Management; |
| 5 | + |
| 6 | +namespace PLP_SystemInfo.ComponentInfo |
| 7 | +{ |
| 8 | + public class ProcessorInfo |
| 9 | + { |
| 10 | + //Processor |
| 11 | + static string GetProcessorArchitecture(int i) |
| 12 | + { |
| 13 | + switch (i) |
| 14 | + { |
| 15 | + case 0: |
| 16 | + return "x86"; |
| 17 | + case 1: |
| 18 | + return "MIPS"; |
| 19 | + case 2: |
| 20 | + return "Alpha"; |
| 21 | + case 3: |
| 22 | + return "PowerPC"; |
| 23 | + case 5: |
| 24 | + return "ARM"; |
| 25 | + case 6: |
| 26 | + return "ia64"; |
| 27 | + case 9: |
| 28 | + return "x64"; |
| 29 | + case 12: |
| 30 | + return "ARM64"; |
| 31 | + default: return "unknown"; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + static Collection<double> GetCacheSize() |
| 36 | + { |
| 37 | + Collection<double> result = new Collection<double>(); |
| 38 | + |
| 39 | + ManagementClass mgmtc = new ManagementClass("Win32_CacheMemory"); |
| 40 | + foreach (ManagementObject o in mgmtc.GetInstances()) |
| 41 | + { |
| 42 | + double max = double.Parse(o["MaxCacheSize"].ToString()) / 1024d; |
| 43 | + result.Add(max); |
| 44 | + } |
| 45 | + |
| 46 | + return result; |
| 47 | + } |
| 48 | + |
| 49 | + public static ProcessorCollection GetProcessors() |
| 50 | + { |
| 51 | + ProcessorCollection processors = new ProcessorCollection(); |
| 52 | + Collection<double> result = GetCacheSize(); |
| 53 | + |
| 54 | + int i = -1; |
| 55 | + foreach (var item in new ManagementObjectSearcher("Select * from Win32_Processor").Get()) |
| 56 | + { |
| 57 | + i++; |
| 58 | + processors.Add(new Models.Processor( |
| 59 | + item["Name"].ToString(), |
| 60 | + GetProcessorArchitecture(int.Parse(item["Architecture"].ToString())), |
| 61 | + Environment.ProcessorCount, |
| 62 | + int.Parse(item["NumberOfCores"].ToString()), |
| 63 | + double.Parse(item["L2CacheSize"].ToString()) / 1024d, |
| 64 | + double.Parse(item["L3CacheSize"].ToString()) / 1024d, |
| 65 | + result[i], |
| 66 | + double.Parse(item["CurrentClockSpeed"].ToString()) / 1000d, |
| 67 | + double.Parse(item["MaxClockSpeed"].ToString()) / 1000d)); |
| 68 | + } |
| 69 | + |
| 70 | + return processors; |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments