Skip to content

Commit b3df2b8

Browse files
committed
[#5] : disk configuration
1 parent f877120 commit b3df2b8

14 files changed

+162
-40
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# MachineMonitor
1+
# Machine Monitor
22
[![Build status](https://monbsoft.visualstudio.com/MachineMonitor/_apis/build/status/MachineMonitor-CI)](https://monbsoft.visualstudio.com/MachineMonitor/_build/latest?definitionId=5)
33

44
Machine Monitor is a system monitor to display resources and performances of your machine (CPU, Memory and GPU).
55

6+
![alt text](doc/capture.jpg "Machine Monitor")
67

78
## Credits
89
* [windows-toolkit/WindowsCommunityToolkit](https://github.com/windows-toolkit/WindowsCommunityToolkit), The Windows Community Toolkit is a collection of helper functions, custom controls, and app services.

doc/capture.png

9.8 KB
Loading

src/MachineMonitor/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<setting name="Transparent" serializeAs="String">
2626
<value>False</value>
2727
</setting>
28+
<setting name="Disk" serializeAs="String">
29+
<value>_Total</value>
30+
</setting>
2831
</Monbsoft.MachineMonitor.Properties.Settings>
2932
<Monbsoft.MachineMonitor.Settings>
3033
<setting name="Network" serializeAs="String">

src/MachineMonitor/Configuration/ConfigurationStore.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
using Monbsoft.MachineMonitor.Properties;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace Monbsoft.MachineMonitor.Configuration
94
{
105
public class ConfigurationStore
116
{
7+
public string Disk
8+
{
9+
get
10+
{
11+
return Settings.Default.Disk;
12+
}
13+
set
14+
{
15+
Settings.Default.Disk = value;
16+
Save();
17+
}
18+
}
19+
1220
public string Network
1321
{
1422
get
@@ -40,4 +48,4 @@ private void Save()
4048
Settings.Default.Save();
4149
}
4250
}
43-
}
51+
}

src/MachineMonitor/MachineMonitor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
</ApplicationDefinition>
7373
<Compile Include="Configuration\ConfigurationStore.cs" />
7474
<Compile Include="Messages\UpdatedConfigurationMessage.cs" />
75+
<Compile Include="Services\DiskService.cs" />
7576
<Compile Include="Services\NetworkService.cs" />
7677
<Compile Include="Properties\Settings.Designer.cs">
7778
<AutoGen>True</AutoGen>

src/MachineMonitor/Messages/UpdatedConfigurationMessage.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public UpdatedConfigurationMessage(ChangedType type)
1313

1414
public enum ChangedType
1515
{
16-
Network,
17-
Transparent
16+
Disk = 0,
17+
Network = 1,
18+
Transparent = 2
1819
}
1920

2021
public ChangedType Changed { get; set; }

src/MachineMonitor/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MachineMonitor/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
<Setting Name="Transparent" Type="System.Boolean" Scope="User">
99
<Value Profile="(Default)">False</Value>
1010
</Setting>
11+
<Setting Name="Disk" Type="System.String" Scope="User">
12+
<Value Profile="(Default)">_Total</Value>
13+
</Setting>
1114
</Settings>
1215
</SettingsFile>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Monbsoft.MachineMonitor.Services
9+
{
10+
public class DiskService
11+
{
12+
public List<string> GetDisks()
13+
{
14+
var category = new PerformanceCounterCategory("PhysicalDisk");
15+
return category.GetInstanceNames().OrderBy(i => i).ToList();
16+
}
17+
}
18+
}

src/MachineMonitor/ViewModels/ConfigurationViewModel.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,60 @@ public class ConfigurationViewModel : ViewModelBase
1313
{
1414
#region Champs
1515
private readonly ConfigurationStore _configuration;
16-
private readonly NetworkService _networkService;
16+
private string _disk;
1717
private string _network;
1818
private bool _transparent;
1919
#endregion
2020

2121
#region Constructeurs
22-
public ConfigurationViewModel(ConfigurationStore configuration, NetworkService networkService)
22+
public ConfigurationViewModel(
23+
ConfigurationStore configuration,
24+
NetworkService networkService,
25+
DiskService diskService)
2326
{
2427
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
25-
_networkService = networkService ?? throw new ArgumentNullException(nameof(networkService));
26-
Networks = _networkService.GetNetworks();
28+
if (networkService == null)
29+
{
30+
throw new ArgumentNullException(nameof(networkService));
31+
}
32+
if (diskService == null)
33+
{
34+
throw new ArgumentNullException(nameof(diskService));
35+
}
36+
37+
Networks = networkService.GetNetworks();
38+
Disks = diskService.GetDisks();
39+
_disk = _configuration.Disk;
2740
_network = _configuration.Network;
2841
_transparent = _configuration.Transparent;
2942
}
3043
#endregion
3144

3245
#region Propriétés
46+
public List<string> Disks
47+
{
48+
get;
49+
private set;
50+
}
3351
public List<string> Networks
3452
{
3553
get;
3654
private set;
3755
}
56+
57+
public string SelectedDisk
58+
{
59+
get
60+
{
61+
return _disk;
62+
}
63+
set
64+
{
65+
Set(ref _disk, value);
66+
Disk_Changed();
67+
}
68+
}
69+
3870
public string SelectedNetwork
3971
{
4072
get { return _network; }
@@ -62,7 +94,11 @@ public bool Transparent
6294
private static void SendMessage(ChangedType type)
6395
{
6496
Messenger.Default.Send<UpdatedConfigurationMessage>(new UpdatedConfigurationMessage(type));
65-
97+
}
98+
private void Disk_Changed()
99+
{
100+
_configuration.Disk = SelectedDisk;
101+
SendMessage(ChangedType.Disk);
66102
}
67103
private void Network_Changed()
68104
{
@@ -77,4 +113,4 @@ private void Transparent_Changed()
77113
}
78114
#endregion
79115
}
80-
}
116+
}

src/MachineMonitor/ViewModels/MainViewModel.cs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using Monbsoft.MachineMonitor.Configuration;
44
using Monbsoft.MachineMonitor.Messages;
55
using Monbsoft.MachineMonitor.Views;
6+
using System;
67
using System.Diagnostics;
8+
using System.Windows.Threading;
79
using static Monbsoft.MachineMonitor.Messages.UpdatedConfigurationMessage;
810

911
namespace Monbsoft.MachineMonitor.ViewModels
@@ -13,11 +15,12 @@ public class MainViewModel : ViewModelBase
1315
#region Champs
1416
private readonly ConfigurationStore _configuration;
1517
private readonly PerformanceCounter _cpuCounter;
16-
private readonly PerformanceCounter _diskCounter;
1718
private readonly PerformanceCounter _memoryCounter;
1819
private readonly PerformanceCounter _networkCounter;
20+
private readonly DispatcherTimer _timer;
1921
private double _cpu;
2022
private double _disk;
23+
private PerformanceCounter _diskCounter;
2124
private double _network;
2225
private double _networkMax;
2326
private double _ram;
@@ -30,18 +33,23 @@ public class MainViewModel : ViewModelBase
3033
/// </summary>
3134
public MainViewModel(ConfigurationStore configuration)
3235
{
36+
_configuration = configuration;
3337
_cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
3438
_memoryCounter = new PerformanceCounter("Memory", "% Committed Bytes In Use");
35-
_diskCounter = new PerformanceCounter("PhysicalDisk", "% Disk Read Time", "_Total");
3639

3740
if (configuration != null && !string.IsNullOrEmpty(configuration.Network))
3841
{
3942
_networkCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", configuration.Network);
4043
}
41-
_configuration = configuration;
44+
45+
_timer = new DispatcherTimer();
46+
_timer.Interval = TimeSpan.FromMilliseconds(500);
47+
_timer.Tick += Timer_Tick;
4248

4349
// messages
4450
Messenger.Default.Register<UpdatedConfigurationMessage>(this, HandleUpdatedConfiguration);
51+
52+
OnDiskChange();
4553
}
4654
#endregion
4755

@@ -90,14 +98,10 @@ public void Initialize(MainWindow view)
9098
_view = view;
9199
OnTransparencyChange(_configuration.Transparent);
92100
}
93-
public void Refresh()
101+
public void Start()
94102
{
95-
Cpu = _cpuCounter.NextValue();
96-
Ram = _memoryCounter.NextValue();
97-
Disk = _diskCounter.NextValue();
98-
Network = GetPercentageNetwork();
103+
_timer.Start();
99104
}
100-
101105
private double GetPercentageNetwork()
102106
{
103107
if (_networkCounter == null)
@@ -113,10 +117,31 @@ private double GetPercentageNetwork()
113117
}
114118
private void HandleUpdatedConfiguration(UpdatedConfigurationMessage updatedMessage)
115119
{
116-
if (updatedMessage.Changed == ChangedType.Transparent)
120+
_timer.Stop();
121+
switch(updatedMessage.Changed)
117122
{
118-
OnTransparencyChange(_configuration.Transparent);
123+
case ChangedType.Disk:
124+
{
125+
OnDiskChange();
126+
break;
127+
}
128+
case ChangedType.Transparent:
129+
{
130+
OnTransparencyChange(_configuration.Transparent);
131+
break;
132+
}
133+
134+
default:
135+
{
136+
break;
137+
}
119138
}
139+
_timer.Start();
140+
141+
}
142+
private void OnDiskChange()
143+
{
144+
_diskCounter = new PerformanceCounter("PhysicalDisk", "% Disk Time",_configuration.Disk);
120145
}
121146
private void OnTransparencyChange(bool transparent)
122147
{
@@ -129,6 +154,13 @@ private void OnTransparencyChange(bool transparent)
129154
_view.DeactiveTransparency();
130155
}
131156
}
157+
private void Timer_Tick(object sender, EventArgs e)
158+
{
159+
Cpu = _cpuCounter.NextValue();
160+
Ram = _memoryCounter.NextValue();
161+
Disk = _diskCounter.NextValue();
162+
Network = GetPercentageNetwork();
163+
}
132164
#endregion
133165
}
134166
}

