private static void RunStartupFunctions(ProjectManifest projectManifest, AssemblyLoadSystem als, Game game) { foreach (var function in projectManifest.GameStartupFunctions) { Type t; if (!als.TryGetType(function.TypeName, out t)) { t = Type.GetType(function.TypeName); if (t == null) { throw new InvalidOperationException("Invalid type name listed in project manifest's startup functions: " + function.TypeName); } } MethodInfo mi = t.GetMethod(function.MethodName); if (mi == null) { throw new InvalidOperationException("Invalid method name listed in startup function for type " + function.TypeName + ". Function name = " + function.MethodName); } var parameters = mi.GetParameters(); if (parameters.Length != 1 || parameters[0].ParameterType != typeof(Game)) { throw new InvalidOperationException("Startup function must be a static method accepting one parameter of type Engine.Game"); } mi.Invoke(null, new[] { game }); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override bool ValidateParameters() { try { // // Validate the target AndroidManifest input is at least parsable. // string sourcePath = ProjectManifest.GetMetadata("FullPath"); var sourceManifest = new AndroidManifest(sourcePath); } catch (Exception e) { Log.LogErrorFromException(e, true); return(false); } var inputFiles = new List <ITaskItem>(); inputFiles.Add(ProjectManifest); if (IncludeJarOrZip != null) { inputFiles.AddRange(IncludeJarOrZip); } InputFiles = inputFiles.ToArray(); return(base.ValidateParameters()); }
private async Task <Tuple <Waddle.Dtos.Project, bool> > EnsureProjectExistsAsync( ProjectManifest manifest, Waddle.ProjectService projectService, ProcessTemplate tempalte) { var projectCreatedJIT = false; var projects = await projectService.GetProjectsAsync(); var project = projects.Value.FirstOrDefault(p => p.Name.Equals(manifest.Metadata.Name, StringComparison.OrdinalIgnoreCase)); if (project == null) { await projectService.CreateProjectAsync( manifest.Metadata.Name, tempalte, manifest.Template.SourceControlType, manifest.Metadata.Description); projectCreatedJIT = true; Logger.StatusBegin("Waiting on project creation..."); while (project == null) { projects = await projectService.GetProjectsAsync(); project = projects.Value.FirstOrDefault(p => p.Name.Equals(manifest.Metadata.Name, StringComparison.OrdinalIgnoreCase)); } Logger.StatusEndSuccess("Succeed"); } else { Logger.Message($"{project.Name} already exists..."); } return(new Tuple <Waddle.Dtos.Project, bool>(project, projectCreatedJIT)); }
private void SaveProjectManifest(ProjectManifest manifest, Purl path) { using (StreamWriter stream = new StreamWriter(_fileSystem.CreateFile(path.AsString))) { stream.Write(_serializer.Serialize(manifest)); } }
protected Compilation LoadProject(string projectPath, List <SyntaxTree> syntaxTrees, string sourceCode, string sourcePath, out SyntaxTree sourceSyntaxTree) { //load all syntax trees syntaxTrees.Clear(); this.LoadProjectALFiles(projectPath, syntaxTrees, sourceCode, sourcePath, out sourceSyntaxTree); List <Diagnostic> diagnostics = new List <Diagnostic>(); //load project manifest string projectFile = Path.Combine(projectPath, "app.json"); ProjectManifest manifest = ProjectManifest.ReadFromString(projectFile, File.ReadAllText(projectFile), diagnostics); //create compilation Compilation compilation = Compilation.Create("MyCompilation", manifest.AppManifest.AppPublisher, manifest.AppManifest.AppVersion, manifest.AppManifest.AppId, null, syntaxTrees, new CompilationOptions()); LocalCacheSymbolReferenceLoader referenceLoader = this.SafeCreateLocalCacheSymbolReferenceLoader(Path.Combine(projectPath, ".alpackages")); compilation = compilation .WithReferenceLoader(referenceLoader) .WithReferences(manifest.GetAllReferences()); return(compilation); }
protected async Task ProcessPermissionsAsync( ProjectManifest manifest, ProjectService projectService, Tuple <Kdoctl.CliServices.AzDoServices.Dtos.Project, bool> outcome) { if (manifest.Permissions != null && manifest.Permissions.Any()) { var gService = GetGraphService(); var allUsers = await gService.ListUsersAsync(); var projectId = outcome.Item1.Id; foreach (var permissionEntry in manifest.Permissions) { if (!string.IsNullOrWhiteSpace(permissionEntry.Name) && permissionEntry.Membership != null) { var projectGroups = await gService.ListGroupsInProjectAsync(projectId); if (projectGroups != null) { var targetGroup = projectGroups .FirstOrDefault(pg => pg.DisplayName.Equals(permissionEntry.Name, StringComparison.OrdinalIgnoreCase)); if (targetGroup != null) { await ApplyGroupPermissionsAsync(gService, allUsers, projectId, permissionEntry, targetGroup); } } } } } }
public void Fail_InvalidVersionBuild() { // Setup var xml = XmlGenerators.ProjectManifestFile(ProtectionLevel.DontSaveSensitive, 1, 1, Fakes.RandomString(), 1, Fakes.RandomString(), new string[] { }, new string[] { }, new ParameterSetupData[] { }); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var versionBuildNode = xmlDoc.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionBuild\"]", xmlDoc.GetNameSpaceManager()); if (versionBuildNode != null) { versionBuildNode.InnerText = Fakes.RandomString(); } ; File.WriteAllText(path, xmlDoc.OuterXml); // Execute var projectManifest = new ProjectManifest(); var exception = Record.Exception(() => projectManifest.Initialize(path, null)); // Assert Assert.NotNull(exception); Assert.IsType <InvalidXmlException>(exception); Assert.True(exception.Message.Contains("Build")); }
public void PrepareNewProject(string directory) { projectManifest = new ProjectManifest(); CurrentProject = new DirectoryInfo(directory); projectManifest.Name = CurrentProject.Name; projectManifest.Created = DateTime.Now; projectManifest.Modified = DateTime.Now; projectManifest.Description = "NOT IMPLEMENTED"; projectManifest.Frames = new List <string>(); string manifestFileString = JsonConvert.SerializeObject(projectManifest); if (File.Exists(directory + "/manifest.json")) { File.Delete(directory + "/manifest.json"); } if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllText(directory + "/manifest.json", manifestFileString); Directory.CreateDirectory(directory + @"\Frames Folder"); ProjectNameInputField.text = projectManifest.Name; }
protected void LoadProject() { this.Logger.WriteInformation("Loading al files..."); //load all syntax trees this.SyntaxTrees = new List <SyntaxTree>(); this.ALFiles = new List <ProjectFileInfo>(); this.LoadProjectALFiles(this.ProjectPath, this.OutputPath); List <Diagnostic> diagnostics = new List <Diagnostic>(); //load project manifest string projectFile = Path.Combine(this.ProjectPath, "app.json"); ProjectManifest manifest = ProjectManifest.ReadFromString(projectFile, File.ReadAllText(projectFile), diagnostics); this.Logger.WriteInformation("Preparing compilation..."); //create compilation Compilation compilation = Compilation.Create("MyCompilation", manifest.AppManifest.AppPublisher, manifest.AppManifest.AppVersion, manifest.AppManifest.AppId, null, this.SyntaxTrees, new CompilationOptions()); LocalCacheSymbolReferenceLoader referenceLoader = new LocalCacheSymbolReferenceLoader(Path.Combine(this.ProjectPath, ".alpackages")); compilation = compilation .WithReferenceLoader(referenceLoader) .WithReferences(manifest.GetAllReferences()); this.Compilation = compilation; }
protected async Task EnsureServiceEndpointForKubernetesAsync( ProjectManifest manifest, ServiceEndpointManifest seManifest, ProjectService projectService, k8s.Models.V1Secret secret, Tuple <Kdoctl.CliServices.AzDoServices.Dtos.Project, bool> outcome) { var seService = GetServiceEndpointService(); var project = outcome.Item1; var eps = await seService.ListServiceEndpointsAsync(project.Id); if (eps != null && eps.Value != null) { var endpoint = eps.Value.FirstOrDefault(ep => ep.Name.Equals(seManifest.Name, StringComparison.OrdinalIgnoreCase)); if (endpoint == null) { using var op = Insights.BeginOperation($"Creating Kubernetes Service Endpoint '{seManifest.Name}' ..."); var newEndpoint = await seService.CreateKubernetesEndpointAsync( project.Id, project.Name, seManifest.Name, seManifest.Description, GetK8sService().GetClusterAPIUri().ToString(), Convert.ToBase64String(secret.Data["ca.crt"]), Convert.ToBase64String(secret.Data["token"])); if (newEndpoint != null) { op.EndWithSuccess(); } else { op.EndWithFailure(); } } else { using var op = Insights.BeginOperation($"Kubernetes Service Endpoint '{seManifest.Name}' ..."); var updatedEndpoint = await seService.UpdateKubernetesEndpointAsync( endpoint.Id, project.Id, project.Name, seManifest.Name, seManifest.Description, GetK8sService().GetClusterAPIUri().ToString(), Convert.ToBase64String(secret.Data["ca.crt"]), Convert.ToBase64String(secret.Data["token"])); if (updatedEndpoint != null) { op.EndWithSuccess(); } else { op.EndWithFailure(); } } } }
protected async Task <Tuple <Kdoctl.CliServices.AzDoServices.Dtos.Project, bool> > EnsureProjectExistsAsync( ProjectManifest manifest, ProjectService projectService) { var projectCreatedJIT = false; var projects = await projectService.ListProjectsAsync(); var project = projects.Value.FirstOrDefault(p => p.Name.Equals(manifest.Metadata.Name, StringComparison.OrdinalIgnoreCase)); if (project == null) { using var op = Insights.BeginOperation("Creating project, reading Process templates...", "Project"); var templates = await projectService.ListProcessAsync(); var tempalte = templates.Value.FirstOrDefault(t => t.Name.Equals(manifest.Template.Name, StringComparison.InvariantCulture)); if (tempalte == null) { op.EndWithFailure($"Process template {manifest.Template.Name} is not valid! Good example: Agile, CMMI, Basic, Scrum etc."); throw new InvalidOperationException($"Process template {manifest.Template.Name} is not valid! Good example: Agile, CMMI, Basic, Scrum etc."); } await projectService.CreateProjectAsync( manifest.Metadata.Name, tempalte, manifest.Template.SourceControlType, manifest.Metadata.Description); projectCreatedJIT = true; while (project == null) { projects = await projectService.ListProjectsAsync(); project = projects.Value.FirstOrDefault(p => p.Name.Equals(manifest.Metadata.Name, StringComparison.OrdinalIgnoreCase)); } } await projectService.UpdateRetentionAsync(project.Id, new ProjectRetentionSetting { ArtifactsRetention = new UpdateRetentionSettingSchema { Value = 15 }, PullRequestRunRetention = new UpdateRetentionSettingSchema { Value = 12 }, RetainRunsPerProtectedBranch = new UpdateRetentionSettingSchema { Value = 4 }, RunRetention = new UpdateRetentionSettingSchema { Value = 12 }, }); return(new Tuple <Kdoctl.CliServices.AzDoServices.Dtos.Project, bool>(project, projectCreatedJIT)); }
public void Pass_SetProtectionLevel(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description, string[] packages, string[] connectionManagers, ParameterSetupData[] parameters) { // Setup var xml = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers, parameters); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); var projectManifest = new ProjectManifest(); projectManifest.Initialize(path, null); var desiredProtectionLevel = projectManifest.ProtectionLevel; //== ProtectionLevel.DontSaveSensitive //? ProtectionLevel.DontSaveSensitive // : ProtectionLevel.ServerStorage; string savedXml; using (var stream = new MemoryStream()) { projectManifest.Save(stream, desiredProtectionLevel, Fakes.RandomString()); stream.Flush(); stream.Position = 0; var sr = new StreamReader(stream); savedXml = sr.ReadToEnd(); } // Execute var testXmlDoc = new XmlDocument(); testXmlDoc.LoadXml(savedXml); var projectProtectionLevel = testXmlDoc.DocumentElement?.Attributes["SSIS:ProtectionLevel"]?.Value; var packageProtectionLevelNodes = testXmlDoc.SelectNodes("//SSIS:Properties/SSIS:Property[@SSIS:Name = \"ProtectionLevel\"]", testXmlDoc.GetNameSpaceManager()); // Assert ProtectionLevel testProtectionLevel; Assert.True(Enum.TryParse(projectProtectionLevel, out testProtectionLevel)); Assert.Equal(desiredProtectionLevel, testProtectionLevel); Assert.NotNull(packageProtectionLevelNodes); foreach (XmlElement packageProtectionElement in packageProtectionLevelNodes) { Assert.Equal(desiredProtectionLevel, (ProtectionLevel)int.Parse(packageProtectionElement.InnerText)); } Assert.Equal(desiredProtectionLevel, projectManifest.ProtectionLevel); }
public void Pass_New(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description, string[] packages, string[] connectionManagers, ParameterSetupData[] parameters) { // Setup var xml = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers, parameters); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var projectManifest = new ProjectManifest(); projectManifest.Initialize(path, null); // Assert Assert.NotNull(projectManifest); foreach (var parameterSetupData in parameters) { var fullName = $"Project::{parameterSetupData.Name}"; Assert.True(projectManifest.Parameters.ContainsKey(fullName)); Assert.Equal(parameterSetupData.Value, projectManifest.Parameters[fullName].Value); Assert.Equal(parameterSetupData.Sensitive, projectManifest.Parameters[fullName].Sensitive); Assert.Equal(parameterSetupData.DataType.ToString("G"), projectManifest.Parameters[fullName].ParameterDataType.Name); } foreach (var package in packages) { Assert.True(projectManifest.PackageNames.Contains(package)); foreach (var parameterSetupData in parameters) { var fullName = $"{package}::{parameterSetupData.Name}"; Assert.True(projectManifest.Parameters.ContainsKey(fullName)); Assert.Equal(parameterSetupData.Value, projectManifest.Parameters[fullName].Value); Assert.Equal(parameterSetupData.Sensitive, projectManifest.Parameters[fullName].Sensitive); Assert.Equal(parameterSetupData.DataType.ToString("G"), projectManifest.Parameters[fullName].ParameterDataType.Name); } } foreach (var connectionManager in connectionManagers) { Assert.True(projectManifest.ConnectionManagerNames.Contains(connectionManager)); } Assert.Equal(versionMajor, projectManifest.VersionMajor); Assert.Equal(versionMinor, projectManifest.VersionMinor); Assert.Equal(versionBuild, projectManifest.VersionBuild); Assert.Equal(versionComments, projectManifest.VersionComments); Assert.Equal(description, projectManifest.Description); Assert.Equal(protectionLevel, projectManifest.ProtectionLevel); }
/// <summary> /// Constructs a new ProjectContext. /// </summary> /// <param name="projectRootPath">The root path of the project.</param> /// <param name="projectManifest">The loaded project manifest.</param> public ProjectContext(string projectRootPath, ProjectManifest projectManifest, string manifestPath) { if (string.IsNullOrEmpty(projectRootPath)) { throw new ArgumentException("Parameter must not be empty or null.", nameof(projectRootPath)); } if (projectManifest == null) { throw new ArgumentNullException(nameof(projectManifest)); } ProjectRootPath = projectRootPath; ProjectManifest = projectManifest; ProjectManifestPath = manifestPath; }
protected async Task <List <Tuple <k8s.Models.V1ServiceAccount> > > EnsureServiceEndpointExistsAsync( ProjectManifest manifest, ProjectService projectService, Tuple <Kdoctl.CliServices.AzDoServices.Dtos.Project, bool> outcome) { List <Tuple <k8s.Models.V1ServiceAccount> > producedK8sInfo = new List <Tuple <k8s.Models.V1ServiceAccount> >(); if (manifest.ServiceEndpoints != null) { foreach (var seManifest in manifest.ServiceEndpoints) { if (!string.IsNullOrWhiteSpace(seManifest.Name)) { if (seManifest.Kind == ServiceEndpointKind.Kubernetes && seManifest.ClusterInfo != null) { // only supporting Kubernetes for now if (seManifest.ClusterInfo.Namespace != null && seManifest.ClusterInfo.ServiceAccount != null && seManifest.ClusterInfo.Namespace.Metadata != null && seManifest.ClusterInfo.ServiceAccount.Spec != null && seManifest.ClusterInfo.ServiceAccount.Spec.Metadata != null && seManifest.ClusterInfo.ServiceAccount.Binding != null && seManifest.ClusterInfo.ServiceAccount.Role != null && !string.IsNullOrWhiteSpace(seManifest.ClusterInfo.Namespace.Metadata.Name) && !string.IsNullOrWhiteSpace(seManifest.ClusterInfo.ServiceAccount.Spec.Metadata.Name)) { //Logger.StatusBegin($"Creating Service endpoint '{seManifest.Name}' to deploy in Kubernetes namespace.."); await GetK8sService().EnsureNamespaceExistsAsync(seManifest.ClusterInfo); var sa = await GetK8sService().EnsureServiceAccountExists(seManifest.ClusterInfo); if (sa != null) { var secret = await GetK8sService().GetSecretAsync(sa); await EnsureServiceEndpointForKubernetesAsync(manifest, seManifest, projectService, secret, outcome); producedK8sInfo.Add(new Tuple <k8s.Models.V1ServiceAccount>(sa)); } } } } } } return(producedK8sInfo); }
private async Task EnsureEnvironmentExistsAsync( ProjectManifest manifest, Waddle.AdoConnectionFactory factory, Waddle.Dtos.Project project) { if (project != null && manifest.Environments != null && manifest.Environments.Any()) { var peService = factory.GetPipelineEnvironmentService(); foreach (var pe in manifest.Environments) { if (pe != null && !string.IsNullOrWhiteSpace(pe.Name)) { await ProvisionEnvironmentAsync(factory, project, peService, pe); } } } }
public void Fail_UserKeyProtectionLevel(ProtectionLevel protectionLevel) { // Setup var xml = XmlGenerators.ProjectManifestFile(protectionLevel, 1, 1, Fakes.RandomString(), 1, Fakes.RandomString(), new string[] {}, new string[] {}, new ParameterSetupData[] {}); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var projectManifest = new ProjectManifest(); var exception = Record.Exception(() => projectManifest.Initialize(path, null)); // Assert Assert.NotNull(exception); Assert.IsType <InvalidProtectionLevelException>(exception); Assert.Equal(((InvalidProtectionLevelException)exception).ProtectionLevel, protectionLevel); }
public void Setup(TopScene sceneController, string projectFilePath) { try { manifest = JsonConvert.DeserializeObject <ProjectManifest>(File.ReadAllText(projectFilePath + "/manifest.json")); } catch (Exception ex) { Debug.LogException(ex); manifest = null; } this.projectFilePath = projectFilePath; this.sceneController = sceneController; nameLabel.text = (manifest == null) ? "<color=#FF0000>Error: Could not read manifest file...</color>" : manifest.Name; pathLabel.text = projectFilePath; modifiedLabel.text = (manifest == null) ? "Unknown" : manifest.Modified.ToShortDateString() + " " + manifest.Modified.ToShortTimeString(); string manifestFileContents = File.ReadAllText(projectFilePath + "/manifest.json"); }
public void PrepareExistingProject(string directory) { string manifestFileContents = File.ReadAllText(directory + "/manifest.json"); projectManifest = JsonConvert.DeserializeObject <ProjectManifest>(manifestFileContents); frameManager.Frames.Clear(); foreach (string frameFilePath in projectManifest.Frames) { frameManager.Frames.Add(new FrameData(frameFilePath)); } foreach (FrameData frameData in frameManager.Frames) { frameData.LoadFrame(); Vector3[] points = frameData.Data.ToVector3(); foreach (Vector3 point in points) { pointCloudManager.AddPoint(point); } } ProjectNameInputField.text = projectManifest.Name; ProjectLoaded = true; }
protected async Task EnsureReleaseFoldersAsync(ProjectManifest manifest, Kdoctl.CliServices.AzDoServices.Dtos.Project project) { if (manifest.ReleaseFolders != null && manifest.ReleaseFolders.Any()) { var releaseService = GetReleaseService(); var releasePaths = await releaseService.ListFoldersAsync(project.Id); foreach (var rp in manifest.ReleaseFolders) { var existingItem = releasePaths.Value .FirstOrDefault(p => p.Path.Replace("\\", "/").Equals(rp.Path, StringComparison.OrdinalIgnoreCase)); if (existingItem == null) { existingItem = await releaseService.CreateFolderAsync(project.Id, rp.Path); } using var op = Insights.BeginOperation($"Creating permissions {rp.Path}...", "ReleaseFolderPermissions"); await ProvisionReleasePathPermissionsAsync(project, rp, existingItem); } } }
public void Fail_InvalidProtectionLevelString(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description, string[] packages, string[] connectionManagers, ParameterSetupData[] parameters) { // Setup var projectManifestXmlDoc = new XmlDocument(); var xml = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers, parameters); projectManifestXmlDoc.LoadXml(xml); projectManifestXmlDoc.DocumentElement.Attributes["SSIS:ProtectionLevel"].Value = Fakes.RandomString(); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, projectManifestXmlDoc.OuterXml); // Execute var projectManifest = new ProjectManifest(); var exception = Record.Exception(() => projectManifest.Initialize(path, null)); // Assert Assert.NotNull(exception); Assert.IsType <InvalidXmlException>(exception); Assert.True(exception.Message.Contains("Invalid Protection Level")); }
protected async Task EnsureBuildFoldersAsync( ProjectManifest manifest, Kdoctl.CliServices.AzDoServices.Dtos.Project project) { if (manifest.BuildFolders != null && manifest.BuildFolders.Any()) { var buildService = this.GetBuildService(); var buildPaths = await buildService.ListFoldersAsync(project.Id); foreach (var bp in manifest.BuildFolders) { var existingItem = buildPaths.Value .FirstOrDefault(p => p.Path.Replace("\\", "/").Equals(bp.Path, StringComparison.OrdinalIgnoreCase)); if (existingItem == null) { existingItem = await buildService.CreateFolderAsync(project.Id, bp.Path); } using var op = Insights.BeginOperation($"Creating permissions {bp.Path}...", "Build-Folder-Permissions"); await ProvisionBuildPathPermissionsAsync(project, bp, existingItem); } } }
protected async Task EnsureEnvironmentExistsAsync( ProjectManifest manifest, Kdoctl.CliServices.AzDoServices.Dtos.Project project, List <Tuple <k8s.Models.V1ServiceAccount> > k8sOutcome) { if (project != null && manifest.Environments != null && manifest.Environments.Any()) { var peService = GetPipelineEnvironmentService(); foreach (var pe in manifest.Environments) { if (pe != null && !string.IsNullOrWhiteSpace(pe.Name) && k8sOutcome != null && k8sOutcome.Count > 0) { var item = k8sOutcome.FirstOrDefault().Item1; if (item != null) { await ProvisionEnvironmentAsync(project, peService, pe, item.Metadata.NamespaceProperty, item.Metadata.NamespaceProperty); } } } } }
private async Task EnsureRepositoriesExistsAsync( ProjectManifest manifest, Waddle.AdoConnectionFactory factory, Waddle.RepositoryService repoService, Waddle.Dtos.Project project, bool projectWasAbsent) { if (project != null && manifest.Repositories != null && manifest.Repositories.Any()) { foreach (var repo in manifest.Repositories) { if (!string.IsNullOrWhiteSpace(repo.Name)) { var reposCollection = await repoService.GetRepositoryListAsync(project.Id); var repository = reposCollection .FirstOrDefault(r => r.Name.Equals(repo.Name, StringComparison.OrdinalIgnoreCase)); if (repository == null) { Logger.StatusBegin($"Creating Repository {repo.Name}..."); await ExecutionSupports.Retry(async() => { repository = await repoService.CreateAsync(project.Id, repo.Name); }, exception => { Logger.SilentError(exception.Message); }); Logger.StatusEndSuccess("Succeed"); } Logger.StatusBegin($"Setting up permissions for repository {repo.Name}..."); await EnsureRepositoryPermissionsAsync(factory, project, repo, repository); Logger.StatusEndSuccess("Succeed"); } } await DeleteDefaultRepoAsync(repoService, project, projectWasAbsent); } }
private async Task EnsureBuildFoldersAsync(ProjectManifest manifest, Waddle.AdoConnectionFactory factory, Waddle.Dtos.Project project) { if (manifest.BuildFolders != null && manifest.BuildFolders.Any()) { var buildService = factory.GetBuildService(); var buildPaths = await buildService.ListFoldersAsync(project.Id); foreach (var bp in manifest.BuildFolders) { var existingItem = buildPaths.Value .FirstOrDefault(p => p.Path.Replace("\\", "/").Equals(bp.Path, StringComparison.OrdinalIgnoreCase)); if (existingItem == null) { existingItem = await buildService.CreateFolderAsync(project.Id, bp.Path); } Logger.StatusBegin($"Creating permissions {bp.Path}..."); await ProvisionBuildPathPermissionsAsync(factory, project, bp, existingItem); Logger.StatusEndSuccess("Succeed"); } } }
protected async Task EnsureRepositoriesExistsAsync( ProjectManifest manifest, RepositoryService repoService, Kdoctl.CliServices.AzDoServices.Dtos.Project project, bool projectWasAbsent) { if (project != null && manifest.Repositories != null && manifest.Repositories.Any()) { foreach (var repo in manifest.Repositories) { if (!string.IsNullOrWhiteSpace(repo.Name)) { var reposCollection = await repoService.GetRepositoryListAsync(project.Id); var repository = reposCollection .FirstOrDefault(r => r.Name.Equals(repo.Name, StringComparison.OrdinalIgnoreCase)); if (repository == null) { using var op = Insights.BeginOperation($"Creating Repository {repo.Name}...", "Repository"); await ExecutionSupports.Retry(async() => { repository = await repoService.CreateAsync(project.Id, repo.Name); }, exception => { Insights.TrackException(exception); }); op.EndWithSuccess("Succeed"); } using var opPermissions = Insights.BeginOperation($"Setting up permissions for repository {repo.Name}...", "RepoPermissions"); await EnsureRepositoryPermissionsAsync(project, repo, repository); } } await DeleteDefaultRepoAsync(repoService, project, projectWasAbsent); } }
private DTSProtectionLevel GetProtectionLevel(ProjectManifest manifest) { var level = manifest.ProtectionLevel; if (ProtectionLevel != null) { level = (DTSProtectionLevel)Enum.Parse(typeof(DTSProtectionLevel), ProtectionLevel, true); } return level; }
public void Pass_SetVersion(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description, string[] packages, string[] connectionManagers, ParameterSetupData[] parameters) { // Setup var xml = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers, parameters); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var projectManifest = new ProjectManifest(); projectManifest.Initialize(path, null); var newVersionMajor = projectManifest.VersionMajor * 2; var newVersionMinor = projectManifest.VersionMinor * 2; var newVersionBuild = projectManifest.VersionBuild * 2; var newVersionComments = Fakes.RandomString(); var newDescription = Fakes.RandomString(); projectManifest.VersionBuild = newVersionBuild; projectManifest.VersionMajor = newVersionMajor; projectManifest.VersionMinor = newVersionMinor; projectManifest.VersionComments = newVersionComments; projectManifest.Description = newDescription; string savedXml; using (var stream = new MemoryStream()) { projectManifest.Save(stream, ProtectionLevel.DontSaveSensitive, Fakes.RandomString()); stream.Flush(); stream.Position = 0; var sr = new StreamReader(stream); savedXml = sr.ReadToEnd(); } var testXmlDoc = new XmlDocument(); testXmlDoc.LoadXml(savedXml); var versionMajorNodes = testXmlDoc.SelectNodes("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionMajor\"]", testXmlDoc.GetNameSpaceManager()); var versionMinorNodes = testXmlDoc.SelectNodes("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionMinor\"]", testXmlDoc.GetNameSpaceManager()); var versionBuildNodes = testXmlDoc.SelectNodes("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionBuild\"]", testXmlDoc.GetNameSpaceManager()); var versionCommentsNodes = testXmlDoc.SelectNodes("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionComments\"]", testXmlDoc.GetNameSpaceManager()); var descriptionNodes = testXmlDoc.SelectNodes("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"Description\"]", testXmlDoc.GetNameSpaceManager()); // Assert Assert.NotNull(versionMajorNodes); foreach (XmlElement versionMajorNode in versionMajorNodes) { Assert.Equal(newVersionMajor, int.Parse(versionMajorNode.InnerText)); } Assert.NotNull(versionMinorNodes); foreach (XmlElement versionMinorNode in versionMinorNodes) { Assert.Equal(newVersionMinor, int.Parse(versionMinorNode.InnerText)); } Assert.NotNull(versionBuildNodes); foreach (XmlElement versionBuildNode in versionBuildNodes) { Assert.Equal(newVersionBuild, int.Parse(versionBuildNode.InnerText)); } Assert.NotNull(versionCommentsNodes); foreach (XmlElement versionCommentsNode in versionCommentsNodes) { Assert.Equal(newVersionComments, versionCommentsNode.InnerText); } Assert.NotNull(descriptionNodes); foreach (XmlElement descriptionNode in descriptionNodes) { Assert.Equal(newDescription, descriptionNode.InnerText); } Assert.Equal(newVersionBuild, projectManifest.VersionBuild); Assert.Equal(newVersionMajor, projectManifest.VersionMajor); Assert.Equal(newVersionMinor, projectManifest.VersionMinor); Assert.Equal(newVersionComments, projectManifest.VersionComments); Assert.Equal(newDescription, projectManifest.Description); }
private void SetProjectProperties(Project project, ProjectManifest manifest) { // set the properties we care about foreach (var prop in manifest.Properties.Keys) { switch (prop) { case "Name": project.Name = manifest.Properties[prop]; break; case "VersionMajor": project.VersionMajor = Int32.Parse(manifest.Properties[prop]); break; case "VersionMinor": project.VersionMinor = Int32.Parse(manifest.Properties[prop]); break; case "VersionBuild": project.VersionBuild = Int32.Parse(manifest.Properties[prop]); break; case "VersionComments": project.VersionComments = manifest.Properties[prop]; break; } } }
private async Task EnsureTeamProvisionedAsync(ProjectManifest manifest, Waddle.AdoConnectionFactory factory, Waddle.ProjectService projectService, Tuple <Waddle.Dtos.Project, bool> outcome) { var gService = factory.GetGroupService(); var secService = factory.GetSecurityNamespaceService(); var aclService = factory.GetAclListService(); var allUsers = await gService.ListUsersAsync(); foreach (var teamManifest in manifest.Teams) { var tc = await projectService.GetTeamsAsync(); var eteam = tc.Value .FirstOrDefault(tc => tc.Name.Equals(teamManifest.Name, StringComparison.OrdinalIgnoreCase)); if (eteam == null) { Logger.StatusBegin($"Creating team [{teamManifest.Name}]..."); var team = await projectService.CreateTeamAsync( new Microsoft.TeamFoundation.Core.WebApi.WebApiTeam { Name = teamManifest.Name, Description = teamManifest.Description, ProjectId = outcome.Item1.Id, ProjectName = outcome.Item1.Name }, outcome.Item1.Id); while (eteam == null) { tc = await projectService.GetTeamsAsync(); eteam = tc.Value .FirstOrDefault(tc => tc.Name.Equals(teamManifest.Name, StringComparison.OrdinalIgnoreCase)); } Logger.StatusEndSuccess("Succeed"); } if (eteam != null && teamManifest.Membership != null && (teamManifest.Membership.Groups != null && teamManifest.Membership.Groups.Any())) { var teamGroup = await GetGroupByNameAsync(factory, IdentityOrigin.Vsts.ToString(), eteam.Name); if (teamGroup != null) { foreach (var gp in teamManifest.Membership.Groups) { var groupObject = await GetGroupByNameAsync(factory, IdentityOrigin.Aad.ToString(), gp.Name, gp.Id); if (groupObject != null) { await gService.AddMemberAsync(eteam.ProjectId, teamGroup.Descriptor, groupObject.Descriptor); } } foreach (var user in teamManifest.Membership.Users) { var userInfo = allUsers.Value.FirstOrDefault(u => u.OriginId.Equals(user.Id)); if (userInfo != null) { await gService.AddMemberAsync(eteam.ProjectId, teamGroup.Descriptor, userInfo.Descriptor); } } } } if (eteam != null && teamManifest.Admins != null && teamManifest.Admins.Any()) { var token = $"{eteam.ProjectId}\\{eteam.Id}"; var releaseNamespace = await secService.GetNamespaceAsync(SecurityNamespaceConstants.Identity); var secNamespaceId = releaseNamespace.NamespaceId; var aclDictioanry = new Dictionary <string, VstsAcesDictionaryEntry>(); foreach (var adminUserName in teamManifest.Admins) { var matches = await gService.GetLegacyIdentitiesByNameAsync(adminUserName.Name); if (matches != null && matches.Count > 0) { var adminUserInfo = matches.Value.First(); aclDictioanry.Add(adminUserInfo.Descriptor, new VstsAcesDictionaryEntry { Allow = 31, Deny = 0, Descriptor = adminUserInfo.Descriptor }); } } await aclService.SetAclsAsync(secNamespaceId, token, aclDictioanry, false); } } }
protected async Task EnsureTeamProvisionedAsync( ProjectManifest manifest, ProjectService projectService, Tuple <Kdoctl.CliServices.AzDoServices.Dtos.Project, bool> outcome) { if (manifest.Teams != null && manifest.Teams.Any()) { var gService = GetGraphService(); var secService = GetSecurityNamespaceService(); var aclService = GetAclListService(); var allUsers = await gService.ListUsersAsync(); foreach (var teamManifest in manifest.Teams) { var tc = await projectService.GetTeamsAsync(); var eteam = tc.Value .FirstOrDefault(tc => tc.Name.Equals(teamManifest.Name, StringComparison.OrdinalIgnoreCase)); if (eteam == null) { using var op = Insights.BeginOperation($"Creating team [{teamManifest.Name}]...", "Team"); var team = await projectService.CreateTeamAsync( new Microsoft.TeamFoundation.Core.WebApi.WebApiTeam { Name = teamManifest.Name, Description = teamManifest.Description, ProjectId = outcome.Item1.Id, ProjectName = outcome.Item1.Name }, outcome.Item1.Id); var breakOut = 0; while (eteam == null) { tc = await projectService.GetTeamsAsync(); eteam = tc.Value .FirstOrDefault(tc => tc.Name.Equals(teamManifest.Name, StringComparison.OrdinalIgnoreCase)); if (++breakOut > 10) { op.EndWithFailure($"Team [{teamManifest.Name}] was not retrieved on time."); throw new InvalidOperationException($"Team [{teamManifest.Name}] was not retrieved on time."); } } } if (eteam != null && teamManifest.Membership != null && (teamManifest.Membership.Groups != null && teamManifest.Membership.Groups.Any())) { var teamGroup = await GetGroupByNameAsync(IdentityOrigin.Vsts.ToString(), eteam.Name); if (teamGroup != null) { foreach (var gp in teamManifest.Membership.Groups) { var groupObject = await GetGroupByNameAsync(IdentityOrigin.Aad.ToString(), gp.Name, gp.Id); if (groupObject != null) { await gService.AddMemberAsync(eteam.ProjectId, teamGroup.Descriptor, groupObject.Descriptor); } } foreach (var user in teamManifest.Membership.Users) { var userInfo = allUsers.Value.FirstOrDefault(u => u.OriginId.Equals(user.Id)); if (userInfo != null) { await gService.AddMemberAsync(eteam.ProjectId, teamGroup.Descriptor, userInfo.Descriptor); } } } } if (eteam != null && teamManifest.Admins != null && teamManifest.Admins.Any()) { var token = $"{eteam.ProjectId}\\{eteam.Id}"; var releaseNamespace = await secService.GetNamespaceAsync(SecurityNamespaceConstants.Identity); var secNamespaceId = releaseNamespace.NamespaceId; var aclDictioanry = new Dictionary <string, VstsAcesDictionaryEntry>(); foreach (var adminUserName in teamManifest.Admins) { var matches = await gService.GetLegacyIdentitiesByNameAsync(adminUserName.Name); if (matches != null && matches.Count > 0) { var adminUserInfo = matches.Value.First(); aclDictioanry.Add(adminUserInfo.Descriptor, new VstsAcesDictionaryEntry { Allow = 31, Deny = 0, Descriptor = adminUserInfo.Descriptor }); } } await aclService.SetAclsAsync(secNamespaceId, token, aclDictioanry, false); } } } }
private void ProjectManifest_OnNewProjectCreated(ProjectManifest manifest) { mostRecentList.AddOrUpdate(manifest.ProjectFile); }