Skip to content

Commit

Permalink
Preparing Backgroundog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 18, 2023
1 parent 441b8ba commit 5467758
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 12 deletions.
29 changes: 28 additions & 1 deletion src/Project/Sucrose.Backgroundog/Extension/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,26 @@ public static JObject GetCpuInfo()
{ "Min", SBMI.CpuData.Min },
{ "Now", SBMI.CpuData.Now },
{ "Max", SBMI.CpuData.Max },
{ "Name", SBMI.CpuData.Name }
{ "Name", SBMI.CpuData.Name },
{ "Core", SBMI.CpuData.Core },
{ "Thread", SBMI.CpuData.Thread },
{ "Fullname", SBMI.CpuData.Fullname }
};
}

public static JObject GetDateInfo()
{
DateTime Date = DateTime.Now;

return new JObject
{
{ "Year", Date.Year },
{ "Month", Date.Month },
{ "Day", Date.Day },
{ "Hour", Date.Hour },
{ "Minute", Date.Minute },
{ "Second", Date.Second },
{ "Millisecond", Date.Millisecond }
};
}

Expand Down Expand Up @@ -51,5 +70,13 @@ public static JObject GetBatteryInfo()
{ "RemainingTimeEstimated", SBMI.BatteryData.RemainingTimeEstimated }
};
}

public static JObject GetMotherboardInfo()
{
return new JObject
{
{ "Name", SBMI.MotherboardData.Name }
};
}
}
}
42 changes: 38 additions & 4 deletions src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using LibreHardwareMonitor.Hardware;
using Newtonsoft.Json;
using Sucrose.Backgroundog.Extension;
using System.Management;
using SBMI = Sucrose.Backgroundog.Manage.Internal;

namespace Sucrose.Backgroundog.Helper
Expand Down Expand Up @@ -30,10 +32,31 @@ public static async Task Start()
Min = Sensor.Min,
Max = Sensor.Max,
Now = Sensor.Value,
Name = Hardware.Name
Name = Hardware.Name,
Core = SBMI.CpuData.Core,
Thread = SBMI.CpuData.Thread,
Fullname = SBMI.CpuData.Fullname
};
}
}

if (SBMI.CpuManagement)
{
SBMI.CpuManagement = false;

_ = Task.Run(() =>
{
ManagementObjectSearcher Searcher = new("SELECT * FROM Win32_Processor");

foreach (ManagementObject Object in Searcher.Get().Cast<ManagementObject>())
{
SBMI.CpuData.Core = Convert.ToInt32(Object["NumberOfCores"]);
SBMI.CpuData.Fullname = Object["Name"].ToString().TrimStart().TrimEnd();
SBMI.CpuData.Thread = Convert.ToInt32(Object["NumberOfLogicalProcessors"]);
break;
}
});
}
}
else if (Hardware.HardwareType == HardwareType.Memory)
{
Expand Down Expand Up @@ -125,11 +148,22 @@ public static async Task Start()
}
}
}
else if (Hardware.HardwareType == HardwareType.Motherboard)
{
Hardware.Update();

SBMI.MotherboardData = new()
{
Name = Hardware.Name
};
}
}

Console.WriteLine(JsonConvert.SerializeObject(SBMI.CpuData, Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(SBMI.MemoryData, Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(SBMI.BatteryData, Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(Data.GetCpuInfo(), Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(Data.GetDateInfo(), Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(Data.GetMemoryInfo(), Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(Data.GetBatteryInfo(), Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(Data.GetMotherboardInfo(), Formatting.Indented));

//foreach (IHardware Hardware in SBMI.Computer.Hardware)
//{
Expand Down
19 changes: 15 additions & 4 deletions src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using LibreHardwareMonitor.Hardware;
using SBSDBS = Sucrose.Backgroundog.Struct.Data.BatteryStruct;
using SBSDCS = Sucrose.Backgroundog.Struct.Data.CpuStruct;
using SBSDMS = Sucrose.Backgroundog.Struct.Data.MemoryStruct;
using SBSDMDS = Sucrose.Backgroundog.Struct.Data.MotherboardStruct;
using SBSDMYS = Sucrose.Backgroundog.Struct.Data.MemoryStruct;
using Timer = System.Threading.Timer;

namespace Sucrose.Backgroundog.Manage
Expand All @@ -16,17 +17,22 @@ internal static class Internal

public static bool Processing = true;

public static bool CpuManagement = true;

public static Timer InitializeTimer = null;

public static SBSDCS CpuData = new()
{
Min = 0f,
Now = 0f,
Max = 0f,
Name = string.Empty
Core = 0,
Thread = 0,
Name = string.Empty,
Fullname = string.Empty
};

public static SBSDMS MemoryData = new()
public static SBSDMYS MemoryData = new()
{
MemoryUsed = 0f,
MemoryLoad = 0f,
Expand All @@ -47,7 +53,7 @@ internal static class Internal
IsStorageEnabled = false,
IsBatteryEnabled = true,
IsControllerEnabled = false,
IsMotherboardEnabled = false,
IsMotherboardEnabled = true,
};

public static SBSDBS BatteryData = new()
Expand All @@ -68,5 +74,10 @@ internal static class Internal
ChargeDischargeCurrent = 0f,
RemainingTimeEstimated = 0f
};

public static SBSDMDS MotherboardData = new()
{
Name = string.Empty
};
}
}
30 changes: 27 additions & 3 deletions src/Project/Sucrose.Backgroundog/Struct/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace Sucrose.Backgroundog.Struct.Data
[StructLayout(LayoutKind.Sequential)]
public struct CpuStruct
{
/// <summary>
///
/// </summary>
public int? Core;
/// <summary>
///
/// </summary>
Expand All @@ -23,7 +27,15 @@ public struct CpuStruct
/// <summary>
///
/// </summary>
public string? Name;
public int? Thread;
/// <summary>
///
/// </summary>
public string Name;
/// <summary>
///
/// </summary>
public string Fullname;
}

/// <summary>
Expand All @@ -35,7 +47,7 @@ public struct MemoryStruct
/// <summary>
///
/// </summary>
public string? Name;
public string Name;
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -71,7 +83,7 @@ public struct BatteryStruct
/// <summary>
///
/// </summary>
public string? Name;
public string Name;
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -129,4 +141,16 @@ public struct BatteryStruct
/// </summary>
public float? RemainingTimeEstimated;
}

/// <summary>
///
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct MotherboardStruct
{
/// <summary>
///
/// </summary>
public string Name;
}
}

0 comments on commit 5467758

Please sign in to comment.