Esempio n. 1
0
 /// <summary>
 /// method to get work item data in detail
 /// </summary>
 /// <param name="workitemstoFetch"></param>
 /// <returns></returns>
 public WorkItemFetchResponse.WorkItems GetWorkItemsDetailInBatch(string workitemstoFetch)
 {
     WorkItemFetchResponse.WorkItems viewModel = new WorkItemFetchResponse.WorkItems();
     try
     {
         using (var client = GetHttpClient())
         {
             HttpResponseMessage response = client.GetAsync(_configuration.UriString + "/_apis/wit/workitems?api-version=" + _configuration.VersionNumber + "&ids=" + workitemstoFetch + "&$expand=relations").Result;
             if (response.IsSuccessStatusCode && response.StatusCode == System.Net.HttpStatusCode.OK)
             {
                 viewModel = response.Content.ReadAsAsync <WorkItemFetchResponse.WorkItems>().Result;
             }
             else
             {
                 var    errorMessage = response.Content.ReadAsStringAsync();
                 string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                 LastFailureMessage = error;
             }
         }
     }
     catch (Exception ex)
     {
         logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + ex.Message + "\n" + ex.StackTrace + "\n");
         string error = ex.Message;
         LastFailureMessage = error;
     }
     return(viewModel);
 }
