/// <summary> /// Return a list of all projects present on the site associated with this RestApiRequestor. /// </summary> /// <returns>List of all projects present on the site.</returns> public IEnumerable <projectType> QueryProjects() { var projects = new List <projectType>(); int currentPage = 1; bool morePagesToCheck = true; while (morePagesToCheck) { // Construct URI specific to the current page of data to fetch. var uri = Endpoints.GetQueryProjectsUri(baseUri, GetSiteId(), currentPage); // Issue request. var errorMessage = String.Format("Failed to retrieve project list for site '{0}'", siteName); ApiRequest request = new ApiRequest(uri, HttpMethod.Get, GetAuthToken()); tsResponse response = request.IssueRequest(errorMessage); // Add all projects in current page to our result set projectListType projectList = response.GetProjectList(); projects.AddRange(projectList.project); // Evaluate whether we have more work to do paginationType paginationData = response.GetPaginationType(); if (currentPage * Constants.MaxResponsePageSize >= Convert.ToInt32(paginationData.totalAvailable)) { morePagesToCheck = false; } currentPage++; } return(projects); }
/// <summary> /// Retrieves the project details for the given project name. /// </summary> /// <param name="projectName">The name of the project to query.</param> /// <returns>Project details associated with a given project name, or null if no match is found.</returns> public projectType GetProjectByName(string projectName) { int currentPage = 1; bool morePagesToCheck = true; while (morePagesToCheck) { // Construct URI specific to the current page of data to fetch. var uri = Endpoints.GetQueryProjectsUri(baseUri, GetSiteId(), currentPage); // Issue request. var errorMessage = String.Format("Failed to retrieve project list for site '{0}'", siteName); ApiRequest request = new ApiRequest(uri, HttpMethod.Get, GetAuthToken()); tsResponse response = request.IssueRequest(errorMessage); // Rip project names out of response and check for a match. projectListType projectList = response.GetProjectList(); foreach (var project in projectList.project.Where(project => project.name == projectName)) { return(project); } // If we've read all the project names in and still haven't found a match, give up. Otherwise check the next page. paginationType paginationData = response.GetPaginationType(); if (currentPage * Constants.MaxResponsePageSize >= Convert.ToInt32(paginationData.totalAvailable)) { morePagesToCheck = false; } currentPage++; } // No match found. return(null); }