private static void appendNewRows(HttpResponseMessage responseTillRun, int DBTopId, HttpClient client, AuthenticationHeaderValue authHeader) { int continuousTokenFinalRun = Convert.ToInt32(responseTillRun.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault()); int continuousToken = DBTopId + 1; DataBaseConn db = new DataBaseConn(); Consolidated obj3 = new Consolidated(); try { for (int i = 0; i <= continuousTokenFinalRun;) { HttpResponseMessage responseNew = client.GetAsync("/engineering/_apis/release/releases?$top=10&$expand=environments&queryOrder=ascending&continuationToken=" + continuousToken).Result; int continuousTokenNew = Convert.ToInt32(responseNew.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault()); Rootobject result2 = JsonConvert.DeserializeObject <Rootobject>(responseNew.Content.ReadAsStringAsync().Result); obj3.classRootObject = result2; obj3.classWorkItemClass = getWorkItemId(result2, client, authHeader); db.getDBConn(obj3); continuousToken = continuousTokenNew; i = continuousToken; } //DoTheMainWork2(null, true); } catch (Exception ex) { Console.WriteLine("Error inside amendNewRows : " + ex.Message); } }
private static void ListProjects(AuthenticationHeaderValue authHeader) { try { DataBaseConn db = new DataBaseConn(); int DBTopId = db.getDBTopId(); // use the httpclient using (var client = new HttpClient()) { client.BaseAddress = new Uri(vstsCollectionUrl); //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; // connect to the REST endpoint HttpResponseMessage responseTillRun = client.GetAsync("/engineering/_apis/release/releases?$top=100&$expand=environments").Result; if (DBTopId != 0) { appendNewRows(responseTillRun, DBTopId, client, authHeader); //Console.WriteLine("if condition called"); } else { HttpResponseMessage response = client.GetAsync("/engineering/_apis/release/releases?$top=100&$expand=environments&queryOrder=ascending").Result; //HttpResponseMessage response = client.GetAsync("/engineering/_apis/release/releases?$top=2&$expand=environments").Result; //int continuousToken = (Convert.ToBoolean(response.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault())) ? Convert.ToInt32(response.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault()) : 1; int continuousToken = Convert.ToInt32(response.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault()); int continuousTokenFinalRun = Convert.ToInt32(responseTillRun.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault()); // check to see if we have a succesfull respond if (response.IsSuccessStatusCode) { //DoTheMainWork(response); //**** DB Connection***** Consolidated obj = new Consolidated(); Rootobject result = JsonConvert.DeserializeObject <Rootobject>(response.Content.ReadAsStringAsync().Result); obj.classRootObject = result; obj.classWorkItemClass = getWorkItemId(result, client, authHeader); db.getDBConn(obj); if (continuousToken != 0) { Consolidated obj2 = new Consolidated(); try { for (int i = 0; i <= continuousTokenFinalRun;) { HttpResponseMessage responseNew = client.GetAsync("/engineering/_apis/release/releases?$top=100&$expand=environments&queryOrder=ascending&continuationToken=" + continuousToken).Result; int continuousTokenNew = Convert.ToInt32(responseNew.Headers.FirstOrDefault(x => x.Key == "x-ms-continuationtoken").Value.FirstOrDefault()); Rootobject result2 = JsonConvert.DeserializeObject <Rootobject>(responseNew.Content.ReadAsStringAsync().Result); obj2.classRootObject = result2; obj2.classWorkItemClass = getWorkItemId(result2, client, authHeader); db.getDBConn(obj2); continuousToken = continuousTokenNew; i = continuousToken; } //DoTheMainWork2(null, true); } catch (Exception ex) { Console.WriteLine("Error inside ListProjects 1 : " + ex.Message); } } } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException(); } else { Console.WriteLine("{0}:{1}", response.StatusCode, response.ReasonPhrase); Console.ReadLine(); } } } } catch (Exception ex) { Console.WriteLine("Error inside ListProjects 2 : " + ex.Message); } Console.WriteLine("Data gathered, press any key to exit!"); //Console.ReadLine(); }