Skip to content

Commit b6bcf16

Browse files
committed
* Visual Studio being silly
1 parent cd919ea commit b6bcf16

11 files changed

+276
-63
lines changed

MemPlus/Classes/LOG/ApplicationLog.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ internal class ApplicationLog : Log
1111
/// <summary>
1212
/// Initialize a new ApplicationLog object
1313
/// </summary>
14+
/// <param name="data">The data that needs to be added to the Log</param>
1415
internal ApplicationLog(string data)
1516
{
1617
LogType = LogType.Application;

MemPlus/Classes/LOG/ILogMethods.cs

+15
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@
22

33
namespace MemPlus.Classes.LOG
44
{
5+
/// <summary>
6+
/// Interface containing methods that are required for Log objects
7+
/// </summary>
58
internal interface ILogMethods
69
{
10+
/// <summary>
11+
/// Add data to the Log object
12+
/// </summary>
13+
/// <param name="data">The data that needs to be added to the log</param>
714
void AddData(string data);
15+
/// <summary>
16+
/// Retrieve the data from the Log object
17+
/// </summary>
18+
/// <returns>The data from the Log object</returns>
819
string GetData();
20+
/// <summary>
21+
/// Retrieve the creation date of the Log object
22+
/// </summary>
23+
/// <returns>The creation date of the Log object</returns>
924
DateTime GetDate();
1025
}
1126
}

MemPlus/Classes/LOG/Log.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,51 @@
22

33
namespace MemPlus.Classes.LOG
44
{
5+
/// <inheritdoc />
6+
/// <summary>
7+
/// Abstract class containing logging information
8+
/// </summary>
59
public abstract class Log : ILogMethods
610
{
711
/// <summary>
812
/// The type of log
913
/// </summary>
1014
internal LogType LogType { get; set; }
11-
15+
/// <summary>
16+
/// The creation date of the Log object
17+
/// </summary>
1218
public DateTime Time { get; set; }
19+
/// <summary>
20+
/// The data inside the Log object
21+
/// </summary>
1322
public string Data { get; set; }
1423

24+
/// <inheritdoc />
25+
/// <summary>
26+
/// Retrieve the data of the Log object
27+
/// </summary>
28+
/// <returns>The data of the Log object</returns>
1529
public DateTime GetDate()
1630
{
1731
return Time;
1832
}
1933

34+
/// <inheritdoc />
35+
/// <summary>
36+
/// Add data to the Log object
37+
/// </summary>
38+
/// <param name="data">The data that needs to be added to the log</param>
2039
public void AddData(string data)
2140
{
2241
Time = DateTime.Now;
2342
Data = data;
2443
}
2544

45+
/// <inheritdoc />
46+
/// <summary>
47+
/// Retrieve the data from the Log object
48+
/// </summary>
49+
/// <returns>The data from the Log object</returns>
2650
public string GetData()
2751
{
2852
return Data;

MemPlus/Classes/LOG/LogController.cs

+56-1
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,74 @@
33

44
namespace MemPlus.Classes.LOG
55
{
6+
/// <summary>
7+
/// Class containing methods to control logs
8+
/// </summary>
69
public class LogController
710
{
11+
/// <summary>
12+
/// The list of available Log objects
13+
/// </summary>
814
private readonly List<Log> _logList;
15+
/// <summary>
16+
/// Delegate that will be called when a Log object was added
17+
/// </summary>
18+
/// <param name="l">The Log object that was added</param>
919
internal delegate void LogAdded(Log l);
20+
/// <summary>
21+
/// Delegate that will be called when a Log object was removed
22+
/// </summary>
23+
/// <param name="l">The Log object that was deleted</param>
1024
internal delegate void LogDeleted(Log l);
25+
/// <summary>
26+
/// Delegate that will be called when all Log objects are removed
27+
/// </summary>
1128
internal delegate void LogsCleared();
29+
/// <summary>
30+
/// Delegate that will be called when a list of Log objects with a specific LogType were removed
31+
/// </summary>
32+
/// <param name="clearedList">The list of Log objects that were removed</param>
1233
internal delegate void LogTypeCleared(List<Log> clearedList);
1334

35+
/// <summary>
36+
/// Method that will be called when a Log object was added
37+
/// </summary>
1438
internal LogAdded LogAddedEvent;
39+
/// <summary>
40+
/// Method that will be called when a Log object was removed
41+
/// </summary>
1542
internal LogDeleted LogDeletedEvent;
43+
/// <summary>
44+
/// Method that will be called when all Log objects were removed
45+
/// </summary>
1646
internal LogsCleared LogsClearedEvent;
47+
/// <summary>
48+
/// Method that will be called when a list of Log objects with a specific LogType were removed
49+
/// </summary>
1750
internal LogTypeCleared LogTypeClearedEvent;
1851

52+
/// <summary>
53+
/// Initialize a new LogController object
54+
/// </summary>
1955
internal LogController()
2056
{
2157
_logList = new List<Log>();
2258
}
2359

60+
/// <summary>
61+
/// Add a Log object to the list of logs
62+
/// </summary>
63+
/// <param name="l">The Log object that needs to be added</param>
2464
internal void AddLog(Log l)
2565
{
2666
_logList.Add(l);
2767
LogAddedEvent?.Invoke(l);
2868
}
2969

70+
/// <summary>
71+
/// Remove a Log object from the list of logs
72+
/// </summary>
73+
/// <param name="l">The Log object that needs to be removed</param>
3074
internal void RemoveLog(Log l)
3175
{
3276
if (_logList.Contains(l))
@@ -40,6 +84,10 @@ internal void RemoveLog(Log l)
4084
}
4185
}
4286

87+
/// <summary>
88+
/// Clear all Log objects that have a specific LogType
89+
/// </summary>
90+
/// <param name="logType">The LogType that Log objects need to contain in order to be removed</param>
4391
internal void ClearLogs(LogType logType)
4492
{
4593
List<Log> deleted = new List<Log>();
@@ -54,12 +102,19 @@ internal void ClearLogs(LogType logType)
54102
LogTypeClearedEvent?.Invoke(deleted);
55103
}
56104

105+
/// <summary>
106+
/// Clear all Log objects
107+
/// </summary>
57108
internal void ClearLogs()
58109
{
59110
_logList.Clear();
60-
LogClearedEvent?.Invoke();
111+
LogsClearedEvent?.Invoke();
61112
}
62113

114+
/// <summary>
115+
/// Retrieve the list of currently available Log objects
116+
/// </summary>
117+
/// <returns>The list of currently available Log objects</returns>
63118
internal List<Log> GetLogs()
64119
{
65120
return _logList;

MemPlus/Classes/RAM/RamController.cs

+93-13
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,74 @@
99

1010
namespace MemPlus.Classes.RAM
1111
{
12+
/// <summary>
13+
/// Sealed class containing methods and interaction logic in terms of RAM
14+
/// </summary>
1215
internal sealed class RamController
1316
{
17+
#region Variables
18+
/// <summary>
19+
/// The RamOptimizer object that can be called to clear memory
20+
/// </summary>
21+
private readonly RamOptimizer _ramOptimizer;
22+
/// <summary>
23+
/// The Timer object that will periodically update RAM usage statistics
24+
/// </summary>
1425
private readonly Timer _ramTimer;
26+
/// <summary>
27+
/// The LogController object that can be used to add logs
28+
/// </summary>
1529
private readonly LogController _logController;
16-
30+
/// <summary>
31+
/// The Dispatcher object that can be used to update GUI components
32+
/// </summary>
1733
private readonly Dispatcher _dispatcher;
34+
/// <summary>
35+
/// The SfCircularGauge object that can be used to present RAM usage statistics
36+
/// </summary>
1837
private readonly SfCircularGauge _gauge;
38+
/// <summary>
39+
/// The Label object that can be used to show the total physical memory
40+
/// </summary>
1941
private readonly Label _lblTotal;
42+
/// <summary>
43+
/// The Label object that can be used to show the available physical memory
44+
/// </summary>
2045
private readonly Label _lblAvailable;
21-
46+
/// <summary>
47+
/// The ComputerInfo object that can be used to retrieve RAM usage statistics
48+
/// </summary>
2249
private readonly ComputerInfo _info;
50+
#endregion
2351

52+
#region Properties
53+
/// <summary>
54+
/// Property containing how much RAM is being used
55+
/// </summary>
2456
internal double RamUsage { get; private set; }
57+
/// <summary>
58+
/// Property containing the percentage of RAM that is being used
59+
/// </summary>
2560
internal double RamUsagePercentage { get; private set; }
61+
/// <summary>
62+
/// Property containing the total amount of RAM available
63+
/// </summary>
2664
internal double RamTotal { get; private set; }
65+
/// <summary>
66+
/// Property containing how much RAM was saved during the last optimisation
67+
/// </summary>
2768
internal double RamSavings { get; private set; }
28-
69+
#endregion
70+
71+
/// <summary>
72+
/// Initialize a new RamController object
73+
/// </summary>
74+
/// <param name="dispatcher">The Dispatcher object that can be used to update GUI components</param>
75+
/// <param name="gauge">The SfCircularGauge control that can be used to present RAM usage statistics</param>
76+
/// <param name="lblTotal">The Label control that can be used to display the total available memory statistics</param>
77+
/// <param name="lblAvailable">The Label control that can be used to display the available memory statistics</param>
78+
/// <param name="timerInterval">The interval for which RAM usage statistics should be updated</param>
79+
/// <param name="logController">The LogController object that can be used to add logs</param>
2980
internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTotal, Label lblAvailable, int timerInterval, LogController logController)
3081
{
3182
_logController = logController ?? throw new ArgumentNullException(nameof(logController));
@@ -42,44 +93,72 @@ internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTo
4293
_lblTotal = lblTotal ?? throw new ArgumentNullException(nameof(lblTotal));
4394
_lblAvailable = lblAvailable ?? throw new ArgumentNullException(nameof(lblAvailable));
4495

96+
_ramOptimizer = new RamOptimizer(_logController);
97+
4598
_ramTimer = new Timer();
4699
_ramTimer.Elapsed += OnTimedEvent;
47100
_ramTimer.Interval = timerInterval;
48101

49102
_logController.AddLog(new ApplicationLog("Done initializing RamController"));
50103
}
51104

105+
/// <summary>
106+
/// Enable RAM usage monitoring
107+
/// </summary>
52108
internal void EnableMonitor()
53109
{
54110
if (_ramTimer.Enabled) return;
55111
_ramTimer.Enabled = true;
56-
OnTimedEvent(null, null);
112+
113+
UpdateRamUsage();
114+
UpdateGuiControls();
115+
57116
_logController.AddLog(new ApplicationLog("The RAM monitor has been enabled"));
58117
}
59118

119+
/// <summary>
120+
/// Disable RAM usage monitoring
121+
/// </summary>
60122
internal void DisableMonitor()
61123
{
62124
_ramTimer.Enabled = false;
63125
_logController.AddLog(new ApplicationLog("The RAM monitor has been disabled"));
64126
}
65127

66-
private void OnTimedEvent(object source, ElapsedEventArgs e)
128+
/// <summary>
129+
/// Update the GUI controls with the available RAM usage statistics
130+
/// </summary>
131+
private void UpdateGuiControls()
67132
{
68-
_logController.AddLog(new ApplicationLog("RAM monitor timer has been called"));
69-
70-
UpdateRamUsage();
71-
72133
_dispatcher.Invoke(() =>
73134
{
74135
_gauge.Scales[0].Pointers[0].Value = RamUsagePercentage;
75136
_gauge.GaugeHeader = "RAM usage (" + RamUsagePercentage.ToString("F2") + "%)";
76137
_lblTotal.Content = (RamTotal / 1024 / 1024 / 1024).ToString("F2") + " GB";
77138
_lblAvailable.Content = (RamUsage / 1024 / 1024 / 1024).ToString("F2") + " GB";
78139
});
140+
}
141+
142+
/// <summary>
143+
/// Event that will be called when the timer interval was reached
144+
/// </summary>
145+
/// <param name="source">The calling object</param>
146+
/// <param name="e">The ElapsedEventArgs</param>
147+
private void OnTimedEvent(object source, ElapsedEventArgs e)
148+
{
149+
_logController.AddLog(new ApplicationLog("RAM monitor timer has been called"));
150+
151+
UpdateRamUsage();
152+
UpdateGuiControls();
79153

80154
_logController.AddLog(new ApplicationLog("Finished RAM monitor timer"));
81155
}
82156

157+
/// <summary>
158+
/// Clear all non-essential RAM
159+
/// </summary>
160+
/// <param name="filesystemcache">A boolean to indicate whether or not to clear the FileSystem cache</param>
161+
/// <returns></returns>
83162
internal async Task ClearMemory(bool filesystemcache)
84163
{
85164
_logController.AddLog(new ApplicationLog("Clearing RAM memory"));
@@ -90,10 +169,8 @@ await Task.Run(async () =>
90169

91170
double oldUsage = RamUsage;
92171

93-
//Clear working set of all processes that the user has access to
94-
MemPlus.EmptyWorkingSetFunction();
95-
//Clear file system cache
96-
MemPlus.ClearFileSystemCache(filesystemcache);
172+
_ramOptimizer.EmptyWorkingSetFunction();
173+
_ramOptimizer.ClearFileSystemCache(filesystemcache);
97174

98175
await Task.Delay(10000);
99176

@@ -106,6 +183,9 @@ await Task.Run(async () =>
106183
_logController.AddLog(new ApplicationLog("Done clearing RAM memory"));
107184
}
108185

186+
/// <summary>
187+
/// Update RAM usage statistics
188+
/// </summary>
109189
private void UpdateRamUsage()
110190
{
111191
_logController.AddLog(new ApplicationLog("Updating RAM usage"));

0 commit comments

Comments
 (0)