protected override async Task <bool> Validate(Dictionary <string, string> paramDictionary) { var errorList = new List <string>(); ProjectResource project = null; if (string.IsNullOrWhiteSpace(paramDictionary["Project"])) { errorList.Add("Please specify the name of the project using the parameter: --project=XYZ"); } else { var projectName = paramDictionary["Project"]; project = await Repository.Projects.FindByName(projectName).ConfigureAwait(false); if (project == null) { errorList.Add("Could not find project named '" + projectName + "'"); } } var releases = FileSystemImporter.Import <List <ReleaseResource> >(FilePath, typeof(ReleaseImporter).GetAttributeValue((ImporterAttribute ia) => ia.EntityType)); if (releases == null) { errorList.Add("Unable to deserialize the specified export file"); } validatedImportSettings = new ValidatedImportSettings { Project = project, Releases = releases, ErrorList = errorList }; if (validatedImportSettings.HasErrors) { Log.Error("The following issues were found with the provided input:"); foreach (var error in validatedImportSettings.ErrorList) { Log.Error(" {Error:l}", error); } } else { Log.Information("No validation errors found. Releases are ready to import."); } return(!validatedImportSettings.HasErrors); }
protected override async Task <bool> Validate(Dictionary <string, string> paramDictionary) { var importedObject = FileSystemImporter.Import <ProjectExport>(FilePath, typeof(ProjectImporter).GetAttributeValue((ImporterAttribute ia) => ia.EntityType)); var project = importedObject.Project; if (new SemanticVersion(Repository.Client.RootDocument.Version) >= new SemanticVersion(2, 6, 0, 0)) { var existingLifecycle = await CheckProjectLifecycle(importedObject.Lifecycle).ConfigureAwait(false); if (existingLifecycle == null) { throw new CommandException("Unable to find a lifecycle to assign to this project."); } Log.Debug("Found lifecycle '{Lifecycle:l}'", existingLifecycle.Name); project.LifecycleId = existingLifecycle.Id; } var variableSet = importedObject.VariableSet; var deploymentProcess = importedObject.DeploymentProcess; var nugetFeeds = importedObject.NuGetFeeds; var actionTemplates = importedObject.ActionTemplates ?? new List <ReferenceDataItem>(); var libVariableSets = importedObject.LibraryVariableSets; var projectGroup = importedObject.ProjectGroup; var channels = importedObject.Channels; var channelLifecycles = importedObject.ChannelLifecycles; var scopeValuesUsed = GetScopeValuesUsed(variableSet.Variables, deploymentProcess.Steps, variableSet.ScopeValues); var environmentChecksTask = CheckEnvironmentsExist(scopeValuesUsed[ScopeField.Environment]).ConfigureAwait(false); var machineChecksTask = CheckMachinesExist(scopeValuesUsed[ScopeField.Machine]).ConfigureAwait(false); var feedChecksTask = CheckNuGetFeedsExist(nugetFeeds).ConfigureAwait(false); var templateChecksTask = CheckActionTemplates(actionTemplates).ConfigureAwait(false); var libraryVariableSetChecksTask = CheckLibraryVariableSets(libVariableSets).ConfigureAwait(false); var projectGroupChecksTask = CheckProjectGroup(projectGroup).ConfigureAwait(false); var channelLifecycleChecksTask = CheckChannelLifecycles(channelLifecycles).ConfigureAwait(false); var environmentChecks = await environmentChecksTask; var machineChecks = await machineChecksTask; var feedChecks = await feedChecksTask; var templateChecks = await templateChecksTask; var libraryVariableSetChecks = await libraryVariableSetChecksTask; var projectGroupChecks = await projectGroupChecksTask; var channelLifecycleChecks = await channelLifecycleChecksTask; var errorList = new List <string>(); errorList.AddRange( environmentChecks.MissingDependencyErrors .Concat(machineChecks.MissingDependencyErrors) .Concat(feedChecks.MissingDependencyErrors) .Concat(templateChecks.MissingDependencyErrors) .Concat(libraryVariableSetChecks.MissingDependencyErrors) .Concat(projectGroupChecks.MissingDependencyErrors) .Concat(channelLifecycleChecks.MissingDependencyErrors) ); validatedImportSettings = new ValidatedImportSettings { Project = project, ProjectGroupId = projectGroupChecks.FoundDependencies.Values.FirstOrDefault()?.Id, LibraryVariableSets = libraryVariableSetChecks.FoundDependencies, Environments = environmentChecks.FoundDependencies, Feeds = feedChecks.FoundDependencies, Templates = templateChecks.FoundDependencies, Machines = machineChecks.FoundDependencies, DeploymentProcess = deploymentProcess, ScopeValuesUsed = scopeValuesUsed, VariableSet = variableSet, Channels = channels, ChannelLifecycles = channelLifecycleChecks.FoundDependencies, ErrorList = errorList }; if (validatedImportSettings.HasErrors) { var errorMessagesCsvString = string.Join(Environment.NewLine, validatedImportSettings.ErrorList); var errorMessage = string.Format($"The following issues were found with the provided import file: {Environment.NewLine}{errorMessagesCsvString}"); throw new CommandException(errorMessage); } else { Log.Information("No validation errors found. Project is ready to import."); } return(!validatedImportSettings.HasErrors); }
protected BaseImporter(IOctopusAsyncRepository repository, IOctopusFileSystem fileSystem, ILogger log) { this.Log = log; this.Repository = repository; FileSystemImporter = new FileSystemImporter(fileSystem, log); }
protected BaseImporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) { this.log = log; this.repository = repository; fileSystemImporter = new FileSystemImporter(fileSystem, log); }