Skip to content

Commit 2e91342

Browse files
committed
* Completely redesigned the RamAnalyzer window
* Fixed an issue with saving settings and resetting settings * Fixed a typo * Optimized some code
1 parent c2b4f57 commit 2e91342

16 files changed

+304
-165
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace MemPlus.Classes.EXPORT
2+
{
3+
internal sealed class ExportTypes
4+
{
5+
/// <summary>
6+
/// Enumaration containing all the different export types
7+
/// </summary>
8+
internal enum ExportType
9+
{
10+
Html,
11+
Text,
12+
Csv,
13+
Excel
14+
}
15+
}
16+
}

MemPlus/Classes/GUI/StyleManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal static void ChangeStyle(DependencyObject o)
2626
catch (Exception ex)
2727
{
2828
SkinStorage.SetVisualStyle(o, "Metro");
29-
MessageBox.Show(ex.Message, "AniView", MessageBoxButton.OK, MessageBoxImage.Error);
29+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
3030
}
3131
}
3232
}

MemPlus/Classes/LOG/LogController.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Timers;
4+
using MemPlus.Classes.EXPORT;
45

56
namespace MemPlus.Classes.LOG
67
{
@@ -148,7 +149,7 @@ internal List<Log> GetLogs()
148149
/// <param name="path">The path where logs should be stored</param>
149150
/// <param name="logType">The type of logs that should be saved. Can be null if all logs should be saved</param>
150151
/// <param name="exportType">The type of export that should be performed</param>
151-
internal void Export(string path, LogType? logType, ExportType exportType)
152+
internal void Export(string path, LogType? logType, ExportTypes.ExportType exportType)
152153
{
153154
List<Log> exportList;
154155

@@ -171,16 +172,16 @@ internal void Export(string path, LogType? logType, ExportType exportType)
171172
// ReSharper disable once SwitchStatementMissingSomeCases
172173
switch (exportType)
173174
{
174-
case ExportType.Html:
175+
case ExportTypes.ExportType.Html:
175176
LogExporter.ExportHtml(path, exportList);
176177
break;
177178
default:
178179
LogExporter.ExportTxt(path, exportList);
179180
break;
180-
case ExportType.Csv:
181+
case ExportTypes.ExportType.Csv:
181182
LogExporter.ExportCsv(path, exportList);
182183
break;
183-
case ExportType.Excel:
184+
case ExportTypes.ExportType.Excel:
184185
LogExporter.ExportExcel(path, exportList);
185186
break;
186187
}

MemPlus/Classes/LOG/LogExporter.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,4 @@ private static void Export(string path, string data)
125125
}
126126
}
127127
}
128-
129-
/// <summary>
130-
/// Enumaration containing all the different export types
131-
/// </summary>
132-
internal enum ExportType
133-
{
134-
Html,
135-
Text,
136-
Csv,
137-
Excel
138-
}
139128
}

MemPlus/Classes/RAM/RamAnalyzer.cs

Lines changed: 25 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,47 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Threading.Tasks;
5-
using System.Timers;
1+
using System.Collections.Generic;
2+
using System.Management;
63
using MemPlus.Classes.RAM.ViewModels;
74

85
namespace MemPlus.Classes.RAM
96
{
10-
internal sealed class RamAnalyzer
7+
/// <summary>
8+
/// Static class that can be used to retrieve RAM information
9+
/// </summary>
10+
internal static class RamAnalyzer
1111
{
12-
private readonly List<ProcessData> _processDataList;
13-
14-
internal delegate void ProcessAddedEvent(ProcessData processData);
15-
internal delegate void ProcessRemovedEvent(ProcessData processData);
16-
17-
private readonly ProcessAddedEvent _processAddedEvent;
18-
private readonly ProcessRemovedEvent _processRemovedEvent;
19-
20-
internal RamAnalyzer(int delay, ProcessAddedEvent processAddedEvent, ProcessRemovedEvent processRemovedEvent)
12+
/// <summary>
13+
/// Retrieve RAM information
14+
/// </summary>
15+
/// <returns>A list of RAM information</returns>
16+
internal static List<RamStick> GetRamSticks()
2117
{
22-
_processAddedEvent = processAddedEvent;
23-
_processRemovedEvent = processRemovedEvent;
18+
List<RamStick> ramSticks = new List<RamStick>();
2419

25-
_processDataList = new List<ProcessData>();
26-
Timer updateTimer = new Timer
27-
{
28-
Interval = delay,
29-
Enabled = true
30-
};
20+
ConnectionOptions connection = new ConnectionOptions {Impersonation = ImpersonationLevel.Impersonate};
3121

32-
updateTimer.Elapsed += UpdateTimerOnElapsed;
33-
UpdateTimerOnElapsed(null, null);
34-
}
22+
ManagementScope scope = new ManagementScope("\\root\\CIMV2", connection);
23+
scope.Connect();
3524

36-
private async void UpdateTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
37-
{
38-
List<string> currentPaths = new List<string>();
39-
await Task.Run(async () =>
40-
{
41-
foreach (Process p in Process.GetProcesses())
42-
{
43-
try
44-
{
45-
currentPaths.Add(p.MainModule.FileName);
46-
47-
ProcessData processData = EqualsPath(p.MainModule.FileName);
48-
bool addProcessData = false;
49-
if (processData == null)
50-
{
51-
processData = new ProcessData();
52-
addProcessData = true;
53-
}
25+
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
5426

55-
processData.ProcessName = p.ProcessName;
56-
processData.ProcessLocation = p.MainModule.FileName;
57-
processData.Pid = p.Id;
58-
processData.WorkingSet = (p.WorkingSet64 / 1024 / 1024).ToString("F2") + " MB";
27+
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
5928

60-
if (addProcessData)
61-
{
62-
_processDataList.Add(processData);
63-
_processAddedEvent.Invoke(processData);
64-
}
65-
}
66-
catch (Exception ex)
67-
{
68-
69-
}
70-
}
71-
await CleanProcessList(currentPaths);
72-
});
73-
}
74-
75-
private async Task CleanProcessList(IReadOnlyCollection<string> currentPaths)
76-
{
77-
await Task.Run(() =>
29+
// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
30+
foreach (ManagementObject queryObj in searcher.Get())
7831
{
79-
for (int i = _processDataList.Count - 1; i >= 0; i--)
32+
RamStick stick = new RamStick();
33+
foreach (PropertyData data in queryObj.Properties)
8034
{
81-
bool remove = true;
82-
83-
foreach (string s in currentPaths)
84-
{
85-
if (_processDataList[i].ProcessLocation == s)
86-
{
87-
remove = false;
88-
break;
89-
}
90-
}
91-
92-
if (remove)
35+
if (data.Value != null)
9336
{
94-
_processRemovedEvent.Invoke(_processDataList[i]);
95-
_processDataList.RemoveAt(i);
37+
stick.AddRamData(new RamData(data.Name, data.Value.ToString()));
9638
}
9739
}
98-
});
99-
}
10040

101-
private ProcessData EqualsPath(string path)
102-
{
103-
foreach (ProcessData pd in _processDataList)
104-
{
105-
if (pd.ProcessLocation == path)
106-
{
107-
return pd;
108-
}
41+
ramSticks.Add(stick);
10942
}
110-
return null;
111-
}
11243

113-
internal List<ProcessData> GetProcessData()
114-
{
115-
return _processDataList;
44+
return ramSticks;
11645
}
11746
}
11847
}

