Home > Software engineering >  What keys/values do I add to the dictionary for the TeamProject capabilities property?
What keys/values do I add to the dictionary for the TeamProject capabilities property?

Time:09-29

I am having difficulty figuring out how to set the Capabilities property for Microsoft.TeamFoundation.Core.WebApi.TeamProject. It expects a Dictionary<string, Dictionary<string, string>>, but I have no idea what the keys/values would look like. I need to set the "Version Control" and "Work Item Process". This is what I have so far.

var teamProject = new TeamProject {
                Description = projectDescription,
                Name = ProjectName,
                Visibility = ProjectVisibility.Private,
                //How to set this to "Version Control": Git, and "Work Item Process": Agile
                Capabilities = new Dictionary<string, Dictionary<string, string>>()
};

I know there are a few HttpClients in Microsoft.TeamFoundation.Core.WebApi, but which client would give me a list of "Version Control" methods and "Work Item Process" methods. How would I set them as a Dictionary<string, Dictionary<string, string>> for TeamProject to accept them? I have found the page for the property (https://docs.microsoft.com/en-us/dotnet/api/microsoft.teamfoundation.core.webapi.teamproject.capabilities?view=azure-devops-dotnet&source=docs#Microsoft_TeamFoundation_Core_WebApi_TeamProject_Capabilities), but I could not find an example of what microsoft expects for the property. Dictionary<string, Dictionary<string, string>> is vague and does not explain how the Version Control and Work Item Process is set for the dictionary. I would have expected something like this:

var capabilities = new Dictionary<string, string>();
capabilities.Add("Version Control", "Git");
capabilities.Add("Work Item Process", "Agile");

As you can see this does not meet the requirement of Dictionary<string, Dictionary<string, string>>, but rather Dictionary<string, string>. So what am I missing/requiring and am I doing it the correct way?

CodePudding user response:

You may use this code to set up capabilities:

private Dictionary<string, Dictionary<string, string>> SetCapabilities(string processName, string versionControl)
        {
            Dictionary<string, string> processProperties = new Dictionary<string, string>();
            processProperties.Add("Agile","adcc42ab-9882-485e-a3ed-7678f01f66bc");
            processProperties.Add("CMMI","27450541-8e31-4150-9947-dc59f998fc01");
            processProperties.Add("SCRUM","6b724908-ef14-45cf-84f8-768b5384da45");

            Guid processId = Guid.Parse(processProperties[processName]); 

            Dictionary<string, string> processProperaties = new Dictionary<string, string>();

            processProperaties[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityTemplateTypeIdAttributeName] =
                processId.ToString();

            Dictionary<string, string> versionControlProperties = new Dictionary<string, string>();

            versionControlProperties[TeamProjectCapabilitiesConstants.VersionControlCapabilityAttributeName] = versionControl =="Tfvc"?
                SourceControlTypes.Tfvc.ToString():
                SourceControlTypes.Git.ToString();

            Dictionary<string, Dictionary<string, string>> capabilities = new Dictionary<string, Dictionary<string, string>>();

            capabilities[TeamProjectCapabilitiesConstants.VersionControlCapabilityName] = 
                versionControlProperties;
            capabilities[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityName] = 
            
                processProperaties;
                return capabilities;
        }
  • Related