-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
184 lines (163 loc) · 5.9 KB
/
Program.cs
File metadata and controls
184 lines (163 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Diagnostics;
using System.Management;
using SentinelSyncV1;
using System.Threading.Tasks;
using System.Threading.Channels;
using Microsoft.Win32;
using System.Management;
using System.Runtime.InteropServices;
using System.Management;
namespace SentinelSyncV1
{
class Program
{
static string RefreshCpuInfos()
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
dynamic firstVal = cpuCounter.NextValue();
System.Threading.Thread.Sleep(100);
dynamic val = cpuCounter.NextValue();
decimal roundVal = Convert.ToDecimal(val);
roundVal = Math.Round(roundVal, 2);
return roundVal + " %";
}
static void RefreshRamInfos()
{
Console.WriteLine("available : " + SentinelSyncV1.SystemInfo.FormatSize(SentinelSyncV1.SystemInfo.GetAvailPhys()));
Console.WriteLine("used : " + SentinelSyncV1.SystemInfo.FormatSize(SentinelSyncV1.SystemInfo.GetUsedPhys()));
Console.WriteLine("total : " + SentinelSyncV1.SystemInfo.FormatSize(SentinelSyncV1.SystemInfo.GetTotalPhys()));
}
/*
static string getRamCounter()
{
PerformanceCounter ramCounter = new PerformanceCounter();
ramCounter.CategoryName = "Memory";
ramCounter.CounterName = "Available MBytes";
dynamic firstValue = ramCounter.NextValue();
System.Threading.Thread.Sleep(100);
dynamic val = ramCounter.NextValue();
decimal roundVar = Convert.ToDecimal(val);
roundVar = Math.Round(roundVar, 2);
return roundVar.ToString();
}
*/
static void RefreshTempInfos()
{
try
{
double temperature = 0;
string instanceName = "";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\cimv2", "SELECT * FROM MSAcpi_ThermalZoneTemperature");
foreach (ManagementObject obj in searcher.Get())
{
temperature = Convert.ToDouble(obj["CurrentTemperature"].ToString());
temperature = (temperature - 2732) / 10.0;
instanceName = obj["InstanceName"].ToString();
}
Console.WriteLine(temperature + "°C");
}
catch (ManagementException e)
{
Console.WriteLine($"Error: {e.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
}
static void GetAllSystemInfos()
{
var si = new SystemInfo();
Console.WriteLine(si.GetCpuInfos());
Console.WriteLine(si.GetOsInfos("os"));
Console.WriteLine(si.GetOsInfos("arch"));
Console.WriteLine(si.GetOsInfos("osv"));
si.GetGpuInfos();
}
static void ShowCpuUse()
{
while (true)
{
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
{
return;
}
Console.WriteLine("(ENTER to stop) processor utilisation : " + RefreshCpuInfos());
}
}
static void ShowRamUse()
{
while (true)
{
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
{
return;
}
Console.WriteLine("(ENTER to stop) RAM utilisation : ");
RefreshRamInfos();
System.Threading.Thread.Sleep(500);
}
}
static void ShowTemp()
{
while (true)
{
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
{
return;
}
Console.WriteLine("(ENTER to stop) Temperature : ");
RefreshTempInfos();
System.Threading.Thread.Sleep(500);
}
}
static void ShowNet()
{
var sysInfo = new SystemInfo();
while (true)
{
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
{
return;
}
Console.Write("(ENTER to stop) ");
sysInfo.RefreshNetworkInfos();
System.Threading.Thread.Sleep(500);
}
}
static void Main(string[] args)
{
GetAllSystemInfos();
int choice = 0;
var sysInfo = new SystemInfo();
Console.WriteLine("1 - show processor utilisation");
Console.WriteLine("2 - show RAM");
Console.WriteLine("3 - show PC temperature");
Console.WriteLine("4 - show stockage infos");
Console.WriteLine("5 - network infos");
choice = outils.AskNumberBetween("enter a choice : ", 1, 5);
switch (choice)
{
case 1:
ShowCpuUse();
break;
case 2:
ShowRamUse();
break;
case 3:
ShowTemp();
break;
case 4:
sysInfo.GetDrivesInfos();
break;
case 5:
ShowNet();
break;
}
}
}
}