private async Task <string> GetWiqlFromQueryAsync(AdoQuery adoQuery) { _log.Enter(this, args: adoQuery.Name); var uri = new Uri(adoQuery.Url + "?$top=1000&api-version=5.0"); HttpResponseMessage httpResponse = await GetAsync(uri); if (httpResponse.IsSuccessStatusCode) { var rawText = await httpResponse.Content.ReadAsStringAsync(); var jObject = JObject.Parse(rawText); return(jObject["_links"]["wiql"]["href"].Value <string>()); } return(string.Empty); }
/// <summary> /// Execute the query in ADO and transform the results into a list of CompleteWorkItems /// </summary> public async Task <List <CompleteWorkItem> > GetWorkItemsFromQueryAsync(AdoQuery adoQuery) { _log.Enter(this, args: adoQuery.Name); var wiqlUri = await GetWiqlFromQueryAsync(adoQuery); var uri = new Uri(wiqlUri + "?$top=1000&api-version=5.0"); HttpResponseMessage httpResponse = await GetAsync(uri); if (httpResponse.IsSuccessStatusCode) { var content = await httpResponse.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <QueryResult>(content); if (result != null && result.workItems.Any() && result.columns.Any()) { return(await ExtractAllWorkitemsAsync(result)); } } return(new List <CompleteWorkItem>()); }