예제 #1
0
        protected override void Import(Dictionary <string, string> paramDictionary)
        {
            var filePath       = paramDictionary["FilePath"];
            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 = CheckProjectLifecycle(importedObject.Lifecycle);
                if (existingLifecycle == null)
                {
                    throw new CommandException("Unable to find a lifecycle to assign to this project.");
                }
                Log.DebugFormat("Found lifecycle '{0}'", 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 scopeValuesUsed = GetScopeValuesUsed(variableSet.Variables, deploymentProcess.Steps, variableSet.ScopeValues);

            // Check Environments
            var environments = CheckEnvironmentsExist(scopeValuesUsed[ScopeField.Environment]);

            // Check Machines
            var machines = CheckMachinesExist(scopeValuesUsed[ScopeField.Machine]);

            // Check Roles
            //var roles = CheckRolesExist(variableSet.ScopeValues.Roles);

            // Check NuGet Feeds
            var feeds = CheckNuGetFeedsExist(nugetFeeds);

            // Check Action Templates
            var templates = CheckActionTemplates(actionTemplates);

            // Check Libary Variable Sets
            var libraryVariableSets = CheckLibraryVariableSets(libVariableSets);

            // Check Project Group
            var projectGroupId = CheckProjectGroup(projectGroup);

            Log.DebugFormat("Beginning import of project '{0}'", project.Name);

            var importedProject = ImportProject(project, projectGroupId, libraryVariableSets);

            ImportDeploymentProcess(deploymentProcess, importedProject, environments, feeds, templates);

            ImportVariableSets(variableSet, importedProject, environments, machines, scopeValuesUsed);

            Log.DebugFormat("Successfully imported project '{0}'", project.Name);
        }
예제 #2
0
        protected override 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 = Repository.Projects.FindByName(projectName);
                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.ErrorFormat(" {0}", error);
                }
            }
            else
            {
                Log.Info("No validation errors found. Releases are ready to import.");
            }

            return(!validatedImportSettings.HasErrors);
        }
예제 #3
0
        protected override void Import(Dictionary <string, string> paramDictionary)
        {
            var filePath       = paramDictionary["FilePath"];
            var importedObject = FileSystemImporter.Import <ProjectExport>(filePath, typeof(ProjectImporter).GetAttributeValue((ImporterAttribute ia) => ia.EntityType));

            var project           = importedObject.Project;
            var variableSet       = importedObject.VariableSet;
            var deploymentProcess = importedObject.DeploymentProcess;
            var nugetFeeds        = importedObject.NuGetFeeds;
            var actionTemplates   = importedObject.ActionTemplates;
            var libVariableSets   = importedObject.LibraryVariableSets;
            var projectGroup      = importedObject.ProjectGroup;

            var scopeValuesUsed = GetScopeValuesUsed(variableSet.Variables, deploymentProcess.Steps, variableSet.ScopeValues);

            // Check Environments
            var environments = CheckEnvironmentsExist(scopeValuesUsed[ScopeField.Environment]);

            // Check Machines
            var machines = CheckMachinesExist(scopeValuesUsed[ScopeField.Machine]);

            // Check Roles
            //var roles = CheckRolesExist(variableSet.ScopeValues.Roles);

            // Check NuGet Feeds
            var feeds = CheckNuGetFeedsExist(nugetFeeds);

            // Check Action Templates
            var templates = CheckActionTemplates(actionTemplates);

            // Check Libary Variable Sets
            var libraryVariableSets = CheckLibraryVariableSets(libVariableSets);

            // Check Project Group
            var projectGroupId = CheckProjectGroup(projectGroup);

            Log.DebugFormat("Beginning import of project '{0}'", project.Name);

            var importedProject = ImportProject(project, projectGroupId, libraryVariableSets);

            ImportDeploymentProcess(deploymentProcess, importedProject, environments, feeds, templates);

            ImportVariableSets(variableSet, importedProject, environments, machines, scopeValuesUsed);

            Log.DebugFormat("Successfully imported project '{0}'", project.Name);
        }
