Workitem connection

May 4, 2011 at 8:41 AM

A question i have seen that for the connection with workitems was used the a direct webservice call and not the tfs api. What is the reason for this?

thanks

May 12, 2011 at 8:52 AM

so i have created a little method for me that looks like this:

 	   Microsoft.TeamFoundation.Client.TfsTeamProjectCollection collection = new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(new Uri(serverUrl));
            Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore workItemStore = new Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore(collection);
            Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem = workItemStore.GetWorkItem(workItemId);
            
            if (resolve)
            {
                if ((workItem.State != "Resolved") && (workItem.State != "Closed"))
                {
                    //HACK: Get next state dynamically
                    if (workItem.Type.Name == "Task")
                    {
                        workItem.State = "Closed";
                    }
                    else if (workItem.Type.Name == "Bug")
                    {
                        workItem.State = "Resolved";
                    }
                }
            }
            
            Microsoft.TeamFoundation.WorkItemTracking.Client.RegisteredLinkTypeCollection linkTypes = workItemStore.RegisteredLinkTypes;
            Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer versionControlServer = collection.GetService<Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer>();

            var changeset = versionControlServer.GetChangeset(changeSetId);
            workItem.History = String.Format("Fixed on changeset {0}", changeSetId);
            workItem.Links.Add(new Microsoft.TeamFoundation.WorkItemTracking.Client.ExternalLink(linkTypes["Fixed in Changeset"], changeset.ArtifactUri.ToString()));

            workItem.Save();