How to get query names that references the particular iteration path

喜欢而已 提交于 2019-12-08 03:51:13

问题


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);
        }

回答1:


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.



来源:https://stackoverflow.com/questions/30572112/how-to-get-query-names-that-references-the-particular-iteration-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!