/// <summary> /// Takes a tree query and returns a query string to get the associated items by Id. /// </summary> /// <param name="query">The query to be converted.</param> /// <returns>The query for the fields without any clauses that will not allow items to be retrieved by id.</returns> public static string ConvertTreeQueryToQueryForItem(ITfsQuery query) { if (query == null) { throw new ArgumentNullException("query"); } StringBuilder newQueryString = new StringBuilder(); newQueryString.Append("SELECT "); bool first = true; foreach (ITfsFieldDefinition df in query.DisplayFieldList) { if (!first) { newQueryString.Append(", "); } newQueryString.Append(df.ReferenceName); first = false; } newQueryString.Append(" FROM WorkItems"); return(newQueryString.ToString()); }
public IEnumerable <TfsWorkItemWrapper> QueryWorkItems(ITfsQuery query) { foreach (var workItem in query.GetResults()) { yield return(UpdateWorkItemFromCache(new TfsWorkItemWrapper(workItem))); } }
/// <summary> /// Executes the query to get the work items. /// </summary> /// <param name="queryDefinition">The definition of the query to execute</param> /// <param name="cancellationToken">Used to cancel the operation.</param> /// <returns>The tree of work items.</returns> public WorkItemTree QueryForWorkItems(QueryDefinition queryDefinition, CancellationToken cancellationToken) { WorkItemTree ans; if (queryDefinition == null) { throw new ArgumentNullException("queryDefinition"); } Dictionary <string, string> variables = new Dictionary <string, string>(); variables.Add("project", this.projectName); ITfsQuery query = this.queryFactory.CreateTfsQuery(queryDefinition.QueryText, variables); if (queryDefinition.QueryType == QueryType.List) { ans = RunFlatQuery(query, cancellationToken); } else if (queryDefinition.QueryType == QueryType.OneHop) { ans = RunOneHopQuery(query, cancellationToken); } else { ans = RunTreeQuery(query, cancellationToken); } return(ans); }
public void PrepareRefresh() { _availableSourceBranches = null; _sourceBranch = null; _targetBranches = null; _targetBranch = null; _selectedQuery = null; }
/// <summary> /// Runs a flat query. /// </summary> /// <param name="query">The query to execute.</param> /// <param name="cancellationToken">Used to cancel the operation.</param> /// <returns>A tree of work items, the root nodes will not have any children.</returns> private static WorkItemTree RunFlatQuery(ITfsQuery query, CancellationToken cancellationToken) { WorkItemTree ans = new WorkItemTree(); foreach (ITfsWorkItem wi in query.RunQuery(cancellationToken)) { ans.RootNodes.Add(new WorkItemTreeNode(wi, 0)); } return(ans); }
public void CanCancelLinkQuery() { // Arrange ITfsQuery sut = this.factory.CreateTfsQuery(TestHelper.TreeQuery, this.variables); CancellationTokenSource cts = new CancellationTokenSource(); // Act Task t = Task.Factory.StartNew(() => sut.RunLinkQuery(cts.Token)); cts.Cancel(); // Assert TestHelper.AssertTaskCancelled(t); }
/// <summary> /// Runs a tree query. /// </summary> /// <param name="query">The query to execute.</param> /// <param name="cancellationToken">Used to cancel the operation.</param> /// <returns>A tree of work items.</returns> private static WorkItemTree RunTreeQuery(ITfsQuery query, CancellationToken cancellationToken) { WorkItemTree ans = new WorkItemTree(); WorkItemLinkInfo[] wilis = query.RunLinkQuery(cancellationToken); int[] ids = new int[wilis.Length]; for (int i = 0; i < ids.Length; i++) { ids[i] = wilis[i].TargetId; } string workItemQueryString = QueryUtilities.ConvertTreeQueryToQueryForItem(query); IList <ITfsWorkItem> workItems = query.WorkItemStore.Query(ids.Distinct().ToArray(), workItemQueryString); for (int i = 0; i < wilis.Length; i++) { WorkItemLinkInfo wili = wilis[i]; ITfsWorkItem wi = workItems.Select(item => item).Where(item => item.Id == wili.TargetId).Single(); if (wili.SourceId <= 0) { ans.RootNodes.Add(new WorkItemTreeNode(wi, 0)); } else { WorkItemTreeNode parent = null; try { parent = ans.DepthFirstNodes().Where(node => node.WorkItem.Id == wili.SourceId).Single(); } catch (InvalidOperationException) { throw new InvalidOperationException(ModelResources.QueryNotWellFormedTree); } parent.Children.Add(new WorkItemTreeNode(wi, parent.Level + 1)); } } return(ans); }
private void LoadChangesets(ITfsQuery query, BackgroundTask task) { task.TrackProgress.ProgressInfo = "Loading work items ..."; var workItems = new List <TfsWorkItemWrapper>( TfsItemCache.QueryWorkItems(query)); task.TrackProgress.ProgressInfo = "Loading changesets ..."; task.TrackProgress.MaxProgress = workItems.Count; var changesets = new ObservableCollection <TfsChangesetWrapper>( TfsItemCache.QueryChangesets(workItems, task.TrackProgress, task.Cancelled.Token)); Repository.Instance.BackgroundTaskManager.Post( () => { if (!task.Cancelled.IsCancellationRequested) { SetContent(changesets); } return(true); }); }
private void LoadWorkItems(ITfsQuery query, BackgroundTask task) { task.TrackProgress.ProgressInfo = "Loading work items ..."; var workItems = new ObservableCollection <TfsWorkItemWrapper>( TfsItemCache.QueryWorkItems(query)); Repository.Instance.BackgroundTaskManager.Post( () => { try { if (!task.Cancelled.IsCancellationRequested) { SetContent(workItems); } } catch (Exception) { return(true); } return(true); }); }