Skip to content

Commit

Permalink
Merge pull request #3 from 5genesis/csv_replace
Browse files Browse the repository at this point in the history
Csv replace
  • Loading branch information
NaniteBased authored Nov 20, 2020
2 parents a9b81d7 + 28159a5 commit bf592f7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**20/11/2020** [Version 2.0.2]

- Add option for automatically replacing separator character when found within CSV values

**19/10/2020** [Version 2.0.1]

- Fix timing on result retrieval for agent's measurement step
Expand Down
2 changes: 1 addition & 1 deletion Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Main/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $(GitVersion) - Gets the version from Git.
$(GitBranch) - Gets the branch name from Git.
$(GitBranchVersion) - Gets the version number in the recommended format Major.Minor.Build-PreRelease+CommitHash.BranchName.
-->
<Package Name="5Genesis" xmlns="http://opentap.io/schemas/package" InfoLink="https://5genesis.eu/" Version="2.0.1">
<Package Name="5Genesis" xmlns="http://opentap.io/schemas/package" InfoLink="https://5genesis.eu/" Version="2.0.2">
<Description>5Genesis main TAP plugin.</Description>
<Files>
<File Path="5Genesis\Tap.Plugins.5Genesis.Main.dll">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public static string AsString(this CsvSeparator separator)
default: return "\t";
}
}

public static string DefaultReplacement(this CsvSeparator separator)
{
return separator == CsvSeparator.SemiColon ? "," : ";";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,26 @@ public class MultipleCsvResultListener : ConfigurableResultListenerBase
Group: "CSV",
Description: "Select which separator to use in the CSV file.",
Order: 1.0)]
public CsvSeparator Separator { get; set; }
public CsvSeparator Separator {
get { return _separator; }
set {
if (value != _separator)
{
_separator = value;
if (SeparatorReplacement.IsEnabled && SeparatorReplacement.Value.Equals(separator))
{
SeparatorReplacement.Value = _separator.DefaultReplacement();
}
}
}
}
private CsvSeparator _separator;

[Display("File Path", Group: "CSV", Order: 1.1,
[Display("Replace separator with", Group: "CSV", Order: 1.1,
Description: "Replace the separator with this character automatically when found within values")]
public Enabled<string> SeparatorReplacement { get; set; }

[Display("File Path", Group: "CSV", Order: 1.2,
Description: "CSV output path. Available macros are:\n" +
" - Result type: {ResultType} (Mandatory)\n" +
" - Run Identifier: {Identifier} (Mandatory if 'Add Identifier to Results' is enabled)\n" +
Expand All @@ -70,6 +87,7 @@ public MultipleCsvResultListener()
Name = "MultiCSV";

Separator = CsvSeparator.Comma;
SeparatorReplacement = new Enabled<string> { IsEnabled = true, Value = ";" };
FilePath = DEFAULT_FILE_PATH;
ExecutionId = UNDEFINED;

Expand Down Expand Up @@ -141,6 +159,11 @@ public override void OnTestPlanRunCompleted(TestPlanRun planRun, Stream logStrea
// Write the rows of results
foreach (List<string> values in result.RowValues)
{
if (SeparatorReplacement.IsEnabled)
{
for (int i = 0; i < values.Count; i++) { values[i] = values[i].Replace(separator, SeparatorReplacement.Value); }
}

writer.WriteLine(string.Join(separator, values));
}
}
Expand Down

0 comments on commit bf592f7

Please sign in to comment.