예제 #1
0
            public static Project Create(string organizationExternalId, string name, string description,
                                         ProjectType projectType, Guid organizationCMSId, Guid?organizationCPSId, Guid?projectTemplateId, string agentPoolId,
                                         ProjectVisibility projectVisibility, CloudProviderService cloudProviderService, ConfigurationManagementService configurationManagementService, string createdBy)
            {
                var entity = new Project()
                {
                    Name                   = name,
                    InternalName           = name.Replace(".", "").Replace("_", ""),
                    OrganizationExternalId = organizationExternalId,
                    Description            = description,
                    ProjectType            = projectType,
                    OrganizationCMSId      = organizationCMSId,
                    OrganizationCPSId      = organizationCPSId,
                    ProjectTemplateId      = projectTemplateId,
                    AgentPoolId            = agentPoolId,
                    ProjectVisibility      = projectVisibility,
                    OwnerId                = createdBy,
                    CreatedBy              = createdBy
                };

                var validationResult = new DataValidatorManager <Project>().Build().Validate(entity);

                if (!validationResult.IsValid)
                {
                    throw new ApplicationException(validationResult.Errors);
                }

                entity.GrantUserAccess(createdBy, PipelineRole.ProjectAdmin);

                //add activities
                entity.AddActivity(nameof(DomainConstants.Activities.PRCRBA), DomainConstants.Activities.PRCRBA);
                if (cloudProviderService == CloudProviderService.AWS)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PREXBA), DomainConstants.Activities.PREXBA);
                }
                else if (cloudProviderService == CloudProviderService.Azure)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PREXBO), DomainConstants.Activities.PREXBO);
                }

                if (configurationManagementService == ConfigurationManagementService.GitLab)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PREXGL), DomainConstants.Activities.PREXGL);
                }

                entity.AddActivity(nameof(DomainConstants.Activities.PRCLEP), DomainConstants.Activities.PRCLEP);
                entity.AddActivity(nameof(DomainConstants.Activities.PRGTEP), DomainConstants.Activities.PRGTEP);
                entity.AddActivity(nameof(DomainConstants.Activities.PRACBA), DomainConstants.Activities.PRACBA);
                if (projectTemplateId.HasValue)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PRSTPT), DomainConstants.Activities.PRSTPT);
                }

                return(entity);
            }