1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . IO ;
3
- using MemPlus . Classes . RAM . ViewModels ;
4
4
5
5
namespace MemPlus . Classes . RAM
6
6
{
@@ -9,6 +9,11 @@ namespace MemPlus.Classes.RAM
9
9
/// </summary>
10
10
internal static class RamDataExporter
11
11
{
12
+ /// <summary>
13
+ /// Export data to a specific path
14
+ /// </summary>
15
+ /// <param name="path">The path where the data should be stored</param>
16
+ /// <param name="data">The data that should be exported</param>
12
17
private static void Export ( string path , string data )
13
18
{
14
19
using ( StreamWriter sw = new StreamWriter ( path ) )
@@ -17,24 +22,143 @@ private static void Export(string path, string data)
17
22
}
18
23
}
19
24
25
+ /// <summary>
26
+ /// Export a list of RamStick objects to a specific path in text format
27
+ /// </summary>
28
+ /// <param name="path">The path where the data should be stored</param>
29
+ /// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
20
30
internal static void ExportText ( string path , List < RamStick > ramSticks )
21
31
{
32
+ string exportData = "MemPlus - Ram Analyzer Data (" + DateTime . Now + ")" ;
33
+ exportData += Environment . NewLine ;
34
+ exportData += "---" ;
35
+ exportData += Environment . NewLine ;
22
36
37
+ for ( int index = 0 ; index < ramSticks . Count ; index ++ )
38
+ {
39
+ RamStick stick = ramSticks [ index ] ;
40
+ List < RamData > ramDataList = stick . GetRamData ( ) ;
41
+ for ( int i = 0 ; i < ramDataList . Count ; i ++ )
42
+ {
43
+ exportData += ramDataList [ i ] . Key + "\t " + ramDataList [ i ] . Value ;
44
+ if ( i != ramDataList . Count - 1 )
45
+ {
46
+ exportData += Environment . NewLine ;
47
+ }
48
+ }
49
+
50
+ if ( index != ramSticks . Count - 1 )
51
+ {
52
+ exportData += Environment . NewLine ;
53
+ exportData += "----------" ;
54
+ exportData += Environment . NewLine ;
55
+ }
56
+ }
57
+
58
+ Export ( path , exportData ) ;
23
59
}
24
60
61
+ /// <summary>
62
+ /// Export a list of RamStick objects to a specific path in HTML format
63
+ /// </summary>
64
+ /// <param name="path">The path where the data should be stored</param>
65
+ /// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
25
66
internal static void ExportHtml ( string path , List < RamStick > ramSticks )
26
67
{
68
+ string exportData = "<html>" ;
69
+
70
+ exportData += "<head>" ;
71
+ exportData += "<title>MemPlus - Ram Analyzer Data</title>" ;
72
+ exportData += "</head>" ;
73
+
74
+ exportData += "<body>" ;
75
+ exportData += "<h1>MemPlus - Ram Analyzer Data (" + DateTime . Now + ")</h1>" ;
76
+
77
+ for ( int index = 0 ; index < ramSticks . Count ; index ++ )
78
+ {
79
+ RamStick stick = ramSticks [ index ] ;
80
+ exportData += "<table border=\" 1\" >" ;
81
+ exportData += "<thead>" ;
82
+ exportData += "<tr><th>Key</th><th>Value</th></tr>" ;
83
+ exportData += "</thead>" ;
84
+ exportData += "<tbody>" ;
85
+
86
+ foreach ( RamData data in stick . GetRamData ( ) )
87
+ {
88
+ exportData += "<tr>" ;
89
+ exportData += "<td>" + data . Key + "</td>" ;
90
+ exportData += "<td>" + data . Value + "</td>" ;
91
+ exportData += "</tr>" ;
92
+ }
93
+
94
+ exportData += "</tbody>" ;
95
+ exportData += "</table>" ;
96
+
97
+ if ( index != ramSticks . Count - 1 )
98
+ {
99
+ exportData += "<br />" ;
100
+ }
101
+ }
102
+
103
+ exportData += "</body>" ;
104
+
105
+ exportData += "</html>" ;
27
106
107
+ Export ( path , exportData ) ;
28
108
}
29
109
110
+ /// <summary>
111
+ /// Export a list of RamStick objects to a specific path in CSV format
112
+ /// </summary>
113
+ /// <param name="path">The path where the data should be stored</param>
114
+ /// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
30
115
internal static void ExportCsv ( string path , List < RamStick > ramSticks )
31
116
{
32
-
117
+ ExportDelimiter ( path , "," , ramSticks ) ;
33
118
}
34
119
120
+ /// <summary>
121
+ /// Export a list of RamStick objects to a specific path in Excel format
122
+ /// </summary>
123
+ /// <param name="path">The path where the data should be stored</param>
124
+ /// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
35
125
internal static void ExportExcel ( string path , List < RamStick > ramSticks )
36
126
{
127
+ ExportDelimiter ( path , ";" , ramSticks ) ;
128
+ }
129
+
130
+ /// <summary>
131
+ /// Export a list of RamStick objects using a specific delimiter character
132
+ /// </summary>
133
+ /// <param name="path">The path where the data should be stored</param>
134
+ /// <param name="delimiter">The delimiter that should be used to split the data</param>
135
+ /// <param name="ramSticks">The list of RamStick objects that need to be exported</param>
136
+ private static void ExportDelimiter ( string path , string delimiter , List < RamStick > ramSticks )
137
+ {
138
+ string exportData = "Key" + delimiter + "Value" ;
139
+ exportData += Environment . NewLine ;
140
+
141
+ for ( int i = 0 ; i < ramSticks . Count ; i ++ )
142
+ {
143
+ List < RamData > ramData = ramSticks [ i ] . GetRamData ( ) ;
144
+ for ( int index = 0 ; index < ramData . Count ; index ++ )
145
+ {
146
+ exportData += ramData [ index ] . Key + delimiter + ramData [ index ] . Value ;
147
+ if ( index != ramData . Count - 1 )
148
+ {
149
+ exportData += Environment . NewLine ;
150
+ }
151
+ }
152
+
153
+ if ( i != ramSticks . Count - 1 )
154
+ {
155
+ exportData += Environment . NewLine ;
156
+ exportData += "----------" + delimiter + "----------" ;
157
+ exportData += Environment . NewLine ;
158
+ }
159
+ }
37
160
161
+ Export ( path , exportData ) ;
38
162
}
39
163
}
40
164
}
0 commit comments