public async Task <IActionResult> Index(string organizationName, string repositoryName, [FromQuery] Dictionary <string, List <string> > filters = null) { var model = new BrowseRepositoryViewModel() { RepositoryName = repositoryName, OrganizationName = organizationName }; this.telemetryClient.TrackViewRepository(organizationName, repositoryName); var queryParam = new RepositoryQueryParameter(organizationName, repositoryName); var repositoryInfo = (await this.repositoryService.GetRepositories(queryParam)).FirstOrDefault(); if (repositoryInfo == null) { this.TempData["Error"] = $"Did not find a repository [{repositoryName}] on [{organizationName}]."; return(this.RedirectToAction("PageNotFound", "Home")); } var projectsTask = this.repositoryService.GetAllCurrentProjects(repositoryInfo); var stampsTask = this.repositoryService.GetStamps(repositoryInfo); var downloadStatsTask = this.statisticsService.GetDownloadStatistics(repositoryInfo); await Task.WhenAll(projectsTask, stampsTask, downloadStatsTask).ConfigureAwait(false); ManifestQueryResult result = projectsTask.Result; model.NumberOfStamps = stampsTask.Result.Count; model.RepositoryMode = result.Projects?.FirstOrDefault()?.RepositoryInfo?.RepositoryMode.ToString(); List <ProjectInfoViewModel> manifests = this.mapper.Map <List <ProjectInfoViewModel> >(result.Projects); if (manifests.Any()) { model.RepositoryStamp = StampSorter.GetNewestStamp(manifests.Select(x => x.RepositoryStamp).ToList()); var orderedTimes = manifests.OrderByDescending(x => x.AddedDateTime).ToList(); model.ImportedDate = orderedTimes.First().AddedDateTime; model.ImportDuration = model.ImportedDate - orderedTimes.Last().AddedDateTime; model.NumberOfProjects = manifests.Count; model.NumberOfAutogeneratedProjects = manifests.Count(x => x.Autogenerated); model.AutogeneratedPercentage = Math.Round((decimal)model.NumberOfAutogeneratedProjects / model.NumberOfProjects * 100, 1); model.NumberOfComponents = manifests.Sum(x => x.Components.Count); model.NumberOfTags = manifests.Sum(prj => prj.Components.Sum(cmp => cmp.Tags.Count)); foreach (ProjectInfoViewModel projectInfoViewModel in manifests) { projectInfoViewModel.DownloadsCount = downloadStatsTask.Result.ProjectDownloadData.FirstOrDefault(x => x.ProjectKey == projectInfoViewModel.ProjectUri)?.DownloadCount ?? 0; } } ProjectsTableModel projectsTableModel = new ProjectsTableModel(manifests, false, false); model.ProjectsTable = projectsTableModel; model.ProjectsTable.Filters = filters; model.SearchIndexViewModel = this.GetRepositoriesSelectList(organizationName, repositoryName); MvcBreadcrumbNode breadcrumb = PrepareIndexBreadcrumb(organizationName, repositoryName); this.ViewData["BreadcrumbNode"] = breadcrumb; return(this.View(model)); }
public async Task <IEnumerable <RepositoryInfo> > GetRepositories(RepositoryQueryParameter repoParam) { return(await this.database.GetRepositories(this.mapper.Map <IReadOnlyCollection <Persistence.Models.RepositoryQueryParameter> >(new List <RepositoryQueryParameter>() { repoParam })).ConfigureAwait(false)); }
public async Task <SearchStatistics> Update(RepositoryQueryParameter repositoryParameter, IEnumerable <string> keywords) { var result = await this.database.Update( this.mapper.Map <Persistence.Models.RepositoryQueryParameter>(repositoryParameter), keywords); return(this.mapper.Map <SearchStatistics>(result)); }
public async Task <SearchStatistics> Get(RepositoryQueryParameter repositoryParameter) { Persistence.Models.SearchStatistics result = await this.database.Get( this.mapper.Map <Persistence.Models.RepositoryQueryParameter>(repositoryParameter)); return(this.mapper.Map <SearchStatistics>(result)); }
public async Task <IActionResult> GetSearchResultPage(string[] org, string[] repo, string query, bool isRegex, [FromQuery] Dictionary <string, List <string> > filters = null) { void CheckArgs() { if (org == null) { throw new ArgumentNullException(nameof(org)); } if (repo == null) { throw new ArgumentNullException(nameof(repo)); } } CheckArgs(); if (org.Length != repo.Length) { this.TempData["Error"] = $"Number of org parameters does not match the number of repo parameters. Orgs: {string.Join(", ", org)}. Repos: {string.Join(", ", repo)}"; return(this.RedirectToAction("Error", "Home")); } SearchIndexViewModel model = new SearchIndexViewModel { Repositories = await this.GetRepositoriesSelectList().ConfigureAwait(false), Query = query, IsRegex = isRegex }; IReadOnlyCollection <RepositoryQueryParameter> parameters = RepositoryQueryParameter.ConvertFromArrays(org, repo); ManifestQueryResultViewModel queryResultViewModel = await this.GetQueryResultViewModel(parameters, query, isRegex, filters).ConfigureAwait(false); model.Result = queryResultViewModel; return(this.View("Index", model)); }
public async Task <IActionResult> Search(string[] org, string[] repo, string query, bool isRegex, [FromQuery] Dictionary <string, List <string> > filters = null) { if (org == null) { throw new ArgumentNullException(nameof(org)); } if (repo == null) { throw new ArgumentNullException(nameof(repo)); } if (org.Length != repo.Length) { this.TempData["Error"] = $"Number of org parameters does not match the number of repo parameters. Orgs: {string.Join(", ", org)}. Repos: {string.Join(", ", repo)}"; return(this.RedirectToAction("Error", "Home")); } IReadOnlyCollection <RepositoryQueryParameter> parameters = RepositoryQueryParameter.ConvertFromArrays(org, repo); BackgroundJob.Enqueue(() => this.UpdateSearchStatistics(parameters, query)); ManifestQueryResultViewModel queryResultViewModel = await this.GetQueryResultViewModel(parameters, query, isRegex, filters).ConfigureAwait(false); this.telemetryClient.TrackSearch(parameters, query, isRegex, queryResultViewModel.ProjectsTable.Projects.Count, queryResultViewModel.Elapsed); return(this.PartialView("_SearchResultPartial", queryResultViewModel)); }
public async Task <IActionResult> Delete(string organizationName, string repositoryName) { this.telemetryClient.TrackDeleteRepository(organizationName, repositoryName); var queryParam = new RepositoryQueryParameter(organizationName, repositoryName); var repositoryInfo = (await this.repositoryService.GetRepositories(queryParam)).FirstOrDefault(); if (repositoryInfo == null) { throw new InvalidOperationException("Repository not found"); } var isSuccess = await this.repositoryService.DeleteRepository(new RepositoryQueryParameter(repositoryInfo)).ConfigureAwait(false); if (isSuccess) { return(this.RedirectToAction("Index", "Search")); } else { this.TempData["Error"] = $"Problem when trying to delete repository"; return(this.RedirectToAction("Error", "Home")); } }
public async Task <bool> DeleteRepository(RepositoryQueryParameter repoParam) { RepositoryInfo repo = await this.database.GetRepository(repoParam.OrganizationName, repoParam.RepositoryName).ConfigureAwait(false); if (repo == null) { throw new InvalidOperationException($"Failed to find repository {repoParam.RepositoryName} in {repoParam.OrganizationName}"); } DeleteResult projectsResult = await this.database.DeleteProjects(repo).ConfigureAwait(false); if (projectsResult.IsAcknowledged) { DeleteResult repoResult = await this.database.DeleteRepository(repo).ConfigureAwait(false); if (repoResult.IsAcknowledged) { return(true); } } return(false); }