Skip to content

Commit

Permalink
Alpha Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilyltt committed Sep 5, 2024
1 parent 9019ed2 commit e470761
Show file tree
Hide file tree
Showing 34 changed files with 1,734 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "Lagrange.Core"]
path = Lagrange.Core
url = git@github.com:LagrangeDev/Lagrange.Core.git
url = https://github.com/LagrangeDev/Lagrange.Core.git
2 changes: 1 addition & 1 deletion Lagrange.Core
Submodule Lagrange.Core updated 152 files
17 changes: 12 additions & 5 deletions Lagrange.Desktop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35122.118
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Desktop", "Lagrange.Desktop\Lagrange.Desktop.csproj", "{10EFD5D4-8617-4DE4-A809-06D104FFF32B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lagrange.Desktop", "Lagrange.Desktop\Lagrange.Desktop.csproj", "{10EFD5D4-8617-4DE4-A809-06D104FFF32B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lagrange.Core", "Lagrange.Core", "{25A7B6AD-C462-48CD-8428-7CC76B9A5F1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Core", "Lagrange.Core\Lagrange.Core\Lagrange.Core.csproj", "{54654AE2-25C4-430E-BF04-344D23926F07}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lagrange.Core", "Lagrange.Core\Lagrange.Core\Lagrange.Core.csproj", "{54654AE2-25C4-430E-BF04-344D23926F07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lagrange.OneBot", "Lagrange.Core\Lagrange.OneBot\Lagrange.OneBot.csproj", "{CFE7D22A-71E9-4444-B9C2-8157F91BFC79}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -23,14 +25,19 @@ Global
{54654AE2-25C4-430E-BF04-344D23926F07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54654AE2-25C4-430E-BF04-344D23926F07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54654AE2-25C4-430E-BF04-344D23926F07}.Release|Any CPU.Build.0 = Release|Any CPU
{CFE7D22A-71E9-4444-B9C2-8157F91BFC79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFE7D22A-71E9-4444-B9C2-8157F91BFC79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFE7D22A-71E9-4444-B9C2-8157F91BFC79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFE7D22A-71E9-4444-B9C2-8157F91BFC79}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3DC505B8-1135-4A79-A7C2-67F662B8DEC1}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{54654AE2-25C4-430E-BF04-344D23926F07} = {25A7B6AD-C462-48CD-8428-7CC76B9A5F1F}
{CFE7D22A-71E9-4444-B9C2-8157F91BFC79} = {25A7B6AD-C462-48CD-8428-7CC76B9A5F1F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3DC505B8-1135-4A79-A7C2-67F662B8DEC1}
EndGlobalSection
EndGlobal
20 changes: 13 additions & 7 deletions Lagrange.Desktop/App.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<Application x:Class="Lagrange.Desktop.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Lagrange.Desktop"
xmlns:pu="https://opensource.panuon.com/wpf-ui"
StartupUri="/View/MainWindow.xaml">
<Application
x:Class="Lagrange.Desktop.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Lagrange.Desktop"
xmlns:pu="https://opensource.panuon.com/wpf-ui"
StartupUri="/View/MainWindow.xaml">
<Application.Resources>
<pu:StyleDictionary Includes="All" />
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<pu:StyleDictionary Includes="All" />
<ResourceDictionary Source="Resources/SharedStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
5 changes: 4 additions & 1 deletion Lagrange.Desktop/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Configuration;
using Lagrange.Desktop.Model;
using System.Configuration;
using System.Data;
using System.Windows;
using Lagrange.Desktop.View;

namespace Lagrange.Desktop
{
Expand All @@ -9,6 +11,7 @@ namespace Lagrange.Desktop
/// </summary>
public partial class App : Application
{

}

}
File renamed without changes.
27 changes: 27 additions & 0 deletions Lagrange.Desktop/Converters/DoubleToSeverityColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Globalization;
using System.Windows.Data;

namespace Lagrange.Desktop;

public class DoubleToSeverityColorConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is double severity and not (< 0 or > 1) )
{
return severity switch
{
>= 0.9 => "#FF0033",
>= 0.6 => "#FFFF00",
>= 0.3 => "#99CCFF",
_ => "#20A53A"
};
}
throw new ArgumentException("Value must be a double more than 0 and less than 1!");
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
17 changes: 17 additions & 0 deletions Lagrange.Desktop/Converters/RunStateToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Globalization;
using System.Windows.Data;

namespace Lagrange.Desktop;

public class RunStateToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? "#FF00FF00" : "#FFFF0000";
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
17 changes: 17 additions & 0 deletions Lagrange.Desktop/Converters/RunStateToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Globalization;
using System.Windows.Data;

namespace Lagrange.Desktop;

public class RunStateToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? "Online" : "Offline";
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
8 changes: 8 additions & 0 deletions Lagrange.Desktop/Lagrange.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Resources\Logo.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\Logo.png" />
</ItemGroup>

<ItemGroup>
<Content Include="Resources\Logo.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Panuon.WPF.UI" Version="1.2.3.1" />
<PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -23,6 +30,7 @@

<ItemGroup>
<ProjectReference Include="..\Lagrange.Core\Lagrange.Core\Lagrange.Core.csproj" />
<ProjectReference Include="..\Lagrange.Core\Lagrange.OneBot\Lagrange.OneBot.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions Lagrange.Desktop/Lagrange.Desktop.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,37 @@
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Compile Update="View\ConfiguringUserControl.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\ConsoleUserControl.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\DashBoardUserControl.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\QrCodeWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="Resources\SharedStyles.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\ConfiguringUserControl.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\ConsoleUserControl.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\MainWindow.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\DashBoardUserControl.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\QrCodeWindow.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
123 changes: 123 additions & 0 deletions Lagrange.Desktop/Model/DeviceMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using Lagrange.Desktop.ViewModel;
using System.Diagnostics;
using System.Management;

namespace Lagrange.Desktop.Model;

public class DeviceMonitor
{
private CancellationTokenSource _monitorCancellationTokenSource = new();
public static DeviceMonitor Instance { get; } = new DeviceMonitor();
public string CpuModel { get; private set; }
public double RamTotalSize { get; private set; }
private DeviceMonitor()
{
CpuModel = GetCpuModel();
RamTotalSize = GetRamSize();
}

public async Task InitMonitor(DashBoardUserControlViewModel viewModel)
{
var monitor = DeviceMonitor.Instance;
var token = _monitorCancellationTokenSource.Token;

viewModel.CpuModel = monitor.CpuModel;

while (!token.IsCancellationRequested)
{
var data = monitor.GetData();

viewModel.CpuLoad = data[monitor.CpuCounter];
viewModel.RamModel = $"{data[monitor.RamCounter]:F0}/{monitor.RamTotalSize:F0} GB";
viewModel.RamLoad = data[monitor.RamCounter] / monitor.RamTotalSize;
viewModel.DiskLoad = data[monitor.DiskCounter];
viewModel.ProcessCpuLoad = data[monitor.ProcessCpuCounter];
viewModel.ProcessRamLoad = data[monitor.ProcessRamCounter];
await Task.Delay(2000, token);
}

monitor.Dispose();
}

//Percentage of CPU usage
public PerformanceCounter CpuCounter = new (
"Processor Information",
"% Processor Utility",
"_Total",
true
);

//Available memory(GB)
public PerformanceCounter RamCounter = new (
"Memory",
"Available MBytes",
true
);


//Percentage of disk time
public PerformanceCounter DiskCounter = new (
"PhysicalDisk",
"% Disk Time",
"_Total",
true
);

//Memory usage of the current process(MB)
public PerformanceCounter ProcessRamCounter = new (
"Process",
"Working Set",
Process.GetCurrentProcess().ProcessName
);

//CPU usage of the current process
public PerformanceCounter ProcessCpuCounter = new (
"Process",
"% Processor Time",
Process.GetCurrentProcess().ProcessName
);

public Dictionary<PerformanceCounter, double> GetData()
{
return new Dictionary<PerformanceCounter, double>
{
{ CpuCounter, CpuCounter.NextValue() / 100 },
{ RamCounter, RamCounter.NextValue() / 1024 },
{ DiskCounter, DiskCounter.NextValue() / 100 },
{ ProcessRamCounter, ProcessRamCounter.NextValue() / 1024 / 1024 },
{ ProcessCpuCounter, ProcessCpuCounter.NextValue() }
};
}

public string GetCpuModel()
{
var mos =
new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject mo in mos.Get())
{
var name = (mo["Name"]);
return name.ToString();
}
return "";
}

public double GetRamSize() {
var mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject mo in mos.Get())
{
var totalRam = Convert.ToInt64(mo["TotalPhysicalMemory"]);
return totalRam / 1024 / 1024 / 1024;
}
return 1;
}

public void Dispose()
{
CpuCounter.Dispose();
RamCounter.Dispose();
DiskCounter.Dispose();
ProcessRamCounter.Dispose();
ProcessCpuCounter.Dispose();
_monitorCancellationTokenSource.Cancel();
}
}
Loading

0 comments on commit e470761

Please sign in to comment.