Exemple #1
0
        //******Get work item *******
        private static List <WorkItemClass> getWorkItem(WorkItemIdClass itemId, AuthenticationHeaderValue authHeader, int resultId)
        {
            List <WorkItemClass> workItem = new List <WorkItemClass>();

            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("https://tfsprodcus2.visualstudio.com");
                //client.BaseAddress = new Uri("");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("User-Agent", "ManagedClientConsoleAppSample");
                client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress");
                client.DefaultRequestHeaders.Authorization = authHeader;
                //const string newUrl = "https://tfsprodcus2.visualstudio.com/Aade702de-d9d9-418b-8e06-5fedd74e5d58/";
                //client.BaseAddress = new Uri(newUrl);
                if (itemId != null)
                {
                    foreach (var id in itemId.value)
                    {
                        if (!string.IsNullOrEmpty(id.ToString()))
                        {
                            try
                            {
                                HttpResponseMessage response = client.GetAsync("/Aade702de-d9d9-418b-8e06-5fedd74e5d58/_apis/wit/workItems/" + id.id).Result;
                                WorkItemClass       item     = (JsonConvert.DeserializeObject <WorkItemClass>(response.Content.ReadAsStringAsync().Result));
                                item.releaseId = resultId;
                                workItem.Add(item);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error in getWorkItem 0 : " + ex.Message + " and ID : " + id.id);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in getWorkItem " + ex.Message);
            }

            return(workItem);
        }
Exemple #2
0
        //******Get work item ID*******
        private static List <WorkItemClass> getWorkItemId(Rootobject result, HttpClient client, AuthenticationHeaderValue authHeader)
        {
            List <WorkItemClass> workItem = new List <WorkItemClass>();

            foreach (var id in result.value)
            {
                if (!string.IsNullOrEmpty(id.ToString()))
                {
                    HttpResponseMessage response = client.GetAsync("/Engineering/_apis/release/releases/" + id.id + "/workitems").Result;
                    WorkItemIdClass     itemId   = JsonConvert.DeserializeObject <WorkItemIdClass>(response.Content.ReadAsStringAsync().Result);
                    if (itemId != null && itemId.value != null && itemId.count > 0)
                    {
                        workItem.AddRange(getWorkItem(itemId, authHeader, id.id));
                    }
                }
            }
            return(workItem);
        }