public void Export(string path, string symbolSetExpression = "", string expression = "", bool exportPoints = true, bool exportLines = true, bool exportAreas = true, ETLExportEnum exportType = ETLExportEnum.ETLExportSimple, bool append = false, bool omitSource = false) { // The public entry point for exporting selective contents of the JMSML library // into CSV format. // Accepts a path for the output (sans file name extension). The caller // may also provide optional regular expressions to filter on the Label // attributes of SymbolSets in the library and a second optional regular // expression for filtering on the Label attributes of other objects being // exported. IEntityExport entityExporter = null; IModifierExport modifierExporter = null; string entityPath = path; string modifierPath = path; switch (exportType) { // Based on the type of export, create instances of the // appropriate helper class(es). case ETLExportEnum.ETLExportSimple: entityExporter = new SimpleEntityExport(); modifierExporter = new SimpleModifierExport(); break; case ETLExportEnum.ETLExportDomain: entityExporter = new DomainEntityExport(_configHelper); modifierExporter = new DomainModifierExport(_configHelper); break; case ETLExportEnum.ETLExportImage: entityExporter = new ImageEntityExport(_configHelper, omitSource); modifierExporter = new ImageModifierExport(_configHelper, omitSource); break; } if (entityExporter != null && modifierExporter != null) { if (!append) { // If we're not appending the modifiers to the entities // then add a string to the file name to make them unique. entityPath = entityPath + "_Entities"; modifierPath = modifierPath + "_Modifiers"; } entityPath = entityPath + ".csv"; modifierPath = modifierPath + ".csv"; _exportEntities(entityExporter, entityPath, symbolSetExpression, expression, exportPoints, exportLines, exportAreas); _exportModifiers(modifierExporter, modifierPath, symbolSetExpression, expression, append); } }
private void _exportEntities(ETLExportEnum exportType, IEntityExport exporter, string path, string specialPath, string symbolSetExpression = "", string expression = "", bool exportPoints = true, bool exportLines = true, bool exportAreas = true, bool append = false) { // Exports entity, entity types, and entity sub types to CSV, by optionally testing a // regular expression against the Label attributes of the containing symbol sets // and of the entitites in those symbol sets. It also allows filtering on geometry, // so only point, line, or area symbols can be exported. // This method accepts an exporter, a light weight object that knows what column // headings to return and how to compose a CSV line of output from the data its // provided. using (var w = new StreamWriter(path)) { var line = string.Format("{0}", exporter.Headers); w.WriteLine(line); w.Flush(); // Initialize a counter to track lines written out int rowCount = 0; foreach (SymbolSet s in _symbolSets) { if (symbolSetExpression != "" && !System.Text.RegularExpressions.Regex.IsMatch(s.Label, symbolSetExpression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) continue; foreach (SymbolSetEntity e in s.Entities) { if (!(exporter is ImageEntityExport) || e.EntityCode.DigitOne != 0 || e.EntityCode.DigitTwo != 0) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(e.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (exportPoints && e.GeometryType == GeometryType.POINT || exportLines && e.GeometryType == GeometryType.LINE || exportAreas && e.GeometryType == GeometryType.AREA || (e.EntityCode.DigitOne == 0 && e.EntityCode.DigitTwo == 0)) { // If the icon is Full Frame then four lines need to be exported, to reflect the four icon shapes. // Else just write out one line for non-Full-Frame. if (e.Icon == IconType.FULL_FRAME && exportType == ETLExportEnum.ETLExportImage) { foreach (LibraryStandardIdentityGroup sig in _library.StandardIdentityGroups) { line = string.Format("{0}", exporter.Line(sig, s, e, null, null)); w.WriteLine(line); w.Flush(); rowCount++; } } else { line = string.Format("{0}", exporter.Line(null, s, e, null, null)); w.WriteLine(line); w.Flush(); rowCount++; } } } if (e.EntityTypes != null) { foreach (SymbolSetEntityEntityType eType in e.EntityTypes) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(eType.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (exportPoints && eType.GeometryType == GeometryType.POINT || exportLines && eType.GeometryType == GeometryType.LINE || exportAreas && eType.GeometryType == GeometryType.AREA) { // If the icon is Full Frame then four lines need to be exported, to reflect the four icon shapes. // Else just write out one line for non-Full-Frame. if (eType.Icon == IconType.FULL_FRAME && exportType == ETLExportEnum.ETLExportImage) { foreach (LibraryStandardIdentityGroup sig in _library.StandardIdentityGroups) { line = string.Format("{0}", exporter.Line(sig, s, e, eType, null)); w.WriteLine(line); w.Flush(); rowCount++; } } else { line = string.Format("{0}", exporter.Line(null, s, e, eType, null)); w.WriteLine(line); w.Flush(); rowCount++; } } } if (eType.EntitySubTypes != null) { foreach (EntitySubTypeType eSubType in eType.EntitySubTypes) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(eSubType.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (exportPoints && eSubType.GeometryType == GeometryType.POINT || exportLines && eSubType.GeometryType == GeometryType.LINE || exportAreas && eSubType.GeometryType == GeometryType.AREA) { // If the icon is Full Frame then four lines need to be exported, to reflect the four icon shapes. // Else just write out one line for non-Full-Frame. if (eSubType.Icon == IconType.FULL_FRAME && exportType == ETLExportEnum.ETLExportImage) { foreach (LibraryStandardIdentityGroup sig in _library.StandardIdentityGroups) { line = string.Format("{0}", exporter.Line(sig, s, e, eType, eSubType)); w.WriteLine(line); w.Flush(); rowCount++; } } else { line = string.Format("{0}", exporter.Line(null, s, e, eType, eSubType)); w.WriteLine(line); w.Flush(); rowCount++; } } } } } } } } } // Now process through any special entity sub types that might exist in a symbol set if (s.SpecialEntitySubTypes != null && !(exporter is DomainEntityExport)) { _exportSpecialEntities(exportType, exporter, s, w, s.SpecialEntitySubTypes); } else if (s.SpecialEntitySubTypes != null) { if (!append) { StreamWriter ws = new StreamWriter(specialPath); line = string.Format("{0}", exporter.Headers); ws.WriteLine(line); ws.Flush(); _exportSpecialEntities(exportType, exporter, s, ws, s.SpecialEntitySubTypes); ws.Close(); } else _exportSpecialEntities(exportType, exporter, s, w, s.SpecialEntitySubTypes); } } w.Close(); if (rowCount == 0) { // Empty file so delete it logger.Warn("Empty " + path + ". Deleting file..."); File.Delete(path); } } }
private void _exportSpecialEntities(ETLExportEnum exportType, IEntityExport exporter, SymbolSet s, StreamWriter w, EntitySubTypeType[] array) { // Exports special entities to a CSV file string line = ""; if (array != null) { foreach (EntitySubTypeType eSubType in array) { if (eSubType.Icon == IconType.SPECIAL && exportType == ETLExportEnum.ETLExportImage) { foreach (LibraryStandardIdentityGroup sig in _library.StandardIdentityGroups) { line = string.Format("{0}", exporter.Line(sig, s, eSubType)); w.WriteLine(line); w.Flush(); } } else { if (exportType == ETLExportEnum.ETLExportDomain) line = string.Format("{0}", exporter.Line(eSubType)); else line = string.Format("{0}", exporter.Line(null, s, eSubType)); w.WriteLine(line); w.Flush(); } } } }
string IEntityExport.Line(LibraryStandardIdentityGroup sig, SymbolSet ss, EntitySubTypeType eSubType) { IEntityExport iEx = this; return(iEx.Line(sig, ss, null, null, eSubType)); }
private void _exportEntities(IEntityExport exporter, string path, string symbolSetExpression = "", string expression = "", bool exportPoints = true, bool exportLines = true, bool exportAreas = true) { // Exports entity, entity types, and entity sub types to CSV, by optionally testing a // regular expression against the Label attributes of the containing symbol sets // and of the entitites in those symbol sets. It also allows filtering on geometry, // so only point, line, or area symbols can be exported. // This method accepts an exporter, a light weight object that knows what column // headings to return and how to compose a CSV line of output from the data its // provided. using (var w = new StreamWriter(path)) { var line = string.Format("{0}", exporter.Headers); w.WriteLine(line); w.Flush(); foreach (SymbolSet s in _symbolSets) { if (symbolSetExpression != "" && !System.Text.RegularExpressions.Regex.IsMatch(s.Label, symbolSetExpression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { continue; } foreach (SymbolSetEntity e in s.Entities) { if (exportPoints && e.GeometryType == GeometryType.POINT || exportLines && e.GeometryType == GeometryType.LINE || exportAreas && e.GeometryType == GeometryType.AREA || e.GeometryType == GeometryType.NA) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(e.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, e, null, null)); w.WriteLine(line); w.Flush(); } if (e.EntityTypes != null) { foreach (SymbolSetEntityEntityType eType in e.EntityTypes) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(eType.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, e, eType, null)); w.WriteLine(line); w.Flush(); } if (eType.EntitySubTypes != null) { foreach (SymbolSetEntityEntityTypeEntitySubType eSubType in eType.EntitySubTypes) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(eSubType.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, e, eType, eSubType)); w.WriteLine(line); w.Flush(); } } } } } } } } w.Close(); } }