using System.Management;
using System.Text;

namespace MECF.Framework.Common.Utilities
{
    public class SystemInfoHelper
    {
        private static string DeviceInformation(string stringIn)
        {
            var stringBuilder1 = new StringBuilder(string.Empty);
            var managementClass1 = new ManagementClass(stringIn);
            //Create a ManagementObjectCollection to loop through
            var managemenobjCol = managementClass1.GetInstances();
            //Get the properties in the class
            var properties = managementClass1.Properties;
            foreach (var obj in managemenobjCol)
            {
                foreach (var property in properties)
                {
                    try
                    {
                        stringBuilder1.AppendLine(property.Name + ":  " + obj.Properties[property.Name].Value);
                    }
                    catch
                    {
                        //Add codes to manage more information
                    }
                }
                stringBuilder1.AppendLine();
            }
            return stringBuilder1.ToString();
        }

        /// <summary>
        /// 获取操作系统信息。
        /// </summary>
        /// <returns></returns>
        public static string GetComputerSystem()
        {
            return DeviceInformation("Win32_ComputerSystem");
        }

        /// <summary>
        /// 获取CPU信息。
        /// </summary>
        /// <returns></returns>
        public static string GetCpuInfo()
        {
            return DeviceInformation("Win32_Processor");
        }
        
        /// <summary>
        /// 获取磁盘信息。
        /// </summary>
        /// <returns></returns>
        public static string GetLogicalDiskInfo()
        {
            return DeviceInformation("Win32_LogicalDisk");
        }

    }
}
