1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
3- using MemPlus . Classes . RAM . ViewModels ;
44
55namespace MemPlus . Classes . RAM
66{
@@ -9,6 +9,11 @@ namespace MemPlus.Classes.RAM
99 /// </summary>
1010 internal static class RamDataExporter
1111 {
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>
1217 private static void Export ( string path , string data )
1318 {
1419 using ( StreamWriter sw = new StreamWriter ( path ) )
@@ -17,24 +22,143 @@ private static void Export(string path, string data)
1722 }
1823 }
1924
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>
2030 internal static void ExportText ( string path , List < RamStick > ramSticks )
2131 {
32+ string exportData = "MemPlus - Ram Analyzer Data (" + DateTime . Now + ")" ;
33+ exportData += Environment . NewLine ;
34+ exportData += "---" ;
35+ exportData += Environment . NewLine ;
2236
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 ) ;
2359 }
2460
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>
2566 internal static void ExportHtml ( string path , List < RamStick > ramSticks )
2667 {
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>" ;
27106
107+ Export ( path , exportData ) ;
28108 }
29109
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>
30115 internal static void ExportCsv ( string path , List < RamStick > ramSticks )
31116 {
32-
117+ ExportDelimiter ( path , "," , ramSticks ) ;
33118 }
34119
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>
35125 internal static void ExportExcel ( string path , List < RamStick > ramSticks )
36126 {
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+ }
37160
161+ Export ( path , exportData ) ;
38162 }
39163 }
40164}
0 commit comments