diff --git a/configuration.json b/configuration.json index 065a41e21..89fd2514b 100644 --- a/configuration.json +++ b/configuration.json @@ -28,7 +28,7 @@ "Target": { "EndpointType": "TfsTeamProjectEndpoint", "Collection": "https://dev.azure.com/nkdagility-preview/", - "Project": "migrationTest5", + "Project": "migrationTest55", "TfsVersion": "AzureDevOps", "Authentication": { "AuthenticationMode": "AccessToken", diff --git a/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs b/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs index cfc4f8215..85ea638c6 100644 --- a/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs +++ b/src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs @@ -8,12 +8,14 @@ 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; using MigrationTools.DataContracts; using MigrationTools.Endpoints; using MigrationTools.Enrichers; +using MigrationTools.Exceptions; using MigrationTools.FieldMaps; using MigrationTools.Processors; using MigrationTools.Processors.Infrastructure; @@ -54,13 +56,14 @@ public class TfsNodeStructureTool : Tool private TfsLanguageMapOptions _sourceLanguageMaps; private TfsLanguageMapOptions _targetLanguageMaps; - private ProjectInfo _sourceProjectInfo; + private Microsoft.TeamFoundation.Server.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; } @@ -312,6 +315,15 @@ 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); + } + } } } @@ -403,6 +415,8 @@ 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); ////////////////////////////////////////////////// diff --git a/src/MigrationTools/Exceptions/MigrationToolsException.cs b/src/MigrationTools/Exceptions/MigrationToolsException.cs new file mode 100644 index 000000000..34b663f02 --- /dev/null +++ b/src/MigrationTools/Exceptions/MigrationToolsException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Elmah.Io.Client; + +namespace MigrationTools.Exceptions +{ + + + public class MigrationToolsException : Exception + { + public MigrationToolsException(Exception ex, ExceptionSource errorSource) : base(ex.Message) + { + this.ErrorSource = errorSource; + } + + public ExceptionSource ErrorSource { get; } + + public enum ExceptionSource + { + Configuration, + Internal + } + } +} diff --git a/src/MigrationTools/Processors/Infrastructure/Processor.cs b/src/MigrationTools/Processors/Infrastructure/Processor.cs index 14bafe1e6..5ac015ae8 100644 --- a/src/MigrationTools/Processors/Infrastructure/Processor.cs +++ b/src/MigrationTools/Processors/Infrastructure/Processor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.Diagnostics; using System.Linq; using Microsoft.Extensions.DependencyInjection; @@ -64,13 +65,13 @@ public IEndpoint GetEndpoint(string name) { throw new ArgumentException("Endpoint name cannot be null or empty", nameof(name)); } - // Assuming GetRequiredKeyedService throws an exception if the service is not found - IEndpoint endpoint = Services.GetKeyedService(name); - if (endpoint == null) - { - throw new ConfigurationValidationException( Options, ValidateOptionsResult.Fail($"The Endpoint '{name}' specified for `{this.GetType().Name}` was not found.")); - } - return endpoint; + // Assuming GetRequiredKeyedService throws an exception if the service is not found + IEndpoint endpoint = Services.GetKeyedService(name); + if (endpoint == null) + { + throw new ConfigurationValidationException(Options, ValidateOptionsResult.Fail($"The Endpoint '{name}' specified for `{this.GetType().Name}` was not found.")); + } + return endpoint; } public void Execute() @@ -113,12 +114,28 @@ public void Execute() ProcessorActivity.SetStatus(ActivityStatusCode.Error); Log.LogCritical(ex, "Validation of your configuration failed:"); } + catch (MigrationToolsException ex) + { + Status = ProcessingStatus.Failed; + ProcessorActivity.SetStatus(ActivityStatusCode.Error); + switch (ex.ErrorSource) + { + case MigrationToolsException.ExceptionSource.Configuration: + Log.LogCritical(ex, "An error occurred in the Migration Tools causing it to stop! This is likley due to a configuration issue and is not being logged remotely. You can always ask on https://github.com/nkdAgility/azure-devops-migration-tools/discussions "); + break; + case MigrationToolsException.ExceptionSource.Internal: + default: + Log.LogCritical(ex, "An error occurred in the Migration Tools causing it to stop!"); + Telemetry.TrackException(ex, ProcessorActivity.Tags); + break; + } + } catch (Exception ex) { Status = ProcessingStatus.Failed; ProcessorActivity.SetStatus(ActivityStatusCode.Error); - Telemetry.TrackException(ex, ProcessorActivity.Tags); Log.LogCritical(ex, "Error while running {MigrationContextname}", Name); + Telemetry.TrackException(ex, ProcessorActivity.Tags); } finally {