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 _exportModifiers(IModifierExport exporter, string path1, string path2, string symbolSetExpression = "", string expression = "", bool append = false) { // Exports sector one and sector two modifiers to CSV, by optionally testing a // regular expression against the Label attributes of the containing symbol sets // and of the modifiers in those symbol sets. It also allows for appendig the // resulting output to an existing file. // 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. _exportModifier1(exporter, path1, symbolSetExpression, expression, append); _exportModifier2(exporter, path2, symbolSetExpression, expression, append); }
private void _exportModifier2(IModifierExport exporter, string path, string symbolSetExpression = "", string expression = "", bool append = false) { using (var w = new StreamWriter(path, append)) { string line; bool deleteIt = true; // If we're appending this to another file we don't need the // header line added again to that file. if (!append) { 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; if (s.SectorTwoModifiers != null) { deleteIt = false; foreach (ModifiersTypeModifier mod in s.SectorTwoModifiers) { _exportMod(w, s, mod, "2", exporter, expression); } } } w.Close(); if (deleteIt && !append) File.Delete(path); } }
private void _exportMod(StreamWriter w, SymbolSet s, ModifiersTypeModifier mod, string modNumber, IModifierExport exporter, string expression) { string line; if (!(exporter is ImageModifierExport) || mod.ModifierCode.DigitOne != 0 || mod.ModifierCode.DigitTwo != 0) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(mod.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, modNumber, mod)); w.WriteLine(line); w.Flush(); } else if (mod.Category != null) { if (System.Text.RegularExpressions.Regex.IsMatch(mod.Category, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, modNumber, mod)); w.WriteLine(line); w.Flush(); } } } }
private void _exportModifiers(IModifierExport exporter, string path, string symbolSetExpression = "", string expression = "", bool append = false) { // Exports sector one and sector two modifiers to CSV, by optionally testing a // regular expression against the Label attributes of the containing symbol sets // and of the modifiers in those symbol sets. It also allows for appendig the // resulting output to an existing file. // 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, append)) { string line; // If we're appending this to another file we don't need the // header line added again to that file. if (!append) { 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; } if (s.SectorOneModifiers != null) { foreach (ModifiersTypeModifier mod in s.SectorOneModifiers) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(mod.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase) || System.Text.RegularExpressions.Regex.IsMatch(mod.Category, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, "1", mod)); w.WriteLine(line); w.Flush(); } } } if (s.SectorTwoModifiers != null) { foreach (ModifiersTypeModifier mod in s.SectorTwoModifiers) { if (expression == "" || System.Text.RegularExpressions.Regex.IsMatch(mod.Label, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase) || System.Text.RegularExpressions.Regex.IsMatch(mod.Category, expression, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { line = string.Format("{0}", exporter.Line(s, "2", mod)); w.WriteLine(line); w.Flush(); } } } } w.Close(); } }