From 65ebf5362d5b9bd243f6c5dc952daa1ad7a98180 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 3 Oct 2024 08:38:49 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(MigrationTools):=20refact?= =?UTF-8?q?or=20exception=20handling=20and=20update=20XML=20references?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- docs/Reference/Generated/MigrationTools.xml | 18 ++++++------ .../Tools/TfsNodeStructureTool.cs | 28 ++++--------------- .../Exceptions/MigrationToolsException.cs | 10 ++++++- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/docs/Reference/Generated/MigrationTools.xml b/docs/Reference/Generated/MigrationTools.xml index 8b9e5a25..e4034385 100644 --- a/docs/Reference/Generated/MigrationTools.xml +++ b/docs/Reference/Generated/MigrationTools.xml @@ -263,32 +263,32 @@ - => @"23fae28b" + => @"d589bdde" - => @"23fae28bfbd54ac74475334e64dc733a9fd28131" + => @"d589bdde1734dae65833f224ebccf08406e037b3" - => @"2024-09-24T15:02:38+01:00" + => @"2024-10-03T08:34:11+01:00" - => @"4" + => @"3" - => @"v16.0.4-Preview.5-4-g23fae28b" + => @"v16.0.4-Preview.6-3-gd589bdde" - => @"v16.0.4-Preview.5" + => @"v16.0.4-Preview.6" @@ -318,17 +318,17 @@ - => @"8" + => @"7" - => @"Preview.5" + => @"Preview.6" - => @"-Preview.5" + => @"-Preview.6" diff --git a/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs b/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs index 85ea638c..11382c0c 100644 --- a/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs +++ b/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs @@ -8,7 +8,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.TeamFoundation.Common; -using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.TeamFoundation.Server; using Microsoft.TeamFoundation.Work.WebApi; using MigrationTools.Clients; @@ -56,14 +55,13 @@ public class TfsNodeStructureTool : Tool private TfsLanguageMapOptions _sourceLanguageMaps; private TfsLanguageMapOptions _targetLanguageMaps; - private Microsoft.TeamFoundation.Server.ProjectInfo _sourceProjectInfo; + private ProjectInfo _sourceProjectInfo; private string _sourceProjectName; private NodeInfo[] _sourceRootNodes; private ICommonStructureService4 _targetCommonStructureService; private string _targetProjectName; - private Microsoft.TeamFoundation.Server.ProjectInfo _targetProjectInfo; private KeyValuePair? _lastResortRemapRule; public WorkItemMetrics workItemMetrics { get; private set; } @@ -111,7 +109,7 @@ public string GetNewNodeName(string sourceNodePath, TfsNodeStructureType nodeStr Log.LogWarning("nodeStructureEnricher is disabled! You may get migration errors!"); return sourceNodePath; } - var mappers = GetMaps(nodeStructureType); + var mappers = GetMaps(nodeStructureType); var lastResortRule = GetLastResortRemappingRule(); Log.LogDebug("NodeStructureEnricher.GetNewNodeName::Mappers", mappers); @@ -315,15 +313,6 @@ protected void EntryForProcessorType(TfsProcessor processor) _targetCommonStructureService = processor.Target.GetService(); _targetLanguageMaps = processor.Target.Options.LanguageMaps; _targetProjectName = processor.Target.Options.Project; - try - { - _targetProjectInfo = _targetCommonStructureService.GetProjectFromName(_targetProjectName); - } - catch (ProjectException ex) - { - throw new MigrationToolsException(ex, MigrationToolsException.ExceptionSource.Configuration); - } - } } } @@ -415,8 +404,6 @@ private static string GetUserFriendlyPath(string systemNodePath) private void MigrateAllNodeStructures() { Log.LogDebug("NodeStructureEnricher.MigrateAllNodeStructures(@{areaMaps}, @{iterationMaps})", Options.Areas, Options.Iterations); - - ////////////////////////////////////////////////// ProcessCommonStructure(_sourceLanguageMaps.AreaPath, _targetLanguageMaps.AreaPath, _targetProjectName, TfsNodeStructureType.Area); ////////////////////////////////////////////////// @@ -438,9 +425,8 @@ private string GetLocalizedNodeStructureTypeName(TfsNodeStructureType value, Tfs case TfsNodeStructureType.Iteration: return languageMap.IterationPath.IsNullOrEmpty() ? "Iteration" : languageMap.IterationPath; - default: - throw new InvalidOperationException("Not a valid NodeStructureType "); + throw new InvalidOperationException("Not a valid NodeStructureType ").AsMigrationToolsException(MigrationToolsException.ExceptionSource.Internal); } } @@ -464,7 +450,7 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT { 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)); Log.LogError(ex, "Unable to load Common Structure for Source."); - throw ex; + throw ex.AsMigrationToolsException(MigrationToolsException.ExceptionSource.Configuration); } XmlElement sourceTree = _sourceCommonStructureService.GetNodesXml(new string[] { sourceNode.Uri }, true); NodeInfo structureParent; @@ -475,9 +461,7 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT catch (Exception ex) { 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); - Log.LogError(ex2, "Unable to load Common Structure for Target."); - Telemetry.TrackException(ex2, null); - throw ex2; + throw ex2.AsMigrationToolsException(MigrationToolsException.ExceptionSource.Configuration); } _pathToKnownNodeMap[structureParent.Path] = structureParent; @@ -751,7 +735,7 @@ public string FixAreaPathAndIterationPathForTargetQuery(string sourceWIQLQuery, structureType = TfsNodeStructureType.Iteration; break; default: - throw new InvalidOperationException($"Field type {fieldType} is not supported for query remapping."); + throw new InvalidOperationException($"Field type {fieldType} is not supported for query remapping.").AsMigrationToolsException(MigrationToolsException.ExceptionSource.Internal); } var remappedPath = GetNewNodeName(value, structureType); diff --git a/src/MigrationTools/Exceptions/MigrationToolsException.cs b/src/MigrationTools/Exceptions/MigrationToolsException.cs index 34b663f0..c3c6580c 100644 --- a/src/MigrationTools/Exceptions/MigrationToolsException.cs +++ b/src/MigrationTools/Exceptions/MigrationToolsException.cs @@ -2,10 +2,18 @@ using System.Collections.Generic; using System.Text; using Elmah.Io.Client; +using static MigrationTools.Exceptions.MigrationToolsException; namespace MigrationTools.Exceptions { - + + public static class MigrationToolsExceptionExtensions + { + public static MigrationToolsException AsMigrationToolsException(this Exception ex, ExceptionSource errorSource) + { + return new MigrationToolsException(ex, errorSource); + } + } public class MigrationToolsException : Exception {