-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,734 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Submodule Lagrange.Core
updated
152 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
Lagrange.Desktop/Converters/DoubleToSeverityColorConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.