11using GalaSoft . MvvmLight ;
22using GalaSoft . MvvmLight . Messaging ;
33using Monbsoft . MachineMonitor . Configuration ;
4+ using Monbsoft . MachineMonitor . Helpers ;
45using Monbsoft . MachineMonitor . Messages ;
56using Monbsoft . MachineMonitor . Views ;
67using System ;
@@ -23,6 +24,8 @@ public class MainViewModel : ViewModelBase
2324 private double _cpu ;
2425 private double _disk ;
2526 private PerformanceCounter _diskCounter ;
27+ private string _displayMemory ;
28+ private string _displayNetwork ;
2629 private double _memoryTotal ;
2730 private double _network ;
2831 private PerformanceCounter _networkCounter ;
@@ -72,6 +75,22 @@ public double Disk
7275 set { Set ( ref _disk , value ) ; }
7376 }
7477
78+ /// <summary>
79+ /// Gets or sets the usage of the memory with the specified unit.
80+ /// </summary>
81+ public string DisplayMemory
82+ {
83+ get { return _displayMemory ; }
84+ set { Set ( ref _displayMemory , value ) ; }
85+ }
86+ /// <summary>
87+ /// Gets or sets the usage of the network with the specified unit.
88+ /// </summary>
89+ public string DisplayNetwork
90+ {
91+ get { return _displayNetwork ; }
92+ set { Set ( ref _displayNetwork , value ) ; }
93+ }
7594 /// <summary>
7695 /// Gets or sets the percentage of the network usage.
7796 /// </summary>
@@ -109,8 +128,7 @@ public void Initialize(MainWindow view)
109128 foreach ( var mobject in searcher . Get ( ) )
110129 {
111130 _memoryTotal = ToDouble ( mobject , "TotalPhysicalMemory" , Mega ) ;
112- }
113-
131+ }
114132 }
115133
116134 /// <summary>
@@ -132,6 +150,8 @@ private double CalculatePercent()
132150 double free = _memoryCounter . NextValue ( ) ;
133151 double use = ( _memoryTotal - free ) ;
134152 double percent = Math . Round ( ( use / _memoryTotal ) * 100 , 2 ) ;
153+
154+ DisplayMemory = OctetHelper . DisplayMega ( use ) ;
135155 return percent ;
136156 }
137157 private double GetPercentageNetwork ( )
@@ -140,11 +160,16 @@ private double GetPercentageNetwork()
140160 {
141161 return 0d ;
142162 }
143- double value = ( ( double ) _networkCounter . NextValue ( ) * 8 ) / 1000000 ;
163+ double bytes = ( ( double ) _networkCounter . NextValue ( ) ) ;
164+
165+ double value = ( ( double ) bytes * 8 ) / 1000000 ;
144166 if ( _networkMax < value )
145167 {
146168 _networkMax = value ;
147169 }
170+
171+ DisplayNetwork = BitHelper . DisplayByte ( bytes ) ;
172+
148173 return value * 100 / _networkMax ;
149174 }
150175 private void HandleUpdatedConfiguration ( UpdatedConfigurationMessage updatedMessage )
0 commit comments