public TeamProject CreateProject() { string projectName = "Sample project " + Guid.NewGuid(); string projectDescription = "Short description for my new project"; string processName = "Agile"; // Setup version control properties Dictionary <string, string> versionControlProperties = new Dictionary <string, string>(); versionControlProperties[TeamProjectCapabilitiesConstants.VersionControlCapabilityAttributeName] = SourceControlTypes.Git.ToString(); // Setup process properties ProcessHttpClient processClient = Context.Connection.GetClient <ProcessHttpClient>(); Guid processId = processClient.GetProcessesAsync().Result.Find(process => { return(process.Name.Equals(processName, StringComparison.InvariantCultureIgnoreCase)); }).Id; Dictionary <string, string> processProperaties = new Dictionary <string, string>(); processProperaties[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityTemplateTypeIdAttributeName] = processId.ToString(); // Construct capabilities dictionary Dictionary <string, Dictionary <string, string> > capabilities = new Dictionary <string, Dictionary <string, string> >(); capabilities[TeamProjectCapabilitiesConstants.VersionControlCapabilityName] = versionControlProperties; capabilities[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityName] = processProperaties; // Construct object containing properties needed for creating the project TeamProject projectCreateParameters = new TeamProject() { Name = projectName, Description = projectDescription, Capabilities = capabilities }; // Get a client VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient <ProjectHttpClient>(); TeamProject project = null; try { Console.WriteLine("Queuing project creation..."); // Queue the project creation operation // This returns an operation object that can be used to check the status of the creation OperationReference operation = projectClient.QueueCreateProject(projectCreateParameters).Result; ClientSampleHttpLogger.SetSuppressOutput(Context, true); // Check the operation status every 5 seconds (for up to 30 seconds) Operation completedOperation = WaitForLongRunningOperation(operation.Id, 5, 30).Result; // Check if the operation succeeded (the project was created) or failed if (completedOperation.Status == OperationStatus.Succeeded) { // Get the full details about the newly created project project = projectClient.GetProject( projectCreateParameters.Name, includeCapabilities: true, includeHistory: true).Result; Console.WriteLine(); Console.WriteLine("Project created (ID: {0})", project.Id); // Save the newly created project (other sample methods will use it) Context.SetValue <TeamProject>("$newProject", project); } else { Console.WriteLine("Project creation operation failed: " + completedOperation.ResultMessage); } } catch (Exception ex) { Console.WriteLine("Exception during create project: ", ex.Message); } return(project); }
internal async Task <TeamProject> CreateProject(string projectName, string projectDescription = "", string processName = "Scrum") { Logger.Log(LogLevel.Warning, $"Project '{projectName}' does not exist."); Console.WriteLine("Would you like to create one? (Y/N)"); var answer = Console.ReadKey(); if (answer.KeyChar != 'Y' && answer.KeyChar != 'y') { return(null); } Logger.Log(LogLevel.Info, $"Creating project '{projectName}'."); // Setup version control properties Dictionary <string, string> versionControlProperties = new Dictionary <string, string> { [TeamProjectCapabilitiesConstants.VersionControlCapabilityAttributeName] = SourceControlTypes.Git.ToString() }; // Setup process properties ProcessHttpClient processClient = RestConnection.GetClient <ProcessHttpClient>(); Guid processId = processClient.GetProcessesAsync().Result.Find(process => { return(process.Name.Equals(processName, StringComparison.InvariantCultureIgnoreCase)); }).Id; Dictionary <string, string> processProperaties = new Dictionary <string, string> { [TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityTemplateTypeIdAttributeName] = processId.ToString() }; // Construct capabilities dictionary Dictionary <string, Dictionary <string, string> > capabilities = new Dictionary <string, Dictionary <string, string> > { [TeamProjectCapabilitiesConstants.VersionControlCapabilityName] = versionControlProperties, [TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityName] = processProperaties }; // Construct object containing properties needed for creating the project TeamProject projectCreateParameters = new TeamProject() { Name = projectName, Description = projectDescription, Capabilities = capabilities }; // Get a client ProjectHttpClient projectClient = RestConnection.GetClient <ProjectHttpClient>(); TeamProject project = null; try { Logger.Log(LogLevel.Info, "Queuing project creation..."); // Queue the project creation operation // This returns an operation object that can be used to check the status of the creation OperationReference operation = await projectClient.QueueCreateProject(projectCreateParameters); // Check the operation status every 5 seconds (for up to 30 seconds) Operation completedOperation = WaitForLongRunningOperation(operation.Id, 5, 30).Result; // Check if the operation succeeded (the project was created) or failed if (completedOperation.Status == OperationStatus.Succeeded) { // Get the full details about the newly created project project = projectClient.GetProject( projectCreateParameters.Name, includeCapabilities: true, includeHistory: true).Result; Logger.Log(LogLevel.Info, $"Project created (ID: {project.Id})"); } else { Logger.Log(LogLevel.Error, "Project creation operation failed: " + completedOperation.ResultMessage); } } catch (Exception ex) { Logger.Log(ex, "Exception during create project.", LogLevel.Critical); } return(project); }