Skip to content

Commit 96354d6

Browse files
committed
* Added more error handling
* Added more code commentary * Fixed a couple of mistakes
1 parent 97359e9 commit 96354d6

File tree

5 files changed

+454
-100
lines changed

5 files changed

+454
-100
lines changed

MemPlus/Classes/LOG/LogController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ internal LogController(int clearInterval)
6969
logTimer.Enabled = true;
7070
}
7171

72+
/// <summary>
73+
/// Event that will be called by a timer object
74+
/// </summary>
75+
/// <param name="sender">The object that called this method</param>
76+
/// <param name="e">The ElapsedEventArgs</param>
7277
private void OnTimedEvent(object sender, ElapsedEventArgs e)
7378
{
7479
ClearLogs(LogType.Application);

MemPlus/Windows/AboutWindow.xaml.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ namespace MemPlus.Windows
1212
/// </summary>
1313
public partial class AboutWindow
1414
{
15+
#region Variables
16+
/// <summary>
17+
/// The LogController object that can be used to add logs
18+
/// </summary>
1519
private readonly LogController _logController;
20+
#endregion
1621

1722
/// <inheritdoc />
1823
/// <summary>
1924
/// Initialize a new AboutWindow
2025
/// </summary>
26+
/// <param name="logController">The LogController that can be used to add logs</param>
2127
public AboutWindow(LogController logController)
2228
{
2329
_logController = logController;
@@ -36,7 +42,15 @@ public AboutWindow(LogController logController)
3642
private void LoadProperties()
3743
{
3844
_logController.AddLog(new ApplicationLog("Loading AboutWindow properties"));
39-
Topmost = Properties.Settings.Default.Topmost;
45+
try
46+
{
47+
Topmost = Properties.Settings.Default.Topmost;
48+
}
49+
catch (Exception ex)
50+
{
51+
_logController.AddLog(new ApplicationLog(ex.Message));
52+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
53+
}
4054
_logController.AddLog(new ApplicationLog("Done loading AboutWindow properties"));
4155
}
4256

MemPlus/Windows/LogWindow.xaml.cs

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,27 @@ namespace MemPlus.Windows
1616
/// </summary>
1717
public partial class LogWindow
1818
{
19+
#region Variables
20+
/// <summary>
21+
/// The LogController object that can be used to add logs
22+
/// </summary>
1923
private readonly LogController _logController;
24+
/// <summary>
25+
/// The LogType that is currently being monitored
26+
/// </summary>
2027
private readonly LogType _logType;
28+
/// <summary>
29+
/// A boolean to indicate whether automatic scrolling is enabled or not
30+
/// </summary>
2131
private bool _autoScroll;
32+
#endregion
2233

34+
/// <inheritdoc />
35+
/// <summary>
36+
/// Initialize a new LogWindow object
37+
/// </summary>
38+
/// <param name="logController">The LogController object that can be used to add and view logs</param>
39+
/// <param name="logType">The LogType that is currently being monitored</param>
2340
public LogWindow(LogController logController, LogType logType)
2441
{
2542
_logController = logController;
@@ -43,13 +60,28 @@ public LogWindow(LogController logController, LogType logType)
4360
_logController.AddLog(new ApplicationLog("Done initializing LogWindow"));
4461
}
4562

63+
/// <summary>
64+
/// Load the current properties into the GUI
65+
/// </summary>
4666
private void LoadProperties()
4767
{
4868
_logController.AddLog(new ApplicationLog("Loading LogWindow properties"));
49-
Topmost = Properties.Settings.Default.Topmost;
69+
try
70+
{
71+
Topmost = Properties.Settings.Default.Topmost;
72+
}
73+
catch (Exception ex)
74+
{
75+
_logController.AddLog(new ApplicationLog(ex.Message));
76+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
77+
}
5078
_logController.AddLog(new ApplicationLog("Done loading LogWindow properties"));
5179
}
5280

81+
/// <summary>
82+
/// Method that will be called when all logs of a certain type have been cleared
83+
/// </summary>
84+
/// <param name="clearedList">The list of Log objects that were removed</param>
5385
private void LogTypeClearedEvent(List<Log> clearedList)
5486
{
5587
Dispatcher.Invoke(() =>
@@ -61,6 +93,9 @@ private void LogTypeClearedEvent(List<Log> clearedList)
6193
});
6294
}
6395

96+
/// <summary>
97+
/// Fill the ListView will all current Log objects
98+
/// </summary>
6499
private void FillLogView()
65100
{
66101
foreach (Log l in _logController.GetLogs().Where(l => l.LogType == _logType))
@@ -69,6 +104,10 @@ private void FillLogView()
69104
}
70105
}
71106

107+
/// <summary>
108+
/// Method that will be called when a Log object was removed
109+
/// </summary>
110+
/// <param name="log">The Log object that was removed</param>
72111
private void LogDeletedEvent(Log log)
73112
{
74113
if (log.LogType != _logType) return;
@@ -78,6 +117,9 @@ private void LogDeletedEvent(Log log)
78117
});
79118
}
80119

