Access TFS command prompt from client APIs

Is there a way to run a generic command request by name through the TFS 2013 client API

I am working on a C # script that will do some work based on the results of a common command request. I do not want to support the request in the TFS user interface, as well as in my script; I would rather just run a registered request that my team uses, but then just play around with the results. When I write a “registered request”, I simply refer to the request that I wrote in the TFS user interface and saved as a general request.

In other words: I would like to use the TFS interface to create a request, save the file in the list of “general requests”, call it “foo”, then access foo from the client API in my script.

I see that there is the GetQueryDefinition(GUID) method of the WorkItemStore , but where can I get the GUID for a joint command request?

+6
source share
1 answer

Sample code that should do what you need

 ///Handles nested query folders private static Guid FindQuery(QueryFolder folder, string queryName) { foreach (var item in folder) { if (item.Name.Equals(queryName, StringComparison.InvariantCultureIgnoreCase)) { return item.Id; } var itemFolder = item as QueryFolder; if (itemFolder != null) { var result = FindQuery(itemFolder, queryName); if (!result.Equals(Guid.Empty)) { return result; } } } return Guid.Empty; } static void Main(string[] args) { var collectionUri = new Uri("http://TFS/tfs/DefaultCollection"); var server = new TfsTeamProjectCollection(collectionUri); var workItemStore = server.GetService<WorkItemStore>(); var teamProject = workItemStore.Projects["TeamProjectName"]; var x = teamProject.QueryHierarchy; var queryId = FindQuery(x, "QueryNameHere"); var queryDefinition = workItemStore.GetQueryDefinition(queryId); var variables = new Dictionary<string, string>() {{"project", "TeamProjectName"}}; var result = workItemStore.Query(queryDefinition.QueryText,variables); } 
+14
source

Source: https://habr.com/ru/post/977010/


All Articles