Tfs WIQL to object converter

380 Views Asked by At

this is my first question :)

I was wondering, if there is something like a WIQL (TFS Work Item Query Language) parser. I'm dealing with TFS Queries and i have to programatically change some fields of them. Searching for a parses or something had no results to me. Can you help me?

NOTE: I have to change the queries themselves. Not any workitems.

Thank you Guys.

1

There are 1 best solutions below

0
On

You can use REST api or the .net api:

REST API:

 POST https://{instance}/defaultcollection/[{project}/]_apis/wit/wiql?api-version={version}

    Content-type: Application/json

    {
      "query": string
    }

.net API:

// credentials if required
System.Net.ICredentials credentials = new System.Net.NetworkCredential("User", "Password", "Domain");

// create the collection
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection teamProjectCollection =
        new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(new Uri(@"http://tfsServer:8080/tfs/collection"), credentials);

// check we are authenticated
teamProjectCollection.EnsureAuthenticated();

// create the work item store
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore Store = 
            (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore)
                  teamProjectCollection.GetService(typeof(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore));

// create a query to select tasks
string query = "SELECT * FROM WorkItems WHERE [System.WorkItemType] = 'Task' AND [System.IterationPath] = '@IterationPath' ORDER BY [System.WorkItemType], [System.Id]";

// replace the iteration
query = query.Replace("@IterationPath", "IterationPath");

// query the store!
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCollection WIC = Store.Query(query);