MemPlus/Classes/RAM/RamData.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace MemPlus.Classes.RAM
2+
{
3+
/// <summary>
4+
/// ViewModal for displaying RAM information inside a treeview
5+
/// </summary>
6+
internal sealed class RamData
7+
{
8+
/// <summary>
9+
/// A key value
10+
/// </summary>
11+
public string Key { get; set; }
12+
/// <summary>
13+
/// The value that is linked to the specific key
14+
/// </summary>
15+
public string Value { get; set; }
16+
17+
/// <summary>
18+
/// Initialize a new RamData object
19+
/// </summary>
20+
/// <param name="key">The key</param>
21+
/// <param name="value">The corresponding data</param>
22+
internal RamData(string key, string value)
23+
{
24+
Key = key;
25+
Value = value;
26+
}
27+
}
28+
}

MemPlus/Classes/RAM/RamStick.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
3+
namespace MemPlus.Classes.RAM.ViewModels
4+
{
5+
internal sealed class RamStick
6+
{
7+
private readonly List<RamData> _ramData;
8+
9+
internal RamStick()
10+
{
11+
_ramData = new List<RamData>();
12+
}
13+
14+
internal void AddRamData(RamData ramData)
15+
{
16+
_ramData.Add(ramData);
17+
}
18+
19+
internal List<RamData> GetRamData()
20+
{
21+
return _ramData;
22+
}
23+
24+
internal string GetValue(string key)
25+
{
26+
foreach(RamData r in _ramData)
27+
{
28+
if (r.Key.ToLower() == key.ToLower())
29+
{
30+
return r.Value;
31+
}
32+
}
33+
return "";
34+
}
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using MemPlus.Classes.RAM.ViewModels;
4+
5+
namespace MemPlus.Classes.RAM
6+
{
7+
/// <summary>
8+
/// Static class that can be used to export RamStick information
9+
/// </summary>
10+
internal static class RamDataExporter
11+
{
12+
private static void Export(string path, string data)
13+
{
14+
using (StreamWriter sw = new StreamWriter(path))
15+
{
16+
sw.Write(data);
17+
}
18+
}
19+
20+
internal static void ExportText(string path, List<RamStick> ramSticks)
21+
{
22+
23+
}
24+
25+
internal static void ExportHtml(string path, List<RamStick> ramSticks)
26+
{
27+
28+
}
29+
30+
internal static void ExportCsv(string path, List<RamStick> ramSticks)
31+
{
32+
33+
}
34+
35+
internal static void ExportExcel(string path, List<RamStick> ramSticks)
36+
{
37+
38+
}
39+
}
40+
}

MemPlus/Classes/RAM/ViewModels/ProcessData.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

MemPlus/MemPlus.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Reference Include="System" />
5656
<Reference Include="System.Core" />
5757
<Reference Include="System.Drawing" />
58+
<Reference Include="System.Management" />
5859
<Reference Include="System.Xaml">
5960
<RequiredTargetFramework>4.0</RequiredTargetFramework>
6061
</Reference>
@@ -70,8 +71,11 @@
7071
<Generator>MSBuild:Compile</Generator>
7172
<SubType>Designer</SubType>
7273
</ApplicationDefinition>
74+
<Compile Include="Classes\EXPORT\ExportTypes.cs" />
7375
<Compile Include="Classes\RAM\RamAnalyzer.cs" />
74-
<Compile Include="Classes\RAM\ViewModels\ProcessData.cs" />
76+
<Compile Include="Classes\RAM\RamData.cs" />
77+
<Compile Include="Classes\RAM\RamSticksExporter.cs" />
78+
<Compile Include="Classes\RAM\RamStick.cs" />
7579
<Compile Include="Windows\AnalyzerWindow.xaml.cs">
7680
<DependentUpon>AnalyzerWindow.xaml</DependentUpon>
7781
</Compile>

0 commit comments

Comments
 (0)