public IEnumerable <WorkItem> PullWorkItemsThatChanged(Uri tfsConnectionstring, string projectName, DateTime startDate, DateTime endDate) { WorkItemStore workItemStore = GetWorkItemStore(tfsConnectionstring); const string queryTemplate = @" SELECT ID, Title, [Team Project], [Microsoft.VSTS.Common.Priority], System.ChangedDate, [System.AssignedTo], [System.IterationPath], [System.AreaPath], [System.State], [CodeBox.UserVotes] FROM Issue WHERE [System.TeamProject] = @projectName and System.ChangedDate > @startDate and System.ChangedDate < @endDate "; IDictionary paramsDictionary = new Dictionary <string, object>(); paramsDictionary["projectName"] = projectName; //TFS will throw an error if you use the time in query and it defaults to midnight on the day sent in so we //have to use the previous day's date. paramsDictionary["startDate"] = startDate.Date.AddDays(-1); paramsDictionary["endDate"] = endDate.Date.AddDays(1); WorkItemCollection tfsWorkItemCollection = workItemStore.Query(queryTemplate, paramsDictionary); return(tfsWorkItemCollection.Cast <WorkItem>().ToList()); }
/// <summary> /// Flats the link query. /// </summary> /// <param name="query">The query.</param> /// <returns></returns> private IEnumerable <WorkItem> FlatLinkQuery(Query query) { var workItemLinks = query.RunLinkQuery(); // Build the list of work items for which we want to retrieve more information int[] ids = (from WorkItemLinkInfo info in workItemLinks select info.TargetId).ToArray(); // Next we want to create a new query that will retrieve all the column values from the original query, for // each of the work item IDs returned by the original query. var detailsWiql = new StringBuilder(); detailsWiql.AppendLine("SELECT"); bool first = true; foreach (FieldDefinition field in query.DisplayFieldList) { detailsWiql.Append(" "); if (!first) { detailsWiql.Append(","); } detailsWiql.AppendLine("[" + field.ReferenceName + "]"); first = false; } detailsWiql.AppendLine("FROM WorkItems"); // Get the work item details var flatQuery = new Query(TeamProject.Store, detailsWiql.ToString(), ids); WorkItemCollection details = flatQuery.RunQuery(); return(details.Cast <WorkItem>()); }
public IEnumerable <WorkItem> GetReleases() { var query = string.Format(" SELECT * " + " FROM WorkItems " + " WHERE [System.TeamProject] = '" + projectName + "' ORDER BY [System.Id]"); WorkItemCollection workItemCollection = tfs.GetService <WorkItemStore>().Query(query); return(workItemCollection.Cast <WorkItem>().Where(wi => wi.Type.Name.Contains("Release"))); }
/// <summary> /// Gets the linked workitems. /// </summary> /// <param name="sourceWorkitem">The workitem from where to check the links.</param> /// <param name="fieldsList">The fields list.</param> /// <param name="linkTypeReferenceName"></param> /// <returns></returns> public List <WorkItem> GetLinkedWorkitems(WorkItem sourceWorkitem, List <string> fieldsList, string linkTypeReferenceName, string workItemTypeName) { List <int> childIds = new List <int>(); string targetLinkType = string.Empty; foreach (WorkItemLinkType linkType in sourceWorkitem.Store.WorkItemLinkTypes) { if (linkTypeReferenceName.Equals(linkType.ReferenceName)) { targetLinkType = linkType.ForwardEnd.ImmutableName; break; } } if (string.IsNullOrEmpty(targetLinkType)) { return(null); } string queryString = string.Format("SELECT * FROM WorkItemLinks WHERE [Source].[System.Id]='{0}' AND [System.Links.LinkType]='{1}'", sourceWorkitem.Id, targetLinkType); var query = new Query(sourceWorkitem.Store, queryString); var links = query.RunLinkQuery(); if (links.Length == 0) { return(new List <WorkItem>()); } foreach (var item in links.Where(x => x.TargetId != sourceWorkitem.Id)) { childIds.Add(item.TargetId); } string childIdString = string.Join(", ", childIds); string fields = string.Empty; if (fieldsList == null || fieldsList.Count == 0) { fields = "*"; } else { fields = string.Join(", ", fieldsList); } string workItemQuery = string.Format("SELECT {0} FROM Workitems WHERE [System.ID] in ({1})", fields, childIdString); if (!String.IsNullOrEmpty(workItemTypeName)) { workItemQuery += String.Format(" AND [System.WorkItemType] = '{0}'", workItemTypeName); } WorkItemCollection childWorkItems = sourceWorkitem.Store.Query(workItemQuery); return(childWorkItems.Cast <WorkItem>().ToList()); }
/// <summary> /// Gets the child workitems. /// </summary> /// <param name="parentWorkitem">The parent workitem.</param> /// <param name="fieldsList">The fields list.</param> /// <returns></returns> private List <WorkItem> GetChildWorkitems(WorkItem parentWorkitem, List <string> fieldsList) { List <int> childIds = new List <int>(); string parentChildLinkTypeName = "System.LinkTypes.Hierarchy"; string parentChildLinkType = string.Empty; foreach (WorkItemLinkType linkType in parentWorkitem.Store.WorkItemLinkTypes) { if (parentChildLinkTypeName.Equals(linkType.ReferenceName)) { parentChildLinkType = linkType.ForwardEnd.ImmutableName; break; } } if (string.IsNullOrEmpty(parentChildLinkType)) { return(new List <WorkItem>()); } string queryString = string.Format("SELECT * FROM WorkItemLinks WHERE [Source].[System.Id]='{0}' AND [System.Links.LinkType]='{1}'", parentWorkitem.Id, parentChildLinkType); var query = new Query(parentWorkitem.Store, queryString); var links = query.RunLinkQuery(); foreach (var item in links.Where(x => x.TargetId != parentWorkitem.Id)) { childIds.Add(item.TargetId); } string childIdString = string.Join(", ", childIds); if (string.IsNullOrEmpty(childIdString)) { return(new List <WorkItem>()); } string fields = string.Empty; if (fieldsList == null || fieldsList.Count == 0) { fields = "*"; } else { fields = string.Join(", ", fieldsList); } string workItemQuery = string.Format("SELECT {0} FROM Workitems WHERE [System.ID] in ({1})", fields, childIdString); WorkItemCollection childWorkItems = parentWorkitem.Store.Query(workItemQuery); return(childWorkItems.Cast <WorkItem>().ToList()); }
public ObservableCollection <ActiveWorkItem> GetActiveWorkItems(string searchTerm, IPendingChangesExt pc, ITeamFoundationContext context) { var currentlyAssociatedWorkItems = pc.WorkItems; var workItems = new ObservableCollection <ActiveWorkItem>(); // Make the server call asynchronously to avoid blocking the UI if (context != null && context.HasCollection && context.HasTeamProject) { var vcs = context.TeamProjectCollection.GetService <VersionControlServer>(); if (vcs != null) { WorkItemStore workItemStore = (WorkItemStore)context.TeamProjectCollection.GetService(typeof(WorkItemStore)); var project = workItemStore.Projects[context.TeamProjectName]; var query = FindQueryItem("Active Work Items Query", project.QueryHierarchy); string queryString = "Select * " + "From WorkItems " + "Where [Work Item Type] IN ('User Story','Bug','Task') " + "AND [Assigned to] = @Me " + "AND [State] = 'Active' " + "AND [Area Path] Under '" + context.TeamProjectName + "' " + "Order By [Changed Date] Desc "; if (query != null) { queryString = query.QueryText.ToString().Replace("@project", "'" + context.TeamProjectName + "'"); } // Run a query. WorkItemCollection queryResults = workItemStore.Query(queryString); foreach (WorkItem wi in queryResults.Cast <WorkItem>() .Where(i => currentlyAssociatedWorkItems .All(a => a.WorkItem.Id != i.Id) && ( string.IsNullOrEmpty(searchTerm) || i.Type.Name.ToLower().Contains(searchTerm.ToLower()) || i.Id.ToString().ToLower().Contains(searchTerm.ToLower()) || i.Title.ToLower().Contains(searchTerm.ToLower()) || i.Description.ToLower().Contains(searchTerm.ToLower())))) { workItems.Add(new ActiveWorkItem(wi)); } } } return(workItems); }
public IEnumerable <WorkItem> PullData(DateTime startDate, DateTime endDate) { Trace.WriteLine("Querying WIT from " + TeamFoundationServer); WorkItemStore workItemStore = GetWorkItemStore(TeamFoundationServer); string queryTemplate; IDictionary paramsDictionary = new Dictionary <string, object>(); if (!string.IsNullOrWhiteSpace(Project)) { queryTemplate = @" SELECT ID, Title FROM Issue WHERE [System.TeamProject] = @projectName and System.ChangedDate > @startDate and System.ChangedDate < @endDate "; paramsDictionary["projectName"] = Project; } else { queryTemplate = @" SELECT ID, Title FROM Issue WHERE System.ChangedDate > @startDate and System.ChangedDate < @endDate "; } //TFS will throw an error if you use the time in query and it defaults to midnight on the day sent in so we //have to use the previous day's date. paramsDictionary["startDate"] = startDate.Date.AddDays(-1); paramsDictionary["endDate"] = endDate.Date.AddDays(1); WorkItemCollection tfsWorkItemCollection = workItemStore.Query(queryTemplate, paramsDictionary); return(tfsWorkItemCollection.Cast <WorkItem>().ToList()); }
public IEnumerable <WorkItem> PullWorkItems(IEnumerable <int> workItemIds) { WorkItemStore workItemStore = GetWorkItemStore(TeamFoundationServer); const string queryTemplate = @" SELECT ID, Title, [Team Project], [Microsoft.VSTS.Common.Priority], System.ChangedDate, [System.AssignedTo], [System.IterationPath], [System.AreaPath], [System.State], [CodeBox.UserVotes] FROM Issue WHERE [System.TeamProject] = @projectName and ([System.ID]={0}) "; var thing = string.Join(" OR [System.ID]=", workItemIds); var query = (string.Format(CultureInfo.InvariantCulture, queryTemplate, thing)); IDictionary paramsDictionary = new Dictionary <string, object>(); paramsDictionary["projectName"] = Project; WorkItemCollection tfsWorkItemCollection = workItemStore.Query(query, paramsDictionary); return(tfsWorkItemCollection.Cast <WorkItem>().ToList()); }
private void RefreshSelectedDefinitionWorkItems() { this.Logger().Trace("RefreshSelectedDefinitionWorkItems"); if (SelectedWorkItemQueryDefinition == null) { return; } WorkItemCollection workItemCollection = null; var successResult = teamPilgrimServiceModelProvider.TryGetQueryDefinitionWorkItemCollection(out workItemCollection, _projectCollectionServiceModel.TfsTeamProjectCollection, SelectedWorkItemQueryDefinition.QueryDefinition, SelectedWorkItemQueryDefinition.Project.Name); if (!successResult) { return; } Debug.Assert(workItemCollection != null, "workItemCollection != null"); var currentWorkItems = workItemCollection.Cast <WorkItem>().ToArray(); var intersections = WorkItems .Join(currentWorkItems, model => model.WorkItem.Id, workItem => workItem.Id, (model, workitem) => new { model, workitem }) .ToArray(); var intersectedModels = intersections .Select(arg => arg.model) .ToArray(); var modelsToRemove = WorkItems.Where(model => !intersectedModels.Contains(model)).ToArray(); var selectedWorkItemCheckinActionEnum = TeamPilgrimPackage.TeamPilgrimSettings.SelectedWorkItemCheckinAction; var modelsToAdd = currentWorkItems .Where( workItem => !intersectedModels.Select(workItemModel => workItemModel.WorkItem.Id).Contains(workItem.Id)) .Select( workItem => new WorkItemModel(workItem) { WorkItemCheckinAction = selectedWorkItemCheckinActionEnum }) .ToArray(); _backgroundFunctionPreventDataUpdate = true; foreach (var intersectedModel in intersections) { intersectedModel.model.WorkItem = intersectedModel.workitem; } foreach (var modelToAdd in modelsToAdd) { WorkItems.Add(modelToAdd); } foreach (var modelToRemove in modelsToRemove) { WorkItems.Remove(modelToRemove); } _backgroundFunctionPreventDataUpdate = false; WorkItemsOnCollectionChanged(); }
public void projectMigration() { logger.Info(String.Format("--------------------------------Migration from {0} to {1} Start----------------------------------------------", sourceProject.Name, destinationProject.Name)); CheckTestPlanTextBlock.Dispatcher.BeginInvoke(new Action(delegate() { CheckTestPlanTextBlock.Visibility = Visibility.Hidden; })); CheckLogTextBlock.Dispatcher.BeginInvoke(new Action(delegate() { CheckLogTextBlock.Visibility = Visibility.Hidden; })); MigratingLabel.Dispatcher.BeginInvoke(new Action(delegate() { MigratingLabel.Content = "Migrating..."; })); StatusBar.Dispatcher.BeginInvoke(new Action(delegate() { StatusBar.Visibility = Visibility.Visible; })); //WorkItemCollection source =readSource.GetWorkItems(sourceProject.Name).Cast<WorkItem>().Where(x => x.IterationPath.Contains("DevOps"))); IEnumerable <string> iterationPaths = null; WorkItemIterationFilter.Dispatcher.Invoke((Action)(() => { iterationPaths = WorkItemIterationFilter.SelectedItems.Cast <string>(); } )); WorkItemCollection source = readSource.GetWorkItems(sourceProject.Name, IsNotIncludeClosed, IsNotIncludeRemoved, iterationPaths); //Get Workitems from source tfs XmlNode[] iterations = readSource.PopulateIterations(); //Get Iterations and Areas from source tfs //NOTE: Only create areas and iterations that are present in the set of included work items var includedIterations = source.Cast <WorkItem>().Select(x => x.IterationPath).Distinct(); var includedAreas = source.Cast <WorkItem>().Select(x => x.AreaPath).Distinct(); var includedAreasNode = GetElementsWithAttributeValue(iterations[0], includedAreas, attributeCanonicalizationFunction: CanonicolizeAreaPath); var includedIterationsNode = GetElementsWithAttributeValue(iterations[1], includedIterations, attributeCanonicalizationFunction: CanonicolizeIterationPath); StatusViwer.Dispatcher.BeginInvoke(new Action(delegate() { StatusViwer.Content = "Generating Areas..."; })); writeTarget.GenerateAreas(includedAreasNode, sourceProject.Name); //Copy Areas StatusViwer.Dispatcher.BeginInvoke(new Action(delegate() { StatusViwer.Content = StatusViwer.Content + "\nGenerating Iterations..."; })); writeTarget.GenerateIterations(includedIterationsNode, sourceProject.Name); //Copy Iterations StatusViwer.Dispatcher.BeginInvoke(new Action(delegate() { // StatusViwer.Content = StatusViwer.Content + "\nCopying Team Queries..."; })); // writeTarget.SetTeamQueries(readSource.queryCol, sourceProject.Name); //Copy Queries StatusViwer.Dispatcher.BeginInvoke(new Action(delegate() { StatusViwer.Content = StatusViwer.Content + "\nCopying Work Items..."; })); writeTarget.writeWorkItems(sourceStore, source, sourceProject.Name, StatusBar, finalFieldMap); //Copy Workitems StatusViwer.Dispatcher.BeginInvoke(new Action(delegate() { StatusViwer.Content = StatusViwer.Content + "\nCopying Test Plans..."; })); // TestPlanMigration tcm = new TestPlanMigration(sourceTFS, destinationTFS, sourceProject.Name, destinationProject.Name, writeTarget.itemMap, StatusBar); // tcm.CopyTestPlans(); //Copy Test Plans MigratingLabel.Dispatcher.BeginInvoke(new Action(delegate() { MigratingLabel.Content = "Project Migrated"; })); StatusBar.Dispatcher.BeginInvoke(new Action(delegate() { StatusBar.Visibility = Visibility.Hidden; })); CheckTestPlanTextBlock.Dispatcher.BeginInvoke(new Action(delegate() { CheckTestPlanTextBlock.Visibility = Visibility.Visible; })); CheckLogTextBlock.Dispatcher.BeginInvoke(new Action(delegate() { CheckLogTextBlock.Visibility = Visibility.Visible; })); logger.Info("--------------------------------Migration END----------------------------------------------"); }