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 5467758 commit 68663d7
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Manager/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static class Manager

public static int TitleLength => SHS.Clamp(SMMI.PortalSettingManager.GetSettingStable(SMC.TitleLength, 25), 10, 100);

public static string NetworkAdapter => SMMI.BackgroundogSettingManager.GetSetting(SMC.NetworkAdapter, string.Empty);

public static bool PerformanceCounter => SMMI.BackgroundogSettingManager.GetSetting(SMC.PerformanceCounter, true);

public static string LibrarySelected => SMMI.LibrarySettingManager.GetSetting(SMC.LibrarySelected, string.Empty);
Expand Down
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Memory/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public static class Constant

public const string DiscordRefresh = "DiscordRefresh";

public const string NetworkAdapter = "NetworkAdapter";

public const string StorePagination = "StorePagination";

public const string LibraryLocation = "LibraryLocation";
Expand Down
30 changes: 30 additions & 0 deletions src/Project/Sucrose.Backgroundog/Extension/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ public static JObject GetBatteryInfo()
};
}

public static JObject GetNetworkInfo()
{
return new JObject
{
{ "Name", SBMI.NetworkData.Name },
{ "Upload", SBMI.NetworkData.Upload },
{ "Download", SBMI.NetworkData.Download },
{ "FormatUploadData", SBMI.NetworkData.FormatUploadData },
{ "FormatDownloadData", SBMI.NetworkData.FormatDownloadData },
{
"UploadData", new JObject
{
{ "Text", SBMI.NetworkData.UploadData.Text },
{ "Value", SBMI.NetworkData.UploadData.Value },
{ "Type", SBMI.NetworkData.UploadData.Type.ToString() },
{ "Short", SBMI.NetworkData.UploadData.Short.ToString() },
}
},
{
"DownloadData", new JObject
{
{ "Text", SBMI.NetworkData.DownloadData.Text },
{ "Value", SBMI.NetworkData.DownloadData.Value },
{ "Type", SBMI.NetworkData.DownloadData.Type.ToString() },
{ "Short", SBMI.NetworkData.DownloadData.Short.ToString() },
}
},
};
}

public static JObject GetMotherboardInfo()
{
return new JObject
Expand Down
44 changes: 39 additions & 5 deletions src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using LibreHardwareMonitor.Hardware;
using Newtonsoft.Json;
using Skylark.Enum;
using Skylark.Helper;
using Skylark.Standard.Extension.Storage;
using Sucrose.Backgroundog.Extension;
using System.Management;
using SBMI = Sucrose.Backgroundog.Manage.Internal;
using SMMM = Sucrose.Manager.Manage.Manager;
using SSSHN = Sucrose.Shared.Space.Helper.Network;

namespace Sucrose.Backgroundog.Helper
{
Expand Down Expand Up @@ -159,11 +164,40 @@ public static async Task Start()
}
}

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));
_ = Task.Run(() =>
{
foreach (string Name in SSSHN.InstanceNetworkInterfaces())
{
if (SMMM.NetworkAdapter == Name)
{
if (SMMM.NetworkAdapter != SBMI.NetworkData.Name)
{
SBMI.NetworkData.Name = SMMM.NetworkAdapter;

SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name);
SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name);
}

SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue();
SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue();

SBMI.NetworkData.UploadData = StorageExtension.AutoConvert(SBMI.NetworkData.Upload, StorageType.Byte, ModeStorageType.Palila);
SBMI.NetworkData.DownloadData = StorageExtension.AutoConvert(SBMI.NetworkData.Download, StorageType.Byte, ModeStorageType.Palila);

SBMI.NetworkData.FormatUploadData = Numeric.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.UploadData.Text;
SBMI.NetworkData.FormatDownloadData = Numeric.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.DownloadData.Text;

break;
}
}
});

//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.GetNetworkInfo(), Formatting.Indented));
//Console.WriteLine(JsonConvert.SerializeObject(Data.GetMotherboardInfo(), Formatting.Indented));

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

namespace Sucrose.Backgroundog.Manage
Expand All @@ -21,6 +23,10 @@ internal static class Internal

public static Timer InitializeTimer = null;

public static PerformanceCounter UploadCounter = null;

public static PerformanceCounter DownloadCounter = null;

public static SBSDCS CpuData = new()
{
Min = 0f,
Expand All @@ -45,15 +51,15 @@ internal static class Internal

public static Computer Computer = new()
{
IsCpuEnabled = true,
IsGpuEnabled = false,
IsCpuEnabled = false,
IsGpuEnabled = true,
IsPsuEnabled = false,
IsMemoryEnabled = true,
IsMemoryEnabled = false,
IsNetworkEnabled = false,
IsStorageEnabled = false,
IsBatteryEnabled = true,
IsBatteryEnabled = false,
IsControllerEnabled = false,
IsMotherboardEnabled = true,
IsMotherboardEnabled = false,
};

public static SBSDBS BatteryData = new()
Expand All @@ -75,6 +81,17 @@ internal static class Internal
RemainingTimeEstimated = 0f
};

public static SBSDNS NetworkData = new()
{
Upload = 0f,
Download = 0f,
UploadData = new(),
Name = string.Empty,
DownloadData = new(),
FormatUploadData = string.Empty,
FormatDownloadData = string.Empty
};

public static SBSDMDS MotherboardData = new()
{
Name = string.Empty
Expand Down
37 changes: 37 additions & 0 deletions src/Project/Sucrose.Backgroundog/Struct/Data.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using SSSSS = Skylark.Struct.Storage.StorageStruct;

namespace Sucrose.Backgroundog.Struct.Data
{
Expand Down Expand Up @@ -142,6 +143,42 @@ public struct BatteryStruct
public float? RemainingTimeEstimated;
}

/// <summary>
///
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct NetworkStruct
{
/// <summary>
///
/// </summary>
public string Name;
/// <summary>
///
/// </summary>
public float Upload;
/// <summary>
///
/// </summary>
public float Download;
/// <summary>
///
/// </summary>
public SSSSS UploadData;
/// <summary>
///
/// </summary>
public SSSSS DownloadData;
/// <summary>
///
/// </summary>
public string FormatUploadData;
/// <summary>
///
/// </summary>
public string FormatDownloadData;
}

/// <summary>
///
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Shared/Sucrose.Shared.Space/Helper/Network.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using SMR = Sucrose.Memory.Readonly;

Expand All @@ -25,6 +26,13 @@ public static bool IsInternetAvailable()
return NetworkInterface.GetIsNetworkAvailable();
}

public static string[] InstanceNetworkInterfaces()
{
PerformanceCounterCategory Category = new("Network Interface");

return Category.GetInstanceNames();
}

public static NetworkInterface[] AllNetworkInterfaces()
{
return NetworkInterface.GetAllNetworkInterfaces();
Expand Down

0 comments on commit 68663d7

Please sign in to comment.