120+
/// <summary>
121+
/// Method that will be called when all logs were removed
122+
/// </summary>
81123
private void LogsClearedEvent()
82124
{
83125
Dispatcher.Invoke(() =>
@@ -86,6 +128,10 @@ private void LogsClearedEvent()
86128
});
87129
}
88130

131+
/// <summary>
132+
/// Method that will be called when a Log object was added
133+
/// </summary>
134+
/// <param name="log">The Log object that was added</param>
89135
private void LogAddedEvent(Log log)
90136
{
91137
if (log.LogType != _logType) return;
@@ -100,13 +146,21 @@ private void LogAddedEvent(Log log)
100146
});
101147
}
102148

149+
/// <summary>
150+
/// Change the visual style of the controls, depending on the settings.
151+
/// </summary>
103152
private void ChangeVisualStyle()
104153
{
105154
_logController.AddLog(new ApplicationLog("Changing LogWindow theme style"));
106155
StyleManager.ChangeStyle(this);
107156
_logController.AddLog(new ApplicationLog("Done changing LogWindow theme style"));
108157
}
109158

159+
/// <summary>
160+
/// Method that is called when a scoll action happened in the ListView
161+
/// </summary>
162+
/// <param name="sender">The object that called this method</param>
163+
/// <param name="e">The ScrollEventArgs</param>
110164
private void LsvLogs_OnScroll(object sender, ScrollEventArgs e)
111165
{
112166
if (!(e.OriginalSource is ScrollBar sb)) return;
@@ -116,11 +170,21 @@ private void LsvLogs_OnScroll(object sender, ScrollEventArgs e)
116170
_autoScroll = Math.Abs(sb.Value - sb.Maximum) < 1;
117171
}
118172

173+
/// <summary>
174+
/// Method that will be called when all logs of a certain type should be cleared
175+
/// </summary>
176+
/// <param name="sender">The object that called this method</param>
177+
/// <param name="e">The RoutedEventArgs</param>
119178
private void BtnClear_OnClick(object sender, RoutedEventArgs e)
120179
{
121180
_logController.ClearLogs(_logType);
122181
}
123182

183+
/// <summary>
184+
/// Method that will be called when all Logs of a certain type should be exported
185+
/// </summary>
186+
/// <param name="sender">The object that called this method</param>
187+
/// <param name="e">The RoutedEventArgs</param>
124188
private void BtnExport_OnClick(object sender, RoutedEventArgs e)
125189
{
126190
SaveFileDialog sfd = new SaveFileDialog
@@ -161,17 +225,35 @@ private void BtnExport_OnClick(object sender, RoutedEventArgs e)
161225
}
162226
}
163227

228+
/// <summary>
229+
/// Method that will be called when a Log object should be removed
230+
/// </summary>
231+
/// <param name="sender">The object that called this method</param>
232+
/// <param name="e">The RoutedEventArgs</param>
164233
private void DeleteMenuItem_OnClick(object sender, RoutedEventArgs e)
165234
{
166235
if (LsvLogs.SelectedItems.Count == 0) return;
167236
_logController.RemoveLog(LsvLogs.SelectedItem as Log);
168237
}
169238

239+
/// <summary>
240+
/// Method that will be called when a Log object should be copied to the clipboard
241+
/// </summary>
242+
/// <param name="sender">The object that called this method</param>
243+
/// <param name="e">The RoutedEventArgs</param>
170244
private void CopyMenuItem_OnClick(object sender, RoutedEventArgs e)
171245
{
172246
if (LsvLogs.SelectedItems.Count == 0) return;
173247
if (!(LsvLogs.SelectedItem is Log selectedLog)) return;
174-
Clipboard.SetText(selectedLog.Time + "\t" + selectedLog.Data);
248+
try
249+
{
250+
Clipboard.SetText(selectedLog.Time + "\t" + selectedLog.Data);
251+
}
252+
catch (Exception ex)
253+
{
254+
_logController.AddLog(new ApplicationLog(ex.Message));
255+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
256+
}
175257
}
176258
}
177259
}

0 commit comments

Comments
 (0)