/// <summary> /// Delete the default repository /// </summary> /// <param name="Project"></param> /// <returns></returns> public string GetRepositoryToDelete(string Project) { GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _credentials); HttpResponseMessage response = client.GetAsync(Project + "/_apis/git/repositories?api-version=" + _configuration.VersionNumber).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync <GetAllRepositoriesResponse.Repositories>().Result; string repository = viewModel.value.Where(x => x.name == Project).FirstOrDefault().id; return(repository); } else { var errorMessage = response.Content.ReadAsStringAsync(); string error = Utility.GeterroMessage(errorMessage.Result.ToString()); this.lastFailureMessage = error; } } return(string.Empty); }
/// <summary> ///Get Default repository to delete /// </summary> /// <param name="RepoName"></param> /// <returns></returns> public string[] GetDefaultRepository(string RepoName) { try { string[] repo = new string[2]; GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); using (var client = GetHttpClient()) { HttpResponseMessage response = client.GetAsync(RepoName + "/_apis/git/repositories?api-version=" + _configuration.VersionNumber).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync <GetAllRepositoriesResponse.Repositories>().Result; if (viewModel.count > 0) { repo[0] = viewModel.value.FirstOrDefault().id; repo[1] = viewModel.value.FirstOrDefault().name; } return(repo); } else { var errorMessage = response.Content.ReadAsStringAsync(); string error = Utility.GeterroMessage(errorMessage.Result.ToString()); this.LastFailureMessage = error; } } } catch (Exception ex) { logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "GetDefaultRepository" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n"); } return(new string[] { }); }
/// <summary> /// Get list of Repositories /// </summary> /// <returns></returns> public GetAllRepositoriesResponse.Repositories GetAllRepositories() { try { GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); using (var client = GetHttpClient()) { HttpResponseMessage response = client.GetAsync("/_apis/git/repositories?api-version=" + _configuration.VersionNumber).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync <GetAllRepositoriesResponse.Repositories>().Result; return(viewModel); } else { var errorMessage = response.Content.ReadAsStringAsync(); string error = Utility.GeterroMessage(errorMessage.Result.ToString()); this.LastFailureMessage = error; } } } catch (Exception ex) { logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "GetAllRepositories" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n"); } return(new GetAllRepositoriesResponse.Repositories()); }
/// <summary> /// Delete the default repository /// </summary> /// <param name="project"></param> /// <returns></returns> public string GetRepositoryToDelete(string project) { try { GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); using (var client = GetHttpClient()) { HttpResponseMessage response = client.GetAsync(project + "/_apis/git/repositories?api-version=" + _configuration.VersionNumber).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync <GetAllRepositoriesResponse.Repositories>().Result; string repository = viewModel.value.Where(x => x.name == project).FirstOrDefault().id; return(repository); } else { var errorMessage = response.Content.ReadAsStringAsync(); string error = Utility.GeterroMessage(errorMessage.Result.ToString()); LastFailureMessage = error; } } } catch (Exception ex) { logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "GetRepositoryToDelete" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n"); } return(string.Empty); }
public GetAllRepositoriesResponse.Repositories GetAllRepositories() { GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/?api-version=2.0").Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync <GetAllRepositoriesResponse.Repositories>().Result; } viewModel.HttpStatusCode = response.StatusCode; return(viewModel); } }