src/MachineMonitor/ViewModels/ViewModelLocator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public ViewModelLocator()
3939
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
4040
SimpleIoc.Default.Register<ConfigurationStore>();
4141
SimpleIoc.Default.Register<NetworkService>();
42+
SimpleIoc.Default.Register<DiskService>();
4243
SimpleIoc.Default.Register<MainViewModel>();
4344
SimpleIoc.Default.Register<ConfigurationViewModel>();
4445
}

src/MachineMonitor/Views/ConfigurationWindow.xaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
mc:Ignorable="d"
77
Title="Configuration"
88
Background="{StaticResource SystemControlBackgroundBrush}"
9-
WindowStartupLocation="CenterScreen" Width="400" Height="200">
9+
Height="200"
10+
ShowInTaskbar="False"
11+
Width="400"
12+
WindowStartupLocation="CenterScreen">
1013
<Grid Margin="5,0">
1114
<Grid.ColumnDefinitions>
1215
<ColumnDefinition Width="120"/>
@@ -17,30 +20,41 @@
1720
<RowDefinition Height="Auto"/>
1821
<RowDefinition Height="Auto"/>
1922
<RowDefinition Height="Auto"/>
23+
<RowDefinition Height="Auto"/>
24+
<RowDefinition Height="Auto"/>
2025
<RowDefinition/>
2126
<RowDefinition Height="Auto"/>
2227
</Grid.RowDefinitions>
2328
<TextBlock Style="{StaticResource TextBlockStyle}"
24-
Text="Réseau:"/>
29+
Text="Disque:"/>
2530
<ComboBox Grid.Column="1"
2631
Grid.Row="1"
2732
HorizontalAlignment="Left"
33+
ItemsSource="{Binding Disks}"
34+
SelectedItem="{Binding SelectedDisk}"
35+
Width="150"/>
36+
<TextBlock Grid.Row="2"
37+
Style="{StaticResource TextBlockStyle}"
38+
Text="Réseau:"/>
39+
<ComboBox Grid.Column="1"
40+
Grid.Row="3"
41+
HorizontalAlignment="Left"
2842
ItemsSource="{Binding Networks}"
2943
SelectedItem="{Binding SelectedNetwork}"
3044
Width="150">
3145
</ComboBox>
32-
<TextBlock Grid.Row="2"
46+
<TextBlock Grid.Row="4"
3347
Style="{StaticResource TextBlockStyle}"
3448
Text="Transparence:"/>
3549
<CheckBox Grid.Column="1"
36-
Grid.Row="3"
50+
Grid.Row="5"
3751
IsChecked="{Binding Transparent}"/>
3852
<Button x:Name="closeButton"
3953
Click="CloseButton_Click"
4054
Content="Fermer"
4155
HorizontalAlignment="Center"
4256
Grid.ColumnSpan="2"
43-
Grid.Row="5"
57+
Grid.Row="7"
4458
Margin="5"
4559
Padding="5" />
4660
</Grid>

0 commit comments

Comments
 (0)