diff --git a/src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldCalculationMap.cs b/src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldCalculationMap.cs index 53160fa6b..785bd16ce 100644 --- a/src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldCalculationMap.cs +++ b/src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldCalculationMap.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using Microsoft.Extensions.Logging; @@ -82,10 +82,22 @@ internal override void InternalExecute(WorkItem source, WorkItem target) } // Convert field value to numeric - if (!TryConvertToNumeric(fieldValue, out var numericValue)) - { - Log.LogWarning("FieldCalculationMap: Source field '{SourceField}' with value '{FieldValue}' is not numeric on work item {WorkItemId}. Skipping calculation.", parameter.Value, fieldValue, source.Id); - return; + if (!TryConvertToNumeric(fieldValue, out var numericValue)) { + + switch (Config.parsingFallback) { + case FieldCalculationMapParsingFallback.RaiseError: + Log.LogError( + "FieldCalculationMap: Source field '{SourceField}' with value '{FieldValue}' is not numeric on work item {WorkItemId}. Skipping calculation.", + parameter.Value, fieldValue, source.Id); + break; + + case FieldCalculationMapParsingFallback.ResetToZero: + Log.LogWarning( + "FieldCalculationMap: Source field '{SourceField}' with value '{FieldValue}' is not numeric on work item {WorkItemId}. resetting the value to 0.0.", + parameter.Value, fieldValue, source.Id); + numericValue = 0.0; + break; + } } parameterValues[parameter.Key] = numericValue; @@ -216,4 +228,4 @@ private static bool TryConvertToTargetFieldType(object result, Field targetField } } } -} \ No newline at end of file +} diff --git a/src/MigrationTools/Tools/FieldMappingTool/FieldMaps/FieldCalculationMapOptions.cs b/src/MigrationTools/Tools/FieldMappingTool/FieldMaps/FieldCalculationMapOptions.cs index 7a55e8a29..caaaef1e1 100644 --- a/src/MigrationTools/Tools/FieldMappingTool/FieldMaps/FieldCalculationMapOptions.cs +++ b/src/MigrationTools/Tools/FieldMappingTool/FieldMaps/FieldCalculationMapOptions.cs @@ -1,21 +1,31 @@ -using System.Collections.Generic; +using System.Collections.Generic; using MigrationTools.Tools.Infrastructure; -namespace MigrationTools.Tools -{ +namespace MigrationTools.Tools { + public enum FieldCalculationMapParsingFallback { + RaiseError, + ResetToZero + } + /// /// Performs mathematical calculations on numeric fields using NCalc expressions during migration. /// /// ready /// Work Item Field - public class FieldCalculationMapOptions : FieldMapOptions - { + public class FieldCalculationMapOptions : FieldMapOptions { /// /// Gets or sets the NCalc expression to evaluate. Variables in the expression should be enclosed in square brackets (e.g., "[x]*2"). /// /// null public string expression { get; set; } + /// + /// Gets or sets the parsing fallback. + /// + /// null + public FieldCalculationMapParsingFallback parsingFallback { get; set; } = + FieldCalculationMapParsingFallback.RaiseError; + /// /// Gets or sets a dictionary mapping variable names used in the expression to source field reference names. /// @@ -31,23 +41,21 @@ public class FieldCalculationMapOptions : FieldMapOptions /// /// Sets example configuration defaults for documentation purposes. /// - public void SetExampleConfigDefaults() - { + public void SetExampleConfigDefaults() { ApplyTo = new List() { "SomeWorkItemType" }; expression = "[x]*2"; - parameters = new Dictionary - { + parameters = new Dictionary { { "x", "Custom.FieldB" } }; targetField = "Custom.FieldC"; + parsingFallback = FieldCalculationMapParsingFallback.RaiseError; } /// /// Initializes a new instance of the FieldCalculationMapOptions class. /// - public FieldCalculationMapOptions() - { + public FieldCalculationMapOptions() { parameters = new Dictionary(); } } -} \ No newline at end of file +}