public async Task Handle(MetricQueryRequest <WorkItemsWidget> request, CancellationToken cancellationToken) { const string workItemsQuery = "SELECT [System.Id] FROM WorkItems " + "WHERE [System.AssignedTo] = {0} " + "AND [State] NOT IN ('Done','Closed','Inactive','Completed')"; var query = string.Format(workItemsQuery, request.DataContext.AssignedTo); var api = new AzureDevOpsApi(request.DataContext.ConnectionSettings); var workItemQueryResult = await api.QueryWorkItemsAsync(query, cancellationToken).ConfigureAwait(false); var ids = workItemQueryResult.WorkItems.Select(w => w.Id).ToList(); if (ids.Count != 0) { var workItems = await api.GetWorkItemsAsync(ids, cancellationToken).ConfigureAwait(false); _uiAction.Invoke(() => UpdateWidget(request.DataContext, workItemQueryResult.WorkItems, workItems)); } else { request.DataContext.Value = 0; request.DataContext.State = State.Ok; _uiAction.Invoke(request.DataContext.Clear); } }
protected override async Task Handle(StatusRequest <AzureDevOpsWorkItemsWidget> request, CancellationToken cancellationToken) { var api = new AzureDevOpsApi(Endpoint); var wiql = string.Format(query, request.Context.Iteration); var response = await api.QueryWorkItemsAsync(request.Context.Account, request.Context.Project, wiql, cancellationToken); if (response.WorkItems.Any()) { var ids = response.WorkItems.Select(w => w.Id).ToList(); var workItems = await api.GetWorkItemsAsync(request.Context.Account, request.Context.Project, ids, cancellationToken); request.Context.Text = workItems.Count.ToString(); _dispatcher.Invoke(() => new AzureDevOpsWorkItemsSynchronizer(_mapper, request.Context) .Synchronize(workItems.Value.ToList(), request.Context.OfType <AzureDevOpsWorkItemWidget>().ToList())); } else { request.Context.Text = default; _dispatcher.Invoke(request.Context.Clear); } request.Context.Status = Status.OK; }