Skip to content

Commit 65ebf53

Browse files
committed
♻️ (MigrationTools): refactor exception handling and update XML references
Update the XML documentation to reflect the latest commit and tag information, ensuring that the documentation remains accurate and up-to-date. This change is necessary to maintain consistency with the current state of the codebase. Refactor exception handling in `TfsNodeStructureTool.cs` by introducing an extension method `AsMigrationToolsException`. This improves code readability and reduces redundancy by centralizing the conversion of exceptions to `MigrationToolsException`. The refactoring also removes unused imports and redundant code, streamlining the codebase for better maintainability.
1 parent d589bdd commit 65ebf53

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

docs/Reference/Generated/MigrationTools.xml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.Extensions.Logging;
99
using Microsoft.Extensions.Options;
1010
using Microsoft.TeamFoundation.Common;
11-
using Microsoft.TeamFoundation.Core.WebApi;
1211
using Microsoft.TeamFoundation.Server;
1312
using Microsoft.TeamFoundation.Work.WebApi;
1413
using MigrationTools.Clients;
@@ -56,14 +55,13 @@ public class TfsNodeStructureTool : Tool<TfsNodeStructureToolOptions>
5655
private TfsLanguageMapOptions _sourceLanguageMaps;
5756
private TfsLanguageMapOptions _targetLanguageMaps;
5857

59-
private Microsoft.TeamFoundation.Server.ProjectInfo _sourceProjectInfo;
58+
private ProjectInfo _sourceProjectInfo;
6059

6160
private string _sourceProjectName;
6261
private NodeInfo[] _sourceRootNodes;
6362
private ICommonStructureService4 _targetCommonStructureService;
6463

6564
private string _targetProjectName;
66-
private Microsoft.TeamFoundation.Server.ProjectInfo _targetProjectInfo;
6765
private KeyValuePair<string, string>? _lastResortRemapRule;
6866

6967
public WorkItemMetrics workItemMetrics { get; private set; }
@@ -111,7 +109,7 @@ public string GetNewNodeName(string sourceNodePath, TfsNodeStructureType nodeStr
111109
Log.LogWarning("nodeStructureEnricher is disabled! You may get migration errors!");
112110
return sourceNodePath;
113111
}
114-
var mappers = GetMaps(nodeStructureType);
112+
var mappers = GetMaps(nodeStructureType);
115113
var lastResortRule = GetLastResortRemappingRule();
116114

117115
Log.LogDebug("NodeStructureEnricher.GetNewNodeName::Mappers", mappers);
@@ -315,15 +313,6 @@ protected void EntryForProcessorType(TfsProcessor processor)
315313
_targetCommonStructureService = processor.Target.GetService<ICommonStructureService4>();
316314
_targetLanguageMaps = processor.Target.Options.LanguageMaps;
317315
_targetProjectName = processor.Target.Options.Project;
318-
try
319-
{
320-
_targetProjectInfo = _targetCommonStructureService.GetProjectFromName(_targetProjectName);
321-
}
322-
catch (ProjectException ex)
323-
{
324-
throw new MigrationToolsException(ex, MigrationToolsException.ExceptionSource.Configuration);
325-
}
326-
327316
}
328317
}
329318
}
@@ -415,8 +404,6 @@ private static string GetUserFriendlyPath(string systemNodePath)
415404
private void MigrateAllNodeStructures()
416405
{
417406
Log.LogDebug("NodeStructureEnricher.MigrateAllNodeStructures(@{areaMaps}, @{iterationMaps})", Options.Areas, Options.Iterations);
418-
419-
420407
//////////////////////////////////////////////////
421408
ProcessCommonStructure(_sourceLanguageMaps.AreaPath, _targetLanguageMaps.AreaPath, _targetProjectName, TfsNodeStructureType.Area);
422409
//////////////////////////////////////////////////
@@ -438,9 +425,8 @@ private string GetLocalizedNodeStructureTypeName(TfsNodeStructureType value, Tfs
438425

439426
case TfsNodeStructureType.Iteration:
440427
return languageMap.IterationPath.IsNullOrEmpty() ? "Iteration" : languageMap.IterationPath;
441-
442428
default:
443-
throw new InvalidOperationException("Not a valid NodeStructureType ");
429+
throw new InvalidOperationException("Not a valid NodeStructureType ").AsMigrationToolsException(MigrationToolsException.ExceptionSource.Internal);
444430
}
445431
}
446432

@@ -464,7 +450,7 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT
464450
{
465451
Exception ex = new Exception(string.Format("Unable to load Common Structure for Source. This is usually due to different language versions. Validate that '{0}' is the correct name in your version. ", treeTypeSource));
466452
Log.LogError(ex, "Unable to load Common Structure for Source.");
467-
throw ex;
453+
throw ex.AsMigrationToolsException(MigrationToolsException.ExceptionSource.Configuration);
468454
}
469455
XmlElement sourceTree = _sourceCommonStructureService.GetNodesXml(new string[] { sourceNode.Uri }, true);
470456
NodeInfo structureParent;
@@ -475,9 +461,7 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT
475461
catch (Exception ex)
476462
{
477463
Exception ex2 = new Exception(string.Format("Unable to load Common Structure for Target.This is usually due to TFS having a different installed langauge version than was expected.. Validate that '{0}' is the correct name in your version. This would be something like 'Fläche' or 'Aire'. If you open the area tree in Visual Studio, or web access, you should see the name your langauage uses for 'Area' or 'Iteration. Do not try to add a specific area or iteration path to this field. Check the defaults on https://nkdagility.com/learn/azure-devops-migration-tools/Reference/Endpoints/TfsTeamProjectEndpoint/ for an example fro English.", localizedTreeTypeName), ex);
478-
Log.LogError(ex2, "Unable to load Common Structure for Target.");
479-
Telemetry.TrackException(ex2, null);
480-
throw ex2;
464+
throw ex2.AsMigrationToolsException(MigrationToolsException.ExceptionSource.Configuration);
481465
}
482466

483467
_pathToKnownNodeMap[structureParent.Path] = structureParent;
@@ -751,7 +735,7 @@ public string FixAreaPathAndIterationPathForTargetQuery(string sourceWIQLQuery,
751735
structureType = TfsNodeStructureType.Iteration;
752736
break;
753737
default:
754-
throw new InvalidOperationException($"Field type {fieldType} is not supported for query remapping.");
738+
throw new InvalidOperationException($"Field type {fieldType} is not supported for query remapping.").AsMigrationToolsException(MigrationToolsException.ExceptionSource.Internal);
755739
}
756740

757741
var remappedPath = GetNewNodeName(value, structureType);

src/MigrationTools/Exceptions/MigrationToolsException.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
using System.Collections.Generic;
33
using System.Text;
44
using Elmah.Io.Client;
5+
using static MigrationTools.Exceptions.MigrationToolsException;
56

67
namespace MigrationTools.Exceptions
78
{
8-
9+
10+
public static class MigrationToolsExceptionExtensions
11+
{
12+
public static MigrationToolsException AsMigrationToolsException(this Exception ex, ExceptionSource errorSource)
13+
{
14+
return new MigrationToolsException(ex, errorSource);
15+
}
16+
}
917

1018
public class MigrationToolsException : Exception
1119
{

0 commit comments

Comments
 (0)