Pregunta

I'm working with some custom reporting in TFS. I have a set of WorkItem instances that I want to get the information about the Creator and Assigned-To from.

WorkItem wi = GetWorkItem( ... );
String assignedTo = (String)wi.Fields[CoreField.AssignedTo].Value;
String createdBy  = (String)wi.Fields[CoreField.CreatedBy].Value;

The problem is that the fields are raw string values that contain the display-name of the user. I have to store my own database that maps these display-names to their Active Directory identities (by their username or email address).

Obviously maintaining my own parallel database of users isn't the right way - is there any other way to get from wi.Fields[CoreField.AssignedTo].Value to a security identity object, or at least the user's username or email address?

¿Fue útil?

Solución

You can use the IIdentityManagementService2 (http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.framework.client.iidentitymanagementservice2.aspx) in order to get details about the identity using the display name. You can get the service in the same fashion as you would get the WorkItemStore from the project collection object using TfsTeamProjectCollection.GetService<IIdentityManagementService2>(). If you cast the AssignedTo value into a string, you can use the following code to get the identity:

var identity = identityService.ReadIdentity(
            IdentitySearchFactor.DisplayName, 
            assignedTo, 
            MembershipQuery.Direct,
            ReadIdentityOptions.ExtendedProperties);

Where assignedTo would be the value of the display name that you retrieve from the field in the work item.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top