Esempio n. 2
0
        /// <summary>
        /// method to get work item data in detail
        /// </summary>
        /// <param name="workitemstoFetch"></param>
        /// <returns></returns>
        public WorkItemFetchResponse.WorkItems GetWorkItemsDetailinBatch(string workitemstoFetch)
        {
            WorkItemFetchResponse.WorkItems viewModel = new WorkItemFetchResponse.WorkItems();
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(_sourceConfig.UriString);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _sourceCredentials);

                    // use $expand=all to get all fields
                    //HttpResponseMessage response = client.GetAsync(WorkItemURL + "?$expand=all&api-version=2.2").Result;
                    HttpResponseMessage response = client.GetAsync(_sourceConfig.UriString + "/_apis/wit/workitems?api-version=2.2&ids=" + workitemstoFetch + "&$expand=relations").Result;
                    if (response.IsSuccessStatusCode)
                    {
                        viewModel = response.Content.ReadAsAsync <WorkItemFetchResponse.WorkItems>().Result;
                    }
                    // viewModel.HttpStatusCode = response.StatusCode;
                    if (viewModel.count > 0)
                    {
                        DownloadAttachedFiles(viewModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured while generating work item template: " + ex.Message);
                Console.WriteLine("");
            }
            return(viewModel);
        }
        public void DownloadAttachedFiles(WorkItemFetchResponse.WorkItems workItems)
        {
            if (!Directory.Exists(@"Templates\WorkItemAttachments\"))
            {
                Directory.CreateDirectory(@"Templates\WorkItemAttachments\");
            }
            foreach (var wi in workItems.value)
            {
                if (wi.relations != null)
                {
                    foreach (var rel in wi.relations)
                    {
                        if (rel.rel == "AttachedFile")
                        {
                            string remoteUri  = rel.url;
                            string fileName   = rel.attributes["id"] + rel.attributes["name"];
                            string pathToSave = @"Templates\WorkItemAttachments\" + fileName;

                            using (var client = new HttpClient())
                            {
                                client.DefaultRequestHeaders.Accept.Clear();
                                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _sourceCredentials);
                                HttpResponseMessage response = client.GetAsync(remoteUri + "?api-version=1.0").Result;

                                if (response.IsSuccessStatusCode)
                                {
                                    File.WriteAllBytes(pathToSave, response.Content.ReadAsByteArrayAsync().Result);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void UpdateWorkItem()
        {
            WorkItemFetchResponse.WorkItems fetchedEpics           = getWorkItemsfromSource("Epic");
            WorkItemFetchResponse.WorkItems fetchedFeatures        = getWorkItemsfromSource("Feature");
            WorkItemFetchResponse.WorkItems fetchedPBIs            = getWorkItemsfromSource("Product Backlog Item");
            WorkItemFetchResponse.WorkItems fetchedTasks           = getWorkItemsfromSource("Task");
            WorkItemFetchResponse.WorkItems fetchedTestCase        = getWorkItemsfromSource("Test Case");
            WorkItemFetchResponse.WorkItems fetchedBugs            = getWorkItemsfromSource("Bug");
            WorkItemFetchResponse.WorkItems fetchedUserStories     = getWorkItemsfromSource("User Story");
            WorkItemFetchResponse.WorkItems fetchedTestSuits       = getWorkItemsfromSource("Test Suite");
            WorkItemFetchResponse.WorkItems fetchedTestPlan        = getWorkItemsfromSource("Test Plan");
            WorkItemFetchResponse.WorkItems fetchedFeedbackRequest = getWorkItemsfromSource("Feedback Request");



            GetBoardRowsResponse.Result fetchedBoardRows = GetBoardRows(_sourceConfig.Project);

            if (!Directory.Exists("Templates"))
            {
                Directory.CreateDirectory("Templates");
            }

            string fetchedPBIsJSON = JsonConvert.SerializeObject(fetchedPBIs, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\PBIfromTemplate.json", fetchedPBIsJSON);
            string fetchedTasksJSON = JsonConvert.SerializeObject(fetchedTasks, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\TaskfromTemplate.json", fetchedTasksJSON);
            string fetchedTestCasesJSON = JsonConvert.SerializeObject(fetchedTestCase, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\TestCasefromTemplate.json", fetchedTestCasesJSON);
            string fetchedBugsJSON = JsonConvert.SerializeObject(fetchedBugs, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\BugfromTemplate.json", fetchedBugsJSON);
            string fetchedEpicsJSON = JsonConvert.SerializeObject(fetchedEpics, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\EpicfromTemplate.json", fetchedEpicsJSON);
            string fetchedFeaturesJSON = JsonConvert.SerializeObject(fetchedFeatures, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\FeaturefromTemplate.json", fetchedFeaturesJSON);
            string fetchedUerStoriesJSON = JsonConvert.SerializeObject(fetchedUserStories, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\UerStoriesfromTemplate.json", fetchedUerStoriesJSON);
            string fetchedTestSuitsJSON = JsonConvert.SerializeObject(fetchedTestSuits, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\TestSuitesFromTemplate.json", fetchedTestSuitsJSON);
            string fetchedTestPlanJSON = JsonConvert.SerializeObject(fetchedTestPlan, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\TestPlanFromTemplate.json", fetchedTestPlanJSON);
            string fetchedFeedbackRequestJSON = JsonConvert.SerializeObject(fetchedFeedbackRequest, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\FeedbackRequestFromTemplate.json", fetchedFeedbackRequestJSON);


            string fetchedBoardRowsJSON = JsonConvert.SerializeObject(fetchedBoardRows.value, Formatting.Indented);

            System.IO.File.WriteAllText(@"Templates\BoardRowsFromTemplate.json", fetchedBoardRowsJSON);
        }
Esempio n. 5
0
        public static List <WorkItems> GetWorkItemsDetailInBatch(List <string> witIDsList, UrlParameters parameters)
        {
            List <WorkItemFetchResponse.WorkItems> viewModelList = new List <WorkItemFetchResponse.WorkItems>();

            try
            {
                if (witIDsList.Count > 0)
                {
                    foreach (var workitemstoFetch in witIDsList)
                    {
                        WorkItemFetchResponse.WorkItems viewModel = new WorkItemFetchResponse.WorkItems();

                        using (var client = new HttpClient())
                        {
                            client.DefaultRequestHeaders.Clear();
                            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", parameters.PatBase);
                            HttpResponseMessage response = client.GetAsync(parameters.UriString + "/_apis/wit/workitems?api-version=5.0&ids=" + workitemstoFetch + "&$expand=relations").Result;
                            if (response.IsSuccessStatusCode && response.StatusCode == System.Net.HttpStatusCode.OK)
                            {
                                string res = response.Content.ReadAsStringAsync().Result;
                                viewModel = JsonConvert.DeserializeObject <WorkItemFetchResponse.WorkItems>(res);
                                viewModelList.Add(viewModel);
                            }
                            else
                            {
                                var errorMessage = response.Content.ReadAsStringAsync();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.Message;
                WriteFileToDisk("GetWorkItemsDetailInBatch", ex.Message + Environment.NewLine + ex.StackTrace);
            }
            return(viewModelList);
        }