/// <summary> /// Recursively load the treeview /// </summary> /// <param name="queryFolder">The Query Folder to get information about</param> /// <param name="node">The node to add the query folder information to</param> private void GetNodesForQueryTree(QueryFolder queryFolder, TreeNode node) { //Add the folder to the treeview TreeNode folderNode = new TreeNode(); folderNode.Text = queryFolder.Name; folderNode.Tag = queryFolder; folderNode.Image = _graphicDictionary["Closed Folder.png"]; node.Items.Add(folderNode); int lastFolder = node.Items.Count - 1; //Loop through all items in the list of sub-items for this folder foreach (QueryItem queryItem in queryFolder) { //If the item is a query folder, call this method if (queryItem is QueryFolder) { GetNodesForQueryTree(queryItem as QueryFolder, node.Items[lastFolder]); } else { try { //If it isn't, add the query to the list of queries TreeNode itemNode = new TreeNode(); QueryDefinition qd = _wis.GetQueryDefinition(queryItem.Id); itemNode.Text = queryItem.Name; itemNode.Tag = queryItem; ImageSource img = null; if (qd.QueryType == QueryType.OneHop) { img = _graphicDictionary["Directed Link Query.png"]; } else if (qd.QueryType == QueryType.List) { img = _graphicDictionary["Flat Query.png"]; } else { img = _graphicDictionary["Tree Query.png"]; } itemNode.Image = img; folderNode.Items.Add(itemNode); } catch (ArgumentException ex) { MessageBox.Show("Could not get the query definition because of an invalid ID. Query Information is" + " as follows:\nQuery Item ID:" + queryItem.Id + "\nQuery Item Name: " + queryItem.Name + "\nSpecific message: " + ex.Message + "\nProcessing will continue.", "Retrieve Query Definition", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
private WorkItemLinkInfo[] GetCodeReviewRequests(WorkItemStore store) { QueryDefinition query2 = store.GetQueryDefinition(new Guid("3ff1f0be-1fcf-43ee-9206-9371793f503d")); Query executeQuery = new Query(store, query2.QueryText); WorkItemLinkInfo[] result = executeQuery.RunLinkQuery(); return(result); }
private static void V1() { //Initialize TFS Server object TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(ConfigurationManager.AppSettings["TfsServer"])); //Get the catalog of team project collections CatalogNode catalogNode = configurationServer.CatalogNode; //Get all CatalogNodes which are ProjectCollection ReadOnlyCollection <CatalogNode> tpcNodes = catalogNode.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); //Get InstanceId of a ProjectCollection Guid tpcId = Guid.Empty; foreach (CatalogNode tpcNode in tpcNodes) { tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]); break; } Workspace currentWorkspace = null; //string localPath = @"C:\LOS_DEV"; string URL = "http://sptserver.ists.com.vn:8080/tfs/iLendingPro"; //WriteLine($"Local Path: {localPath}"); System.Diagnostics.Debug.WriteLine($"Project Url: {URL}"); TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(new Uri(URL)); //Fill list of projects in a local variable //TfsTeamProjectCollection projectCollection = configurationServer.GetTeamProjectCollection(tpcId); projectCollection.Authenticate(); //Get WorkItem Tracking client for workitem collection for selected ProjectCollection WorkItemStore workItemStore = projectCollection.GetService <WorkItemStore>(); //Get Project from Tracking client Project project = workItemStore.Projects[ConfigurationManager.AppSettings["TfsProjectName"]]; //List<int> changesetIds = new List<int>(); //foreach (var item in File.ReadAllLines("list_item.txt")) //{ // int tmp = 0; // if (int.TryParse(item, out tmp)) // { // changesetIds.Add(tmp); // } //} // QueryFolder teamQueryFolder = project.QueryHierarchy[ConfigurationManager.AppSettings["TfsQueryGroup"]] as QueryFolder; QueryItem queryItem = teamQueryFolder[ConfigurationManager.AppSettings["TfsQueryName"]]; QueryDefinition queryDefinition = workItemStore.GetQueryDefinition(queryItem.Id); Dictionary <string, string> variables = new Dictionary <string, string> { { "@project", queryItem.Project.Name } }; WorkItemCollection workItemCollection = workItemStore.Query(queryDefinition.QueryText, variables); DataTable dt = CreateDataTable(); //Get Source Control/Version Control repository for selected project collection VersionControlServer versionControlServer = projectCollection.GetService <VersionControlServer>(); //Get Details of Version Control using artifact provider VersionControlArtifactProvider artifactProvider = versionControlServer.ArtifactProvider; //Iterate through each item to get its details foreach (WorkItem workItem in workItemCollection) { DataRow dr = dt.NewRow(); dr["ID"] = workItem.Id; dr["Title"] = workItem.Title; //use linq to get the linked changesets to a workitem IEnumerable <Changeset> changesets = workItem.Links.OfType <ExternalLink>().Select(link => artifactProvider.GetChangeset(new Uri(link.LinkedArtifactUri))); //iterate through changesets' to get each changeset details foreach (Changeset changeset in changesets) { dr["ChangesetId"] = changeset.ChangesetId; foreach (Change changes in changeset.Changes) { //ServerItem is the full path of a source control file associated to changeset if (changes.Item.ServerItem.Contains(ConfigurationManager.AppSettings["DevBranchName"])) { dr["Fix in DevBranch"] = "Yes"; break; } else if (changes.Item.ServerItem.Contains(ConfigurationManager.AppSettings["ReleaseBranchName"])) { dr["Fix in ReleaseBranch"] = "Yes"; break; } } } dt.Rows.Add(dr); } //Write datable to excel file using StreamWriter WriteToExcel(dt); }
public static void RunQuery(string tfs_url, string project_name, string query_folder, string query_name, string log_file, int take_first = 0) { _log_file = log_file; WriteLine("Initialize TFS Server object"); TfsConfigurationServer configuration_server = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(tfs_url)); WriteLine(@"Get the catalog of team project collections"); CatalogNode catalog_node = configuration_server.CatalogNode; WriteLine(@"Get all CatalogNodes which are ProjectCollection"); ReadOnlyCollection <CatalogNode> tpc_nodes = catalog_node.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); WriteLine(@"Get InstanceId of a ProjectCollection"); Guid tpc_id = Guid.Empty; foreach (CatalogNode tpc_node in tpc_nodes) { tpc_id = new Guid(tpc_node.Resource.Properties["InstanceId"]); break; } WriteLine(@"Fill list of projects in a local variable"); TfsTeamProjectCollection project_collection = configuration_server.GetTeamProjectCollection(tpc_id); project_collection.Authenticate(); WriteLine(@"Get WorkItem Tracking client for workitem collection for selected ProjectCollection"); WorkItemStore work_item_store = project_collection.GetService <WorkItemStore>(); WriteLine(@"Get Project from Tracking client"); Project project = work_item_store.Projects[project_name]; WriteLine(@"Run Query"); QueryFolder team_query_folder = project.QueryHierarchy[query_folder] as QueryFolder; QueryItem query_item = team_query_folder[query_name]; QueryDefinition queryDefinition = work_item_store.GetQueryDefinition(query_item.Id); Dictionary <string, string> variables = new Dictionary <string, string> { { "project", query_item.Project.Name } }; WorkItemCollection work_item_collection = work_item_store.Query(queryDefinition.QueryText, variables); WriteLine(@"Get Source Control/Version Control repository for selected project collection"); VersionControlServer version_control_server = project_collection.GetService <VersionControlServer>(); WriteLine(@"Get Details of Version Control using artifact provider"); VersionControlArtifactProvider artifact_provider = version_control_server.ArtifactProvider; Write_to_excel(new string[] { "WorkItemID", "WorkItemTitle", "ChangesetId", "CreationDate", "ChangeType", "File" }); WriteLine(@"Iterate through each item to get its details"); IEnumerable <WorkItem> work_items = take_first > 0 ? work_item_collection.OfType <WorkItem>().Take(take_first) : work_item_collection.OfType <WorkItem>(); foreach (WorkItem work_item in work_items) { WriteLine($" ->{work_item.Id}"); IEnumerable <Changeset> changesets = work_item.Links.OfType <ExternalLink>().Select(link => { Changeset set; try { set = artifact_provider.GetChangeset(new Uri(link.LinkedArtifactUri)); } catch (Exception ex) { BackgroundColor = ConsoleColor.Red; WriteLine(ex.Message); BackgroundColor = ConsoleColor.Black; set = null; } return(set); }) .Where(s => s != null); foreach (Changeset changeset in changesets) { WriteLine($" {changeset.ChangesetId}"); foreach (Change change in changeset.Changes) { WriteLine($" {change.Item.ServerItem}"); var data = new string[] { work_item.Id.ToString(), work_item.Title, changeset.ChangesetId.ToString(), changeset.CreationDate.ToString(), change.ChangeType.ToString(), change.Item.ServerItem }; Write_to_excel(data); } } } }