mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
feat: Implementing ProcessorUtils for NetStandard
This commit is contained in:
@@ -41,8 +41,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Data.SQLite" Version="5.0.2" />
|
<PackageReference Include="Microsoft.Data.SQLite" Version="5.0.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="Pastel" Version="2.1.0" />
|
<PackageReference Include="Pastel" Version="2.1.0" />
|
||||||
|
<PackageReference Include="System.Management" Version="5.0.0" />
|
||||||
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
|
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
|
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#if !SIMPLSHARP
|
#if !SIMPLSHARP
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Management;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.IO;
|
using ICD.Common.Utils.IO;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
@@ -16,7 +19,21 @@ namespace ICD.Common.Utils
|
|||||||
/// Gets the model name of the processor.
|
/// Gets the model name of the processor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string ModelName { get { return Environment.MachineName; } }
|
public static string ModelName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string productName = RegistryLocalMachineGetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName");
|
||||||
|
if (productName == string.Empty)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
string csdVersion = RegistryLocalMachineGetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CSDVersion");
|
||||||
|
|
||||||
|
return (productName.StartsWith("Microsoft") ? string.Empty : "Microsoft ") +
|
||||||
|
productName +
|
||||||
|
(csdVersion == string.Empty ? string.Empty : " " + csdVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the processor firmware version.
|
/// Gets the processor firmware version.
|
||||||
@@ -26,8 +43,7 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO
|
return RegistryLocalMachineGetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +55,8 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO
|
long time = RegistryLocalMachineGetLong(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallTime");
|
||||||
return DateTime.MinValue;
|
return time == 0 ? DateTime.MinValue : DateTime.FromFileTime(132448642489109028).ToUniversalTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +68,8 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO
|
ManagementObject os = new ManagementObject("Win32_OperatingSystem=@");
|
||||||
return null;
|
return (string)os["SerialNumber"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +80,22 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO
|
ManagementObjectSearcher wmiObject = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
|
||||||
return 0.0f;
|
|
||||||
|
var memoryValues =
|
||||||
|
wmiObject.Get()
|
||||||
|
.Cast<ManagementObject>()
|
||||||
|
.Select(mo => new
|
||||||
|
{
|
||||||
|
FreePhysicalMemory = double.Parse(mo["FreePhysicalMemory"].ToString()),
|
||||||
|
TotalVisibleMemorySize = double.Parse(mo["TotalVisibleMemorySize"].ToString())
|
||||||
|
})
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
return memoryValues == null
|
||||||
|
? 0
|
||||||
|
: (float)((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) /
|
||||||
|
memoryValues.TotalVisibleMemorySize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,10 +190,7 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static DateTime? GetSystemStartTime()
|
public static DateTime? GetSystemStartTime()
|
||||||
{
|
{
|
||||||
if (s_SystemStartTime == null)
|
return s_SystemStartTime ?? (s_SystemStartTime = Process.GetCurrentProcess().StartTime.ToUniversalTime());
|
||||||
s_SystemStartTime = IcdEnvironment.GetUtcTime() - TimeSpan.FromMilliseconds(Environment.TickCount);
|
|
||||||
|
|
||||||
return s_SystemStartTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -178,6 +205,36 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private static string RegistryLocalMachineGetString(string path, string key)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RegistryKey rk = Registry.LocalMachine.OpenSubKey(path);
|
||||||
|
return rk == null ? string.Empty : (string)rk.GetValue(key);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long RegistryLocalMachineGetLong(string path, string key)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RegistryKey rk = Registry.LocalMachine.OpenSubKey(path);
|
||||||
|
return rk == null ? 0 : (long)rk.GetValue(key);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user