public static async Task <GetIterationResponse> CreateIteration(string project, CreateIterationBody body) { var newIterationPath = String.Empty; var iterationPath = body.name.Split('/'); GetIterationResponse objResponse = null; Util.WriteLog("Starting create of iteration " + body.name); foreach (var path in iterationPath) { body.name = path; var bodyContent = JsonConvert.SerializeObject(body); var stringContent = new StringContent(bodyContent, Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await Client.PostAsync( $"/tfs/{TfsVariables.Collection}/{project}/_apis/wit/classificationnodes/iterations/{newIterationPath}?api-version=4.1", stringContent)) { if (response.IsSuccessStatusCode) { Util.WriteLog($"Created iteration path {newIterationPath}"); string content = await response.Content.ReadAsStringAsync(); objResponse = JsonConvert.DeserializeObject <GetIterationResponse>(content); newIterationPath += path + "/"; } else if (response.StatusCode == HttpStatusCode.Conflict) { Util.WriteLog($"Iteration path already exists {newIterationPath}. Skip create iteration and move on to next. "); //Path exist - but we need to see if subpath exists newIterationPath += path + "/"; } } } return(objResponse); }
public static async Task <GetIterationResponse> GetIteration(string project, string iteration) { GetIterationResponse objResponse = null; Util.WriteLog($"Checking if iteration {iteration} already exists in project {project}"); using (HttpResponseMessage response = await Client.GetAsync( $"/tfs/{TfsVariables.Collection}/{project}/_apis/wit/classificationnodes/Iterations/{iteration}/")) { if (response.StatusCode == HttpStatusCode.NotFound) { Util.WriteLog("No iteration found."); return(null); } if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); objResponse = JsonConvert.DeserializeObject <GetIterationResponse>(content); Util.WriteLog($"Iteration already exist. {objResponse.name} - Has children - {objResponse.hasChildren}"); } } return(objResponse); }