0

With selected project name, I had loaded iteration paths. Now I need to get the query names that references the selected iteration path.

Code to load iteration paths passing project name:

        private void LoadIterationPaths(string projectName)
        {
            var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(_tfs.Uri);
            var wiStore = tfs.GetService<WorkItemStore>();
            var projCollections = wiStore.Projects;

            var detailsOfTheSelectedProject = projCollections.Cast<Project>().Where(project => !String.IsNullOrEmpty(_selectedTeamProject.Name))
                                                                        .FirstOrDefault(project => project.Name.Contains(_selectedTeamProject.Name));
            var iterationPathsList = GetIterationPaths(detailsOfTheSelectedProject);

            foreach (var iterationPath in iterationPathsList.Where(iterationPath => iterationPath.Contains(projectName)))
            {
                cmbIterationPath.Items.Add(iterationPath);
            }
            cmbIterationPath.Enabled = cmbIterationPath.Items.Count > 0;
        }

Now, I need to get the list of Query names that references the selected iteration Path. Thanks.

Note: I am able to get all the query names in a project but that i don't need. For that I used the below code

foreach (StoredQuery qi in detailsOfTheSelectedProject.StoredQueries)
        {
            cmbQueries.Items.Add(qi.Name);
        }
codeseeker
  • 149
  • 11
  • 1
    What do you mean by a query referencing iteration path? The queries which has a rule by "iteration path"? – Beytan Kurt Jun 01 '15 at 12:35
  • @BeytanKurt, If I am selecting the `xxx.WebSites/yyy`, from the iteration path dropdown, I need to bind the `query names` in the next dropdown where and all the above `iteration path` is present. Thanks. **Note**: I am able to get all the query names in a project but that i don't need. Thanks. – codeseeker Jun 01 '15 at 12:37
  • TFS Work item queries are just text written in a semi-language([Work Item Query Language](https://msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx)) and they don't have any reference to any other work item properties, which you can use in code behind. So you can only use a text search by getting all of the query items' `QueryText` property and reading their contents. – Beytan Kurt Jun 01 '15 at 12:45
  • I think you need to parse the WIQL in the StoredQuery.QueryText property. Probably some not-too-smart regex can do the job. – Giulio Vian Jun 01 '15 at 12:45
  • 1
    @GiulioVian, Can you guide me how to accompolish this task, Thanks. – codeseeker Jun 01 '15 at 12:46

1 Answers1

0

Your code should looks like this

string selectedIterationPath = ... foreach (StoredQuery qi in detailsOfTheSelectedProject.StoredQueries) { if (qi.QueryText.Contains(selectedIterationPath) { cmbQueries.Items.Add(qi.Name); } }

This is what me and Beytan Kurt suggested in the comments. Instead of a dumb Contains, you should use a Regular Expression to account for false positives and negatives.

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41