Exemplo n.º 1
0
        protected List <ProcessorDTOResponse> GetWinGTE6ProcessorsInfo()
        {
            List <ProcessorDTOResponse> processors = new List <ProcessorDTOResponse>();

            try
            {
                SelectQuery query = new SelectQuery(
                    @"select 
						Name, 
						Description, 
						DeviceID, 
						MaxClockSpeed, 
						NumberOfCores, 
						NumberOfLogicalProcessors, 
						Caption, 
						Manufacturer, 
						Version,
						DataWidth
					  from Win32_Processor"
                    );
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject obj in searcher.Get())
                {
                    ProcessorDTOResponse processor = new ProcessorDTOResponse();
                    if (vendor.IndexOf("xen") > -1 || vendor.IndexOf("vmware") > -1 || vendor.IndexOf("bochs") > -1)
                    {
                        processor.Label = "Virtual " + GetValueAsString(obj, "Name");
                    }
                    else
                    {
                        processor.Label = GetValueAsString(obj, "Name");
                    }
                    processor.Speed       = GetValueAsString(obj, "MaxClockSpeed");
                    processor.Cores       = GetValueAsString(obj, "NumberOfCores");
                    processor.Index       = GetValueAsString(obj, "DeviceID");
                    processor.Description = GetValueAsString(obj, "Description");
                    processor.NumberOfLogicalProcessors = GetValueAsString(obj, "NumberOfLogicalProcessors");
                    processor.Caption      = GetValueAsString(obj, "Caption");
                    processor.Manufacturer = GetValueAsString(obj, "Manufacturer");
                    processor.Version      = GetValueAsString(obj, "Version");
                    if (GetValueAsString(obj, "DataWidth") == "64")
                    {
                        processor.Is64Bit = "true";
                    }
                    else
                    {
                        processor.Is64Bit = "false";
                    }

                    processors.Add(processor);
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            return(processors);
        }
Exemplo n.º 2
0
        protected List <ProcessorDTOResponse> GetWinLTE6ProcessorsInfo()
        {
            List <ProcessorDTOResponse> processors = new List <ProcessorDTOResponse>();
            Hashtable uniqueProcessors             = new Hashtable();
            int       totalDetectedCPUs            = 0;

            try
            {
                SelectQuery query = new SelectQuery(
                    @"select 
						Name, 
						Description, 
						DeviceID, 
						MaxClockSpeed, 
						Caption, 
						Manufacturer, 
						Version,
						DataWidth,
						SocketDesignation
					  from Win32_Processor"
                    );
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject obj in searcher.Get())
                {
                    totalDetectedCPUs++;

                    string socketDesignation = GetValueAsString(obj, "SocketDesignation");
                    if (uniqueProcessors.ContainsKey(socketDesignation))
                    {
                        continue;
                    }

                    ProcessorDTOResponse processor = new ProcessorDTOResponse();
                    if (vendor.IndexOf("xen") > -1 || vendor.IndexOf("vmware") > -1 || vendor.IndexOf("bochs") > -1)
                    {
                        processor.Label = "Virtual " + GetValueAsString(obj, "Name");
                    }
                    else
                    {
                        processor.Label = GetValueAsString(obj, "Name");
                    }
                    processor.Speed        = GetValueAsString(obj, "MaxClockSpeed");
                    processor.Index        = GetValueAsString(obj, "DeviceID");
                    processor.Description  = GetValueAsString(obj, "Description");
                    processor.Caption      = GetValueAsString(obj, "Caption");
                    processor.Manufacturer = GetValueAsString(obj, "Manufacturer");
                    processor.Version      = GetValueAsString(obj, "Version");
                    if (GetValueAsString(obj, "DataWidth") == "64")
                    {
                        processor.Is64Bit = "true";
                    }
                    else
                    {
                        processor.Is64Bit = "false";
                    }

                    uniqueProcessors.Add(socketDesignation, processor);
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            if (uniqueProcessors.Count > 0)
            {
                int coresCount = totalDetectedCPUs / uniqueProcessors.Count;
                foreach (ProcessorDTOResponse cpu in uniqueProcessors.Values)
                {
                    cpu.Cores = coresCount.ToString();
                    cpu.NumberOfLogicalProcessors = coresCount.ToString();

                    processors.Add(cpu);
                }
            }

            return(processors);
        }