Skip to content

Commit 9084afe

Browse files
committed
* Added Process analyzer building blocks
* Added ProcessLog objects * Code refactoring and improvements
1 parent 92dcaa0 commit 9084afe

24 files changed

+482
-30
lines changed

MemPlus/Business/LOG/Log.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public string GetData()
5959
public enum LogType
6060
{
6161
Application,
62-
Ram
62+
Ram,
63+
Process
6364
}
6465
}

MemPlus/Business/LOG/LogController.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Timers;
45
using MemPlus.Business.EXPORT;
56

@@ -37,7 +38,6 @@ public class LogController
3738
/// </summary>
3839
/// <param name="clearedList">The list of Log objects that were removed</param>
3940
internal delegate void LogTypeCleared(List<Log> clearedList);
40-
4141
/// <summary>
4242
/// Method that will be called when a Log object was added
4343
/// </summary>
@@ -135,14 +135,27 @@ internal void ClearLogs()
135135
}
136136

137137
/// <summary>
138-
/// Retrieve the list of currently available Log objects
138+
/// Retrieve the list of available Log objects
139139
/// </summary>
140-
/// <returns>The list of currently available Log objects</returns>
141-
internal List<Log> GetLogs()
140+
/// <returns>The list of available Log objects</returns>
141+
private List<Log> GetLogs()
142142
{
143143
return _logList;
144144
}
145145

146+
/// <summary>
147+
/// Retrieve the list of available Log objects of a specific LogType
148+
/// </summary>
149+
/// <param name="logType">The LogType of the Log objects that should be returned</param>
150+
/// <returns>A list of Log objects that are of the specified LogType</returns>
151+
internal List<Log> GetLogs(LogType? logType)
152+
{
153+
if (logType == null) return GetLogs();
154+
155+
List<Log> logList = _logList.Where(l => l.LogType == logType).ToList();
156+
return logList;
157+
}
158+
146159
/// <summary>
147160
/// Export logs to the disk
148161
/// </summary>
@@ -169,6 +182,8 @@ internal void Export(string path, LogType? logType, ExportTypes.ExportType expor
169182
exportList = _logList;
170183
}
171184

