async Task <IReadOnlyList <RelationLinks> > InternalGetRelatedIdsAsync(int id, string relationshipType, DateTime?asOf, CancellationToken cancellationToken) { var list = new List <RelationLinks>(); using var mc = log?.Enter(LogLevel.RawApis, new object[] { id, null, asOf, WorkItemExpand.Relations, null, cancellationToken }, "GetWorkItemsAsync"); var workItem = await WorkItemClient.GetWorkItemAsync(id, null, asOf, WorkItemExpand.Relations, userState : null, cancellationToken) .ConfigureAwait(false); if (workItem.Relations != null) { list.AddRange(workItem.Relations .Where(r => relationshipType == null || r.Rel == relationshipType) .Select(r => new RelationLinks { Title = r.Title, Attributes = r.Attributes, Type = FindRelationship(r.Rel), RelatedId = ParseIdFromRelationship(r.Url), RawRelationshipType = r.Rel, Url = r.Url })); } return(list); }
private async Task <IEnumerable <Wit> > InternalGetWitsByIdChunked(List <int> ids, string[] fields, DateTime?asOf, WorkItemExpand?expand, WorkItemErrorPolicy?errorPolicy, CancellationToken cancellationToken) { const int nSize = 150; var workItems = new List <Wit>(); if (errorPolicy == null) { errorPolicy = ErrorPolicy; } // Chunk the retrieval. for (int i = 0; i < ids.Count; i += nSize) { var range = ids.GetRange(i, Math.Min(nSize, ids.Count - i)); using var mc = log?.Enter(LogLevel.RawApis, new object[] { range, fields, asOf, expand, errorPolicy, null, cancellationToken }, "GetWorkItemsAsync"); { var results = await WorkItemClient.GetWorkItemsAsync(range, fields, asOf, expand, errorPolicy, userState : null, cancellationToken) .ConfigureAwait(false); workItems.AddRange(results); } } return(workItems); }
private async Task <IEnumerable <Wit> > InternalGetWorkItemsAsync(string query, string[] fields, int?top, bool?timePrecision, WorkItemExpand?expand, WorkItemErrorPolicy?errorPolicy, CancellationToken cancellationToken) { log?.WriteLine(LogLevel.Query, query); Wiql wiql = new Wiql { Query = query }; if (errorPolicy == null) { errorPolicy = ErrorPolicy; } using var mc = log?.Enter(LogLevel.RawApis, new object[] { wiql, timePrecision, top, null, cancellationToken }, "QueryByWiqlAsync"); // Return a list of URLs + Ids for matching workItems. WorkItemQueryResult queryResult = await WorkItemClient.QueryByWiqlAsync(wiql, timePrecision, top, userState : null, cancellationToken) .ConfigureAwait(false); if (queryResult.WorkItems?.Any() == true) { var ids = queryResult.WorkItems.Select(wi => wi.Id).ToList(); // Get the actual work items from the IDs; chunked. return(await InternalGetWitsByIdChunked(ids, fields, queryResult.AsOf, expand, errorPolicy, cancellationToken) .ConfigureAwait(false)); } return(Enumerable.Empty <Wit>()); }
public TagsImporter(TagsImporterConfig config) { _workItemClient = new WorkItemClient(config.PersonalAccessToken, config.Organization); _timeTrackingClient = new TimeTrackingClient(config.TimeTrackingToken, $"https://{config.Organization}.timehub.7pace.com/api/rest/"); _billableQueryTemplate = config.BillableQueryTemplate; _nonBillableQueryTemplate = config.NonBillableQueryTemplate; }
private static async Task WorkItems(string personalAccessToken) { var client = new WorkItemClient(personalAccessToken, "<organizationName>"); var assignedWorkItemReferences = await client.GetAssignedWorkItemReferences("<uniqueUserName>", "query"); var workItems = await client.GetWorkItemsByReference(assignedWorkItemReferences.WorkItems); }
static void Main(string[] args) { WorkItemClient proxy = new WorkItemClient(); var items = proxy.GetItems(10); Console.WriteLine(items.Count()); }
public async void GetQueries() { var client = new WorkItemClient(TeamProjectName, CollectionUri, AccessToken); var queries = await client.GetQueries(); Assert.NotEmpty(queries); Assert.Equal(2, queries.Length); }
/// <summary> /// TODO: Return an set of objects which contains data like - link to the WorkItem /// </summary> /// <returns></returns> private async Task <int> FindActiveWorkItemsForCurrentUser(string mailAddress) { var workItemQueryResult = await WorkItemClient.QueryByWiqlAsync(new Wiql { Query = string.Format(AssignedToWorkItemsQuery, mailAddress) }, "VSOnline", top : 100).ConfigureAwait(false); return(workItemQueryResult.WorkItems.Count()); }
protected override async Task <WorkItemStateTransitions> AggregatorAsync(WorkItem workItem, DateTime?sinceDate) { if (workItem?.Id == null) { return(null); } var revisions = await WorkItemClient.GetWorkItemRevisionsAsync(workItem); return(new WorkItemStateTransitions(workItem.Id, workItem.Title(), revisions.StateTransitions())); }
public async void GetWorkItems() { var client = new WorkItemClient(TeamProjectName, CollectionUri, AccessToken); var standardQueryId = await client.CreateStandardQuery(); var workItems = await client.GetWorkItems(standardQueryId); Assert.NotEmpty(workItems); Assert.Equal(1, workItems.Length); }
public async void CreateQueries() { var client = new WorkItemClient(TeamProjectName, CollectionUri, AccessToken); var standardQueryId1 = await client.CreateStandardQuery(); var standardQueryId2 = await client.CreateStandardQuery2(); Assert.NotEqual(Guid.Empty, standardQueryId1); Assert.NotEqual(Guid.Empty, standardQueryId2); }
private async Task <Wit> AddAsync(JsonPatchDocument patchDocument, string projectName, string workItemType, bool?validateOnly, bool?bypassRules, CancellationToken cancellationToken) { if (this.ValidateOnly) { validateOnly = true; } using var mc = log?.Enter(LogLevel.RawApis, new object[] { patchDocument, projectName, workItemType, validateOnly, bypassRules, null, cancellationToken }, "CreateWorkItemAsync"); log?.Dump(patchDocument); return(await WorkItemClient.CreateWorkItemAsync(patchDocument, projectName, workItemType, validateOnly, bypassRules, userState : null, cancellationToken) .ConfigureAwait(false)); }
private async Task <Wit> UpdateAsync(int id, JsonPatchDocument patchDocument, bool?validateOnly, bool?bypassRules, bool?supressNotifications, WorkItemExpand?expand, CancellationToken cancellationToken) { if (this.ValidateOnly) { validateOnly = true; } using var mc = log?.Enter(LogLevel.RawApis, new object[] { patchDocument, id, validateOnly, bypassRules, supressNotifications, expand, null, cancellationToken }, "UpdateWorkItemAsync"); log?.Dump(patchDocument); return(await WorkItemClient.UpdateWorkItemAsync(patchDocument, id, validateOnly, bypassRules, supressNotifications, expand, userState : null, cancellationToken) .ConfigureAwait(false)); }
protected override async Task <WorkItemCycleTime> AggregatorAsync(WorkItem workItem, DateTime?sinceDate) { var revisions = await WorkItemClient.GetWorkItemRevisionsAsync(workItem); var startTime = CalculateStartOfCycle(revisions); var endTime = revisions.LastStateTransitionTo(_toState); if (startTime != null && endTime != null && endTime.Value.IsNewerThan(sinceDate)) { return(new WorkItemCycleTime(workItem.Id.Value, workItem.Title(), workItem.Tags(), startTime.Value, endTime.Value)); } return(null); }
private async Task <QueryHierarchyItem> InternalGetStoredQueriesAsync(string projectName, QueryHierarchyItem parent, bool?includeDeleted, CancellationToken cancellationToken) { if (parent.Children == null) { using var mc = log?.Enter(LogLevel.RawApis, new object[] { projectName, parent.Path, QueryExpand.All, 2, includeDeleted, null, cancellationToken }, "GetQueryAsync"); parent = await WorkItemClient.GetQueryAsync(projectName, parent.Path, QueryExpand.All, depth : 2, includeDeleted, userState : null, cancellationToken); } for (int i = 0; i < parent.Children.Count; i++) { QueryHierarchyItem item = parent.Children[i]; if (item.HasChildren == true) { parent.Children[i] = await InternalGetStoredQueriesAsync(projectName, item, includeDeleted, cancellationToken); } } return(parent); }
protected override async Task <WorkItemDoneDate> AggregatorAsync(WorkItem workItem, DateTime?sinceDate) { if (workItem?.Id == null) { return(null); } var revisions = await WorkItemClient.GetWorkItemRevisionsAsync(workItem); var doneDate = revisions.LastStateTransitionTo(_doneState); if (doneDate != null && doneDate.Value.IsNewerThan(sinceDate)) { return new WorkItemDoneDate { Id = workItem.Id.Value, DoneDate = doneDate.Value } } ; return(null); } }