|
21 | 21 | namespace ECoreNetto.Extensions
|
22 | 22 | {
|
23 | 23 | using System;
|
| 24 | + using System.Collections.Generic; |
24 | 25 | using System.Data;
|
25 | 26 | using System.Diagnostics;
|
26 | 27 | using System.IO;
|
27 | 28 | using System.Linq;
|
28 | 29 |
|
29 | 30 | using ClosedXML.Excel;
|
30 | 31 |
|
31 |
| - using ECoreNetto.Resource; |
32 |
| - |
33 | 32 | using Microsoft.Extensions.Logging;
|
34 | 33 | using Microsoft.Extensions.Logging.Abstractions;
|
35 | 34 |
|
@@ -86,114 +85,185 @@ public void GenerateReport(FileInfo modelPath, FileInfo outputPath)
|
86 | 85 |
|
87 | 86 | using (var workbook = new XLWorkbook())
|
88 | 87 | {
|
89 |
| - this.logger.LogDebug("Add EClass reports"); |
| 88 | + this.AddClassSheet(workbook, packages); |
| 89 | + |
| 90 | + this.AddEnumSheet(workbook, packages); |
| 91 | + |
| 92 | + this.AddEDataTypeSheet(workbook, packages); |
| 93 | + |
| 94 | + this.logger.LogInformation("Saving report file to {0}", outputPath.FullName); |
| 95 | + |
| 96 | + workbook.SaveAs(outputPath.FullName); |
| 97 | + } |
| 98 | + |
| 99 | + this.logger.LogInformation("Generated Excel report tables in {0} [ms]", sw.ElapsedMilliseconds); |
| 100 | + } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Adds a worksheet to the workbook with EClass data |
| 104 | + /// </summary> |
| 105 | + /// <param name="workbook"> |
| 106 | + /// The target <see cref="XLWorkbook"/> to which the EClass worksheet is added |
| 107 | + /// </param> |
| 108 | + /// <param name="packages"> |
| 109 | + /// The <see cref="EPackage"/>s that contain the EClass instances to report on |
| 110 | + /// </param> |
| 111 | + private void AddClassSheet(XLWorkbook workbook, IEnumerable<EPackage> packages) |
| 112 | + { |
| 113 | + this.logger.LogDebug("Add EClass reports"); |
90 | 114 |
|
91 |
| - var classWorksheet = workbook.Worksheets.Add("Classes"); |
| 115 | + var classWorksheet = workbook.Worksheets.Add("EClass"); |
92 | 116 |
|
93 |
| - var dataTable = new DataTable(); |
| 117 | + var dataTable = new DataTable(); |
94 | 118 |
|
95 |
| - dataTable.Columns.Add("Class", typeof(string)); |
96 |
| - dataTable.Columns.Add("Feature", typeof(string)); |
97 |
| - dataTable.Columns.Add("EType", typeof(string)); |
98 |
| - dataTable.Columns.Add("Multiplicity", typeof(string)); |
99 |
| - dataTable.Columns.Add("IsContainment", typeof(string)); |
100 |
| - dataTable.Columns.Add("Documentation", typeof(string)); |
| 119 | + dataTable.Columns.Add("Class", typeof(string)); |
| 120 | + dataTable.Columns.Add("Feature", typeof(string)); |
| 121 | + dataTable.Columns.Add("EType", typeof(string)); |
| 122 | + dataTable.Columns.Add("Multiplicity", typeof(string)); |
| 123 | + dataTable.Columns.Add("IsContainment", typeof(string)); |
| 124 | + dataTable.Columns.Add("Documentation", typeof(string)); |
101 | 125 |
|
102 |
| - foreach (var package in packages) |
| 126 | + foreach (var package in packages) |
| 127 | + { |
| 128 | + foreach (var eClass in package.EClassifiers.OfType<EClass>().OrderBy(x => x.Name)) |
103 | 129 | {
|
104 |
| - foreach (var eClass in package.EClassifiers.OfType<EClass>().OrderBy(x => x.Name)) |
| 130 | + var classDataRow = dataTable.NewRow(); |
| 131 | + classDataRow["Class"] = eClass.Name; |
| 132 | + classDataRow["Feature"] = "--"; |
| 133 | + classDataRow["EType"] = "--"; |
| 134 | + classDataRow["Multiplicity"] = "--"; |
| 135 | + classDataRow["IsContainment"] = "--"; |
| 136 | + classDataRow["Documentation"] = eClass.QueryRawDocumentation(); |
| 137 | + dataTable.Rows.Add(classDataRow); |
| 138 | + |
| 139 | + foreach (var structuralFeature in eClass.EStructuralFeatures) |
105 | 140 | {
|
106 |
| - var classDataRow = dataTable.NewRow(); |
107 |
| - classDataRow["Class"] = eClass.Name; |
108 |
| - classDataRow["Feature"] = "--"; |
109 |
| - classDataRow["EType"] = "--"; |
110 |
| - classDataRow["Multiplicity"] = "--"; |
111 |
| - classDataRow["IsContainment"] = "--"; |
112 |
| - classDataRow["Documentation"] = eClass.QueryRawDocumentation(); |
113 |
| - dataTable.Rows.Add(classDataRow); |
114 |
| - |
115 |
| - foreach (var structuralFeature in eClass.EStructuralFeatures) |
| 141 | + if (structuralFeature.Derived || structuralFeature.Transient) |
116 | 142 | {
|
117 |
| - if (structuralFeature.Derived || structuralFeature.Transient) |
118 |
| - { |
119 |
| - continue; |
120 |
| - } |
121 |
| - |
122 |
| - var structuralFeatureDataRow = dataTable.NewRow(); |
123 |
| - structuralFeatureDataRow["Class"] = eClass.Name; |
124 |
| - structuralFeatureDataRow["Feature"] = structuralFeature.Name; |
125 |
| - structuralFeatureDataRow["EType"] = structuralFeature.EType.Name; |
126 |
| - structuralFeatureDataRow["Multiplicity"] = $"{structuralFeature.LowerBound}:{structuralFeature.UpperBound}"; |
127 |
| - structuralFeatureDataRow["IsContainment"] = structuralFeature.QueryIsContainment(); |
128 |
| - structuralFeatureDataRow["Documentation"] = structuralFeature.QueryRawDocumentation(); |
129 |
| - |
130 |
| - dataTable.Rows.Add(structuralFeatureDataRow); |
| 143 | + continue; |
131 | 144 | }
|
| 145 | + |
| 146 | + var structuralFeatureDataRow = dataTable.NewRow(); |
| 147 | + structuralFeatureDataRow["Class"] = eClass.Name; |
| 148 | + structuralFeatureDataRow["Feature"] = structuralFeature.Name; |
| 149 | + structuralFeatureDataRow["EType"] = structuralFeature.EType.Name; |
| 150 | + structuralFeatureDataRow["Multiplicity"] = $"{structuralFeature.LowerBound}:{structuralFeature.UpperBound}"; |
| 151 | + structuralFeatureDataRow["IsContainment"] = structuralFeature.QueryIsContainment(); |
| 152 | + structuralFeatureDataRow["Documentation"] = structuralFeature.QueryRawDocumentation(); |
| 153 | + |
| 154 | + dataTable.Rows.Add(structuralFeatureDataRow); |
132 | 155 | }
|
133 | 156 | }
|
| 157 | + } |
134 | 158 |
|
135 |
| - classWorksheet.Cell(1, 1).InsertTable(dataTable, "Classes", true); |
| 159 | + classWorksheet.Cell(1, 1).InsertTable(dataTable, "Classes", true); |
136 | 160 |
|
137 |
| - try { |
138 |
| - classWorksheet.Rows().AdjustToContents(); |
139 |
| - classWorksheet.Columns().AdjustToContents(); |
140 |
| - } |
141 |
| - catch (Exception e) |
142 |
| - { |
143 |
| - Console.WriteLine("Problem loading fonts {0}", e); |
144 |
| - } |
| 161 | + this.FormatSheet(classWorksheet); |
| 162 | + } |
145 | 163 |
|
146 |
| - var enumWorksheet = workbook.Worksheets.Add("Enums"); |
| 164 | + /// <summary> |
| 165 | + /// Adds a worksheet to the workbook with EEnum data |
| 166 | + /// </summary> |
| 167 | + /// <param name="workbook"> |
| 168 | + /// The target <see cref="XLWorkbook"/> to which the EEnum worksheet is added |
| 169 | + /// </param> |
| 170 | + /// <param name="packages"> |
| 171 | + /// The <see cref="EPackage"/>s that contain the EEnum instances to report on |
| 172 | + /// </param> |
| 173 | + private void AddEnumSheet(XLWorkbook workbook, IEnumerable<EPackage> packages) |
| 174 | + { |
| 175 | + var enumWorksheet = workbook.Worksheets.Add("EEnum"); |
147 | 176 |
|
148 |
| - this.logger.LogDebug("Add EEnum reports"); |
| 177 | + this.logger.LogDebug("Add EEnum reports"); |
149 | 178 |
|
150 |
| - dataTable = new DataTable(); |
| 179 | + var dataTable = new DataTable(); |
151 | 180 |
|
152 |
| - dataTable.Columns.Add("Enum", typeof(string)); |
153 |
| - dataTable.Columns.Add("Literal", typeof(string)); |
154 |
| - dataTable.Columns.Add("Documentation", typeof(string)); |
| 181 | + dataTable.Columns.Add("Enum", typeof(string)); |
| 182 | + dataTable.Columns.Add("Literal", typeof(string)); |
| 183 | + dataTable.Columns.Add("Documentation", typeof(string)); |
155 | 184 |
|
156 |
| - foreach (var package in packages) |
| 185 | + foreach (var package in packages) |
| 186 | + { |
| 187 | + foreach (var eEnum in package.EClassifiers.OfType<EEnum>().OrderBy(x => x.Name)) |
157 | 188 | {
|
158 |
| - foreach (var eEnum in package.EClassifiers.OfType<EEnum>().OrderBy(x => x.Name)) |
159 |
| - { |
160 |
| - var enumDataRow = dataTable.NewRow(); |
161 |
| - enumDataRow["Enum"] = eEnum.Name; |
162 |
| - enumDataRow["Literal"] = "--"; |
163 |
| - enumDataRow["Documentation"] = eEnum.QueryRawDocumentation(); |
164 |
| - dataTable.Rows.Add(enumDataRow); |
| 189 | + var enumDataRow = dataTable.NewRow(); |
| 190 | + enumDataRow["Enum"] = eEnum.Name; |
| 191 | + enumDataRow["Literal"] = "--"; |
| 192 | + enumDataRow["Documentation"] = eEnum.QueryRawDocumentation(); |
| 193 | + dataTable.Rows.Add(enumDataRow); |
165 | 194 |
|
166 |
| - foreach (var eEnumLiteral in eEnum.ELiterals) |
167 |
| - { |
168 |
| - var eEnumLiteralRow = dataTable.NewRow(); |
169 |
| - eEnumLiteralRow["Enum"] = eEnum.Name; |
170 |
| - eEnumLiteralRow["Literal"] = eEnumLiteral.Name; |
171 |
| - eEnumLiteralRow["Documentation"] = eEnumLiteral.QueryRawDocumentation(); |
172 |
| - dataTable.Rows.Add(eEnumLiteralRow); |
173 |
| - } |
| 195 | + foreach (var eEnumLiteral in eEnum.ELiterals) |
| 196 | + { |
| 197 | + var eEnumLiteralRow = dataTable.NewRow(); |
| 198 | + eEnumLiteralRow["Enum"] = eEnum.Name; |
| 199 | + eEnumLiteralRow["Literal"] = eEnumLiteral.Name; |
| 200 | + eEnumLiteralRow["Documentation"] = eEnumLiteral.QueryRawDocumentation(); |
| 201 | + dataTable.Rows.Add(eEnumLiteralRow); |
174 | 202 | }
|
175 | 203 | }
|
| 204 | + } |
| 205 | + |
| 206 | + enumWorksheet.Cell(1, 1).InsertTable(dataTable, "Enums", true); |
| 207 | + |
| 208 | + this.FormatSheet(enumWorksheet); |
| 209 | + } |
| 210 | + |
| 211 | + /// <summary> |
| 212 | + /// Adds a worksheet to the workbook with EDataType data |
| 213 | + /// </summary> |
| 214 | + /// <param name="workbook"> |
| 215 | + /// The target <see cref="XLWorkbook"/> to which the EDataType worksheet is added |
| 216 | + /// </param> |
| 217 | + /// <param name="packages"> |
| 218 | + /// The <see cref="EPackage"/>s that contain the EDataType instances to report on |
| 219 | + /// </param> |
| 220 | + private void AddEDataTypeSheet(XLWorkbook workbook, IEnumerable<EPackage> packages) |
| 221 | + { |
| 222 | + var dataTypeWorksheet = workbook.Worksheets.Add("EDataType"); |
| 223 | + |
| 224 | + this.logger.LogDebug("Add EDataType reports"); |
176 | 225 |
|
177 |
| - enumWorksheet.Cell(1, 1).InsertTable(dataTable, "Enums", true); |
| 226 | + var dataTable = new DataTable(); |
178 | 227 |
|
179 |
| - try |
| 228 | + dataTable.Columns.Add("DataType", typeof(string)); |
| 229 | + dataTable.Columns.Add("Documentation", typeof(string)); |
| 230 | + |
| 231 | + foreach (var package in packages) |
| 232 | + { |
| 233 | + foreach (var eDataType in package.EClassifiers |
| 234 | + .OfType<EDataType>() |
| 235 | + .Where(x => !(x is EEnum)) |
| 236 | + .OrderBy(x => x.Name)) |
180 | 237 | {
|
181 |
| - enumWorksheet.Rows().AdjustToContents(); |
182 |
| - enumWorksheet.Columns().AdjustToContents(); |
| 238 | + var dataTypeRow = dataTable.NewRow(); |
| 239 | + dataTypeRow["DataType"] = eDataType.Name; |
| 240 | + dataTypeRow["Documentation"] = eDataType.QueryRawDocumentation(); |
| 241 | + dataTable.Rows.Add(dataTypeRow); |
183 | 242 | }
|
184 |
| - catch (Exception e) |
185 |
| - { |
186 |
| - Console.WriteLine("Problem loading fonts {0}", e); |
| 243 | + } |
187 | 244 |
|
188 |
| - this.logger.LogWarning("Problem loading fonts when adjusting to contents {0}", e); |
189 |
| - } |
| 245 | + dataTypeWorksheet.Cell(1, 1).InsertTable(dataTable, "DataTypes", true); |
190 | 246 |
|
191 |
| - this.logger.LogInformation("Saving report file to {0}", outputPath.FullName); |
| 247 | + this.FormatSheet(dataTypeWorksheet); |
| 248 | + } |
192 | 249 |
|
193 |
| - workbook.SaveAs(outputPath.FullName); |
| 250 | + /// <summary> |
| 251 | + /// Format the provided sheet |
| 252 | + /// </summary> |
| 253 | + /// <param name="worksheet"> |
| 254 | + /// The <see cref="IXLWorksheet"/> that is to be formatted |
| 255 | + /// </param> |
| 256 | + private void FormatSheet(IXLWorksheet worksheet) |
| 257 | + { |
| 258 | + try |
| 259 | + { |
| 260 | + worksheet.Rows().AdjustToContents(); |
| 261 | + worksheet.Columns().AdjustToContents(); |
| 262 | + } |
| 263 | + catch (Exception e) |
| 264 | + { |
| 265 | + this.logger.LogWarning("Problem loading fonts when adjusting to contents {0}", e); |
194 | 266 | }
|
195 |
| - |
196 |
| - this.logger.LogInformation("Generated Excel report tables in {0} [ms]", sw.ElapsedMilliseconds); |
197 | 267 | }
|
198 | 268 |
|
199 | 269 | /// <summary>
|
|
0 commit comments