185+
if (exportList == null || exportList.Count == 0) throw new ArgumentNullException();
186+
172187
// ReSharper disable once SwitchStatementMissingSomeCases
173188
switch (exportType)
174189
{

MemPlus/Business/LOG/LogExporter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal static class LogExporter
1616
/// <param name="logList">The list of Log objects that should be exported</param>
1717
internal static void ExportHtml(string path, List<Log> logList)
1818
{
19+
if (logList == null || logList.Count == 0) throw new ArgumentNullException();
1920
string exportData = "<html>";
2021

2122
exportData += "<head>";
@@ -54,6 +55,8 @@ internal static void ExportHtml(string path, List<Log> logList)
5455
/// <param name="logList">The list of Log objects that should be exported</param>
5556
internal static void ExportTxt(string path, List<Log> logList)
5657
{
58+
if (logList == null || logList.Count == 0) throw new ArgumentNullException();
59+
5760
string exportData = "MemPlus - Log Export (" + DateTime.Now + ")";
5861
exportData += Environment.NewLine;
5962

@@ -76,6 +79,7 @@ internal static void ExportTxt(string path, List<Log> logList)
7679
/// <param name="logList">The list of Log objects that should be exported</param>
7780
internal static void ExportCsv(string path, List<Log> logList)
7881
{
82+
if (logList == null || logList.Count == 0) throw new ArgumentNullException();
7983
ExportDelimiter(path, logList, ",");
8084
}
8185

@@ -86,6 +90,7 @@ internal static void ExportCsv(string path, List<Log> logList)
8690
/// <param name="logList">The list of Log objects that should be exported</param>
8791
internal static void ExportExcel(string path, List<Log> logList)
8892
{
93+
if (logList == null || logList.Count == 0) throw new ArgumentNullException();
8994
ExportDelimiter(path, logList, ";");
9095
}
9196

@@ -97,6 +102,7 @@ internal static void ExportExcel(string path, List<Log> logList)
97102
/// <param name="delimiter">The delimiter character that should be used</param>
98103
private static void ExportDelimiter(string path, IReadOnlyList<Log> logList, string delimiter)
99104
{
105+
if (logList == null || logList.Count == 0) throw new ArgumentNullException();
100106
string exportData = "Time" + delimiter + "Data";
101107
exportData += Environment.NewLine;
102108

MemPlus/Business/LOG/ProcessLog.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace MemPlus.Business.LOG
4+
{
5+
/// <inheritdoc />
6+
/// <summary>
7+
/// A class that represent a change in the ProcessAnalyzer
8+
/// </summary>
9+
internal class ProcessLog : Log
10+
{
11+
/// <summary>
12+
/// Initialize a new ProcessLog object
13+
/// </summary>
14+
/// <param name="data">The data that needs to be added to the Log</param>
15+
internal ProcessLog(string data)
16+
{
17+
LogType = LogType.Process;
18+
Data = data;
19+
Time = DateTime.Now;
20+
}
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace MemPlus.Business.PROCESS
2+
{
3+
/// <summary>
4+
/// Internal class that represents the presentable details of a Process object
5+
/// </summary>
6+
internal class ProcessDetail
7+
{
8+
/// <summary>
9+
/// The ID of the Process
10+
/// </summary>
11+
public int ProcessId { get; set; }
12+
/// <summary>
13+
/// The name of the Process
14+
/// </summary>
15+
public string ProcessName { get; set; }
16+
/// <summary>
17+
/// The location of the Process
18+
/// </summary>
19+
public string ProcessLocation { get; set; }
20+
/// <summary>
21+
/// The current memory usage of the Process in MB
22+
/// </summary>
23+
public string MemoryUsage { get; set; }
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MemPlus.Business.PROCESS
8+
{
9+
internal static class ProcessDetailExporter
10+
{
11+
12+
}
13+
}

MemPlus/Business/RAM/RamSticksExporter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ private static void Export(string path, string data)
2929
/// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
3030
internal static void ExportText(string path, List<RamStick> ramSticks)
3131
{
32+
if (ramSticks == null || ramSticks.Count == 0) throw new ArgumentNullException();
33+
3234
string exportData = "MemPlus - Ram Analyzer Data (" + DateTime.Now + ")";
3335
exportData += Environment.NewLine;
3436
exportData += "---";
@@ -63,6 +65,8 @@ internal static void ExportText(string path, List<RamStick> ramSticks)
6365
/// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
6466
internal static void ExportHtml(string path, List<RamStick> ramSticks)
6567
{
68+
if (ramSticks == null || ramSticks.Count == 0) throw new ArgumentNullException();
69+
6670
string exportData = "<html>";
6771

6872
exportData += "<head>";
@@ -131,8 +135,10 @@ internal static void ExportExcel(string path, List<RamStick> ramSticks)
131135
/// <param name="path">The path where the data should be stored</param>
132136
/// <param name="delimiter">The delimiter that should be used to split the data</param>
133137
/// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
134-
private static void ExportDelimiter(string path, string delimiter, List<RamStick> ramSticks)
138+
private static void ExportDelimiter(string path, string delimiter, IReadOnlyList<RamStick> ramSticks)
135139
{
140+
if (ramSticks == null || ramSticks.Count == 0) throw new ArgumentNullException();
141+
136142
string exportData = "Key" + delimiter + "Value";
137143
exportData += Environment.NewLine;
138144

MemPlus/Business/UTILS/Utils.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.Management;
35
using System.Security.Principal;
6+
using MemPlus.Business.LOG;
7+
using MemPlus.Business.PROCESS;
48
using MemPlus.Business.RAM;
59

610
namespace MemPlus.Business.UTILS
@@ -53,5 +57,36 @@ internal static List<RamStick> GetRamSticks()
5357

5458
return ramSticks;
5559
}
60+
61+
/// <summary>
62+
/// Retrieve a list of ProcessDetail objects
63+
/// </summary>
64+
/// <param name="logController">The LogController object that can be used to add logs</param>
65+
/// <returns></returns>
66+
internal static List<ProcessDetail> GetProcessDetails(LogController logController)
67+
{
68+
logController.AddLog(new ProcessLog("Retrieving process details"));
69+
List<ProcessDetail> processDetailsList = new List<ProcessDetail>();
70+
foreach (Process p in Process.GetProcesses())
71+
{
72+
try
73+
{
74+
ProcessDetail pd = new ProcessDetail
75+
{
76+
ProcessId = p.Id,
77+
ProcessName = p.ProcessName,
78+
ProcessLocation = p.MainModule.FileName,
79+
MemoryUsage = (p.WorkingSet64 / (1024 * 1024)).ToString("F2") + " MB"
80+
};
81+
processDetailsList.Add(pd);
82+
}
83+
catch (Exception ex)
84+
{
85+
logController.AddLog(new ProcessLog(p.ProcessName + ": " + ex.Message));
86+
}
87+
}
88+
logController.AddLog(new ProcessLog("Done retrieving process details"));
89+
return processDetailsList;
90+
}
5691
}
5792
}

MemPlus/MemPlus.csproj

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@
8787
<SubType>Designer</SubType>
8888
</ApplicationDefinition>
8989
<Compile Include="Business\EXPORT\ExportTypes.cs" />
90+
<Compile Include="Business\LOG\ProcessLog.cs" />
91+
<Compile Include="Business\PROCESS\ProcessDetail.cs" />
92+
<Compile Include="Business\PROCESS\ProcessDetailExporter.cs" />
9093
<Compile Include="Business\RAM\RamData.cs" />
9194
<Compile Include="Business\RAM\RamSticksExporter.cs" />
9295
<Compile Include="Business\RAM\RamStick.cs" />
9396
<Compile Include="Business\UTILS\NativeMethods.cs" />
9497
<Compile Include="Business\UTILS\Utils.cs" />
95-
<Compile Include="Views\Windows\AnalyzerWindow.xaml.cs">
96-
<DependentUpon>AnalyzerWindow.xaml</DependentUpon>
98+
<Compile Include="Views\Windows\RamAnalyzerWindow.xaml.cs">
99+
<DependentUpon>RamAnalyzerWindow.xaml</DependentUpon>
100+
</Compile>
101+
<Compile Include="Views\Windows\ProcessAnalyzerWindow.xaml.cs">
102+
<DependentUpon>ProcessAnalyzerWindow.xaml</DependentUpon>
97103
</Compile>
98104
<Compile Include="Views\Windows\SettingsWindow.xaml.cs">
99105
<DependentUpon>SettingsWindow.xaml</DependentUpon>
@@ -102,7 +108,7 @@
102108
<SubType>Designer</SubType>
103109
<Generator>MSBuild:Compile</Generator>
104110
</Page>
105-
<Page Include="Views\Windows\AnalyzerWindow.xaml">
111+
<Page Include="Views\Windows\RamAnalyzerWindow.xaml">
106112
<SubType>Designer</SubType>
107113
<Generator>MSBuild:Compile</Generator>
108114
</Page>
@@ -137,6 +143,10 @@
137143
<DependentUpon>MainWindow.xaml</DependentUpon>
138144
<SubType>Code</SubType>
139145
</Compile>
146+
<Page Include="Views\Windows\ProcessAnalyzerWindow.xaml">
147+
<SubType>Designer</SubType>
148+
<Generator>MSBuild:Compile</Generator>
149+
</Page>
140150
<Page Include="Views\Windows\SettingsWindow.xaml">
141151
<SubType>Designer</SubType>
142152
<Generator>MSBuild:Compile</Generator>
@@ -229,5 +239,8 @@
229239
<Install>false</Install>
230240
</BootstrapperPackage>
231241
</ItemGroup>
242+
<ItemGroup>
243+
<Resource Include="Resources\Images\process.png" />
244+
</ItemGroup>
232245
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
233246
</Project>

MemPlus/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.1.1.0")]
55-
[assembly: AssemblyFileVersion("1.1.1.0")]
54+
[assembly: AssemblyVersion("1.2.0.0")]
55+
[assembly: AssemblyFileVersion("1.2.0.0")]

0 commit comments

Comments
 (0)