예제 #4
0
        //When importing I think we want to just create a new release, using the NuGet package versions,
        //number and release notes from the exported release
        //we can't import snapshots, so there's no point exporting them
        //instead we'll assume that they have imported the latest project settings and thus the
        //deployment process + variables will be up to date

        protected override void Import(Dictionary <string, string> paramDictionary)
        {
            if (string.IsNullOrWhiteSpace(paramDictionary["Project"]))
            {
                throw new CommandException("Please specify the name of the project using the parameter: --project=XYZ");
            }
            var projectName = paramDictionary["Project"];

            var releases = FileSystemImporter.Import <List <ReleaseResource> >(FilePath, typeof(ReleaseImporter).GetAttributeValue((ImporterAttribute ia) => ia.EntityType));

            if (releases == null)
            {
                throw new CommandException("Unable to deserialize the specified export file");
            }

            var project = Repository.Projects.FindByName(projectName);

            if (project == null)
            {
                throw new CommandException("Could not find project named '" + projectName + "'");
            }

            foreach (var release in releases)
            {
                Log.Debug("Importing release '" + release.Version);
                var existingReleases = Repository.Projects.GetReleases(project);

                if (existingReleases == null || existingReleases.Items.All(rls => rls.Version != release.Version))
                {
                    release.ProjectId = project.Id;
                    Log.Debug("Creating new release '" + release.Version + "' for project " + project.Name);
                    Repository.Releases.Create(release);
                }
                else
                {
                    Log.Debug("Release '" + release.Version + "' already exist for project " + project.Name);
                }
            }

            Log.Debug("Successfully imported releases for project " + project.Name);
        }
예제 #5
0
        protected override 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 = CheckProjectLifecycle(importedObject.Lifecycle);
                if (existingLifecycle == null)
                {
                    throw new CommandException("Unable to find a lifecycle to assign to this project.");
                }
                Log.DebugFormat("Found lifecycle '{0}'", 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 scopeValuesUsed = GetScopeValuesUsed(variableSet.Variables, deploymentProcess.Steps, variableSet.ScopeValues);

            // Check Environments
            var environmentChecks = CheckEnvironmentsExist(scopeValuesUsed[ScopeField.Environment]);

            // Check Machines
            var machineChecks = CheckMachinesExist(scopeValuesUsed[ScopeField.Machine]);

            // Check NuGet Feeds
            var feedChecks = CheckNuGetFeedsExist(nugetFeeds);

            // Check Action Templates
            var templateChecks = CheckActionTemplates(actionTemplates);

            // Check Libary Variable Sets
            var libraryVariableSetChecks = CheckLibraryVariableSets(libVariableSets);

            // Check Project Group
            var projectGroupChecks = CheckProjectGroup(projectGroup);

            var errorList = new List <string>();

            errorList.AddRange(
                environmentChecks.MissingDependencyErrors
                .Concat(machineChecks.MissingDependencyErrors)
                .Concat(feedChecks.MissingDependencyErrors)
                .Concat(templateChecks.MissingDependencyErrors)
                .Concat(libraryVariableSetChecks.MissingDependencyErrors)
                .Concat(projectGroupChecks.MissingDependencyErrors)
                );

            validatedImportSettings = new ValidatedImportSettings
            {
                Project             = project,
                ProjectGroupId      = projectGroupChecks.FoundDependencies.Keys.First(),
                LibraryVariableSets = libraryVariableSetChecks.FoundDependencies,
                Environments        = environmentChecks.FoundDependencies,
                Feeds             = feedChecks.FoundDependencies,
                Templates         = templateChecks.FoundDependencies,
                Machines          = machineChecks.FoundDependencies,
                DeploymentProcess = deploymentProcess,
                ScopeValuesUsed   = scopeValuesUsed,
                VariableSet       = variableSet,
                ErrorList         = errorList
            };

            if (validatedImportSettings.HasErrors)
            {
                Log.Error("The following issues were found with the provided import file:");
                foreach (var error in validatedImportSettings.ErrorList)
                {
                    Log.ErrorFormat(" {0}", error);
                }
            }
            else
            {
                Log.Info("No validation errors found. Project is ready to import.");
            }

            return(!validatedImportSettings.HasErrors);
        }