コード例 #1
0
ファイル: OSInfoTo.cs プロジェクト: nowanys/netnrf
        /// <summary>
        /// 构造
        /// </summary>
        public OSInfoTo()
        {
            // 因为 TickCount 属性值的值是32位有符号整数,所以如果系统连续运行,TickCount 将从零递增到 Int32.MaxValue 约24.9 天,
            // 然后跳转到 Int32.MinValue (这是一个负数,然后再递增为零)在接下来的24.9 天内。
            if (Environment.TickCount > 0)
            {
                TickCount = Environment.TickCount;
            }
            else
            {
                TickCount = long.Parse(int.MaxValue.ToString()) + Math.Abs(Environment.TickCount - int.MinValue);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                OS = OSPlatform.Windows.ToString();

                TotalPhysicalMemory = PlatformForWindows.TotalPhysicalMemory();
                FreePhysicalMemory  = PlatformForWindows.FreePhysicalMemory();

                LogicalDisk = PlatformForWindows.LogicalDisk();

                ProcessorName = PlatformForWindows.ProcessorName();
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                OS = OSPlatform.Linux.ToString();

                TotalPhysicalMemory = PlatformForLinux.MemInfo("MemTotal:");
                FreePhysicalMemory  = PlatformForLinux.MemInfo("MemAvailable:");

                SwapFree  = PlatformForLinux.MemInfo("SwapFree:");
                SwapTotal = PlatformForLinux.MemInfo("SwapTotal:");

                LogicalDisk = PlatformForLinux.LogicalDisk();

                ProcessorName = PlatformForLinux.CpuInfo("model name");
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                OS = OSPlatform.OSX.ToString();

                TotalPhysicalMemory = PlatformForLinux.MemInfo("MemTotal:");
                FreePhysicalMemory  = PlatformForLinux.MemInfo("MemAvailable:");

                LogicalDisk = PlatformForLinux.LogicalDisk();

                ProcessorName = PlatformForLinux.CpuInfo("model name");
            }
        }
コード例 #2
0
        /// <summary>
        /// 构造
        /// </summary>
        public OSInfoTo()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                OS = OSPlatform.Windows.ToString();

                TotalPhysicalMemory = PlatformForWindows.TotalPhysicalMemory();
                FreePhysicalMemory  = PlatformForWindows.FreePhysicalMemory();

                LogicalDisk = PlatformForWindows.LogicalDisk();

                ProcessorName = PlatformForWindows.ProcessorName();

                TickCount = PlatformForWindows.RunTime();

                Model = PlatformForWindows.Model();

                OperatingSystem = PlatformForWindows.OperatingSystem();
            }
            else
            {
                TotalPhysicalMemory = PlatformForLinux.MemInfo("MemTotal:");
                FreePhysicalMemory  = PlatformForLinux.MemInfo("MemAvailable:");

                SwapFree  = PlatformForLinux.MemInfo("SwapFree:");
                SwapTotal = PlatformForLinux.MemInfo("SwapTotal:");

                LogicalDisk = PlatformForLinux.LogicalDisk();

                ProcessorName = PlatformForLinux.CpuInfo("model name");

                TickCount = PlatformForLinux.RunTime();

                Model = PlatformForLinux.Model();

                OperatingSystem = PlatformForLinux.OperatingSystem();

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    OS = OSPlatform.Linux.ToString();
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    OS = OSPlatform.OSX.ToString();
                }
            }
        }