Skip to content

Commit b96e38c

Browse files
committed
♻️ (StringManipulatorTool): refactor to add default manipulator if none are configured
🔧 (appsettings.json): remove default manipulator configuration Remove the default manipulator configuration from `appsettings.json` to allow for more dynamic configuration. The code now checks if manipulators are configured; if not, it adds a default manipulator programmatically. This change enhances flexibility by allowing the application to operate with a default manipulator without requiring explicit configuration in the settings file.
1 parent e79d28b commit b96e38c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

appsettings.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,7 @@
150150
"StringManipulatorTool": {
151151
"Enabled": true,
152152
"MaxStringLength": 1000000,
153-
"Manipulators": [
154-
{
155-
"$type": "RegexStringManipulator",
156-
"Enabled": true,
157-
"Pattern": "[^( -~)\n\r\t]+",
158-
"Replacement": "",
159-
"Description": "Remove invalid characters from the end of the string"
160-
}
161-
]
153+
"Manipulators": []
162154
},
163155
"TfsUserMappingTool": {
164156
"Enabled": false,

src/MigrationTools/Tools/StringManipulatorTool.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
3434
}
3535
if (fieldItem.FieldType == "String" && fieldItem.Value != null)
3636
{
37-
if (HasManipulators())
37+
if (!HasManipulators())
3838
{
39-
foreach (var manipulator in Options.Manipulators)
39+
AddDefaultManipulator();
40+
}
41+
foreach (var manipulator in Options.Manipulators)
4042
{
4143
if (manipulator.Enabled)
4244
{
@@ -49,7 +51,7 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
4951
Log.LogDebug("{WorkItemProcessorEnricher}::ProcessorExecutionWithFieldItem::Disabled::{Description}", GetType().Name, manipulator.Description);
5052
}
5153
}
52-
}
54+
5355
if (HasStringTooLong(fieldItem))
5456
{
5557
fieldItem.Value = fieldItem.Value.ToString().Substring(0, Math.Min(fieldItem.Value.ToString().Length, Options.MaxStringLength));
@@ -58,6 +60,15 @@ public void ProcessorExecutionWithFieldItem(IProcessor processor, FieldItem fiel
5860

5961
}
6062

63+
private void AddDefaultManipulator()
64+
{
65+
if (Options.Manipulators == null)
66+
{
67+
Options.Manipulators = new List<RegexStringManipulator>();
68+
}
69+
Options.Manipulators.Add(new RegexStringManipulator() { Enabled = true, Description = "Default: Removes invalid chars!", Pattern = "[^( -~)\n\r\t]+", Replacement = "" });
70+
}
71+
6172
private bool HasStringTooLong(FieldItem fieldItem)
6273
{
6374
return fieldItem.Value.ToString().Length > 0 && fieldItem.Value.ToString().Length > Options.MaxStringLength;

0 commit comments

Comments
 (0)