Reputation: 114481
I'm setting up a TFS ISubscriber plugin and I want to be able to decide whether to trigger based on the installed Process Template Name (DONE), TypeID and Version.
The code to read the name is relatively straightforward:
var ics = context.GetService<ICommonStructureService>();
string ProjectName = string.Empty;
string ProjectState = String.Empty;
int templateId = 0;
CommonStructureProjectProperty[] ProjectProperties = null;
ics.GetProjectProperties(context, projectUri.ToString(), out ProjectName, out ProjectState, out ProjectProperties);
// The Projectproperties contains a property called "Process Template", holding the name.
But I can't find a way to read the other properties... I've nicked this code from looking at the TFS assemblies using Reflector, but it always returns Unknown:
private ArtifactSpec GetProcessTemplateVersionSpec(string projectUri)
{
var commonService = this.context.GetService<CommonStructureService>();
Guid guid = commonService.GetProject(this.context, projectUri).ToProjectReference().Id;
return new ArtifactSpec(ArtifactKinds.ProcessTemplate, guid.ToByteArray(), 0);
}
public ProcessTemplateVersion GetCurrentProjectProcessVersion(Uri projectUri)
{
return this.GetProjectProcessVersion(projectUri.AbsoluteUri, ProcessTemplateVersionPropertyNames.CurrentVersion);
}
public ProcessTemplateVersion GetCreationProjectProcessVersion(Uri projectUri)
{
return this.GetProjectProcessVersion(projectUri.AbsoluteUri, ProcessTemplateVersionPropertyNames.CreationVersion);
}
private ProcessTemplateVersion GetProjectProcessVersion(string projectUri, string versionPropertyName)
{
ArtifactSpec processTemplateVersionSpec = GetProcessTemplateVersionSpec(projectUri);
ProcessTemplateVersion unknown = ProcessTemplateVersion.Unknown;
using (TeamFoundationDataReader reader = context.GetService<TeamFoundationPropertyService>().GetProperties(context, processTemplateVersionSpec, new string[] { versionPropertyName }))
{
foreach (ArtifactPropertyValue value2 in reader)
{
foreach (PropertyValue value3 in value2.PropertyValues)
{
return TeamFoundationSerializationUtility.Deserialize<ProcessTemplateVersion>(value3.Value as string);
}
return unknown;
}
return unknown;
}
}
Even worse, I'd also like to be able to do this from the client Object Model, but that seems even harder.
Upvotes: 0
Views: 143
Reputation: 114481
After consulting with the Microsoft Product Team I'm sad to report that this property is currently only supported by Visual Studio Online and that the values are not even stored for on-premise instances.
There is a sort-of work around from Rene van Osnabrugge to copy these values and place them in the "standard" project properties.
Put the following in your Classification.xml of each process template:
<properties>
<property name="MSPROJ" value="Classification\FieldMapping.xml" isFile="true" />
<property name="Process Template" value="Microsoft Visual Studio Scrum 2.2" />
<property name="Create Version" value="Custom Text is allowed here" />
<property name="Current Version" value="Custom Text is allowed here" />
</properties>
And use this code to read it afterwards:
string uri = @"http://myServer:8080/tfs/defaultcollection";
string teamProjectName = "myTeamProject";
// Get the team project
var tpc = new TfsTeamProjectCollection(new Uri(uri));
tpc.Authenticate();
var ics = tpc.GetService<ICommonStructureService>();
var teamProject = ics.GetProjectFromName(teamProjectName);
// Read the properties
string projectName = string.Empty;
string projectState = string.Empty;
int templateId = 0;
ProjectProperty[] projectProperties = null;
ics.GetProjectProperties(teamProject.Uri, out projectName, out projectState, out templateId, out projectProperties);
// Return the properties
string processtemplate = projectProperties.Where(p => (p.Name == "Process Template")).Select(p => p.Value).FirstOrDefault();
string currentVersion = projectProperties.Where(p => (p.Name == "Current version")).Select(p => p.Value).FirstOrDefault();
string createVersion = projectProperties.Where(p => (p.Name == "Create version")).Select(p => p.Value).FirstOrDefault();
//Update the properties
projectProperties.Where(p => (p.Name == "Current version")).First().Value = "MS Scrum 2.2 - Custom 2.3";
ics.UpdateProjectProperties(teamProject.Uri, projectState, projectProperties);
Upvotes: 1