From ff01f3d4a57b2ebdf2c1d9bf59da7c3fe6e2fddd Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Fri, 20 Nov 2020 09:16:08 +0100 Subject: [PATCH 1/2] Add option for replacing CSV separator occurences found on values --- .../Enums/CsvSeparatorExtensions.cs | 5 ++++ .../MultipleCsvResultListener.cs | 27 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/Enums/CsvSeparatorExtensions.cs b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/Enums/CsvSeparatorExtensions.cs index eb470cf..5292bc9 100644 --- a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/Enums/CsvSeparatorExtensions.cs +++ b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/Enums/CsvSeparatorExtensions.cs @@ -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 ? "," : ";"; + } } } diff --git a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs index 7180c67..6dda00f 100644 --- a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs +++ b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs @@ -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: "")] + public Enabled 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" + @@ -70,6 +87,7 @@ public MultipleCsvResultListener() Name = "MultiCSV"; Separator = CsvSeparator.Comma; + SeparatorReplacement = new Enabled { IsEnabled = true, Value = ";" }; FilePath = DEFAULT_FILE_PATH; ExecutionId = UNDEFINED; @@ -141,6 +159,11 @@ public override void OnTestPlanRunCompleted(TestPlanRun planRun, Stream logStrea // Write the rows of results foreach (List 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)); } } From 28159a53aaa62d2a579fc0e8c58c055a1c5fc80f Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Fri, 20 Nov 2020 09:19:42 +0100 Subject: [PATCH 2/2] Update description, changelog.Bump version --- CHANGELOG.md | 4 ++++ Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Main/package.xml | 2 +- .../ResultListeners/MultipleCsvResultListener.cs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d0b959..dde1447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Main/package.xml b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Main/package.xml index cdf42f5..fe15782 100644 --- a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Main/package.xml +++ b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Main/package.xml @@ -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. --> - + 5Genesis main TAP plugin. diff --git a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs index 6dda00f..74684e7 100644 --- a/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs +++ b/Tap.Plugins.5Genesis/Tap.Plugins.5Genesis.Misc/ResultListeners/MultipleCsvResultListener.cs @@ -58,7 +58,7 @@ public CsvSeparator Separator { private CsvSeparator _separator; [Display("Replace separator with", Group: "CSV", Order: 1.1, - Description: "")] + Description: "Replace the separator with this character automatically when found within values")] public Enabled SeparatorReplacement { get; set; } [Display("File Path", Group: "CSV", Order: 1.2,