private SearchRepositoriesRequest getSearchRepoRequest(SearchRepositoriesRequestParameters parameters) { SearchRepositoriesRequest repoRequest; try { repoRequest = new SearchRepositoriesRequest(parameters.Term); } catch (Exception) { repoRequest = new SearchRepositoriesRequest(); } Language language = (Language)Enum.Parse(typeof(Language), parameters.Language); repoRequest.User = parameters.Owner; repoRequest.Language = language; repoRequest.SortField = getSortBy(parameters.SortBy); repoRequest.Order = getSortDirection(parameters.Order); repoRequest.Forks = pickRange(parameters.ForksChoice, parameters.Forks); repoRequest.Stars = pickRange(parameters.StarsChoice, parameters.Stars); repoRequest.Size = pickRange(parameters.SizeChoice, parameters.Size); repoRequest.In = getInParameters(parameters.ReadmeIncluded, parameters.Term); repoRequest.Created = getCreatedAtParameter(parameters.DateChoice, parameters.Date, parameters.EndDate); repoRequest.Updated = getUpdatedAtParameter(parameters.UpdatedAt); return(repoRequest); }
public async Task <List <Model.Repository> > searchRepos(SearchRepositoriesRequestParameters requestParameters, int firstPage, int lastPage) { List <Model.Repository> repos = new List <Model.Repository>(); SearchRepositoriesRequest repoRequest = getSearchRepoRequest(requestParameters); for (int i = firstPage; i <= lastPage; i++) { repoRequest.Page = i; SearchRepositoryResult result = await GlobalVariables.client.Search.SearchRepo(repoRequest); repos.AddRange(result.Items.Select(repo => new Model.Repository { Name = repo.Name, Owner = repo.Owner.Login, Size = repo.Size, CreatedAt = repo.CreatedAt, UpdatedAt = repo.UpdatedAt, StargazersCount = repo.StargazersCount, HtmlUrl = repo.HtmlUrl, Description = repo.Description, ForksCount = repo.ForksCount, Language = repo.Language }).ToList()); } return(repos); }
private async void tryShowResults(SearchRepositoriesRequestParameters requestParameters) { try { var pagesCount = await repoSearch.getNumberOfPages(requestParameters); if (pagesCount != 0) { pageDialog = new PageDialog(pagesCount); pageDialog.ShowDialog(); var result = await repoSearch.searchRepos(requestParameters, pageDialog.FirstPage, pageDialog.LastPage); reposDataGrid.ItemsSource = result; downloadResultsButton.Visibility = Visibility.Visible; } else { reposDataGrid.ItemsSource = null; noResultsLabel.Visibility = Visibility.Visible; } } catch (ApiValidationException) { MessageBox.Show("The listed users and repositories cannot be searched either because the " + "resources do not exist or you do not have permission to view them.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (RateLimitExceededException exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (System.Net.Http.HttpRequestException) { MessageBox.Show("An error occurred while trying to send the request. Please check your" + " internet connection", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (AuthorizationException) { MessageBox.Show("Authentication failed: bad credentials", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (AbuseException exception) { MessageBox.Show("You have triggered an abuse detection mechanism. Try again after " + exception.RetryAfterSeconds + " seconds", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void searchReposButtonClick(object sender, RoutedEventArgs e) { if (isValid(termTextBox, ownerTextBox, starsTextBox, forksTextBox, sizeTextBox, accessTokenTextBox)) { searchButton.IsEnabled = false; downloadResultsButton.Visibility = Visibility.Hidden; noResultsLabel.Visibility = Visibility.Hidden; endDatePicker.SelectedDate = DateValidator.validate(datePicker, endDatePicker); GlobalVariables.client = GlobalVariables.createGithubClient(accessTokenTextBox.Text); requestParameters = new SearchRepositoriesRequestParameters(termTextBox.Text, ownerTextBox.Text, Int32.Parse(starsTextBox.Text), Int32.Parse(forksTextBox.Text), Int32.Parse(sizeTextBox.Text), sortComboBox.Text, orderComboBox.Text, datePicker.SelectedDate, dateComboBox.Text, updateDate.SelectedDate, languageComboBox.Text, endDatePicker.SelectedDate, ReadmeIncludedCheckBox.IsChecked, starsComboBox.Text, forksComboBox.Text, sizeComboBox.Text); tryShowResults(requestParameters); searchButton.IsEnabled = true; } }