コード例 #1
0
        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));
        }
コード例 #2
0
        public async Task TestGet_NoWildcards_ReturnsOnlySpecifiedOrgs()
        {
            //arrange
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()),
                                                          TelemetryMock.InitializeMockTelemetryClient());
            var parameters = new[]
            {
                new RepositoryQueryParameter(this.orgOne_RepoOne),
                new RepositoryQueryParameter(this.orgTwo_RepoOne),
                new RepositoryQueryParameter(this.orgThree_RepoOne),
            };
            var repos = (await service.GetRepositories(parameters)).ToList();

            //act
            ManifestQueryResult result = await service.GetCurrentProjects(repos, "FindMe", false);

            //assert
            Assert.AreEqual(3, result.Projects.Count);
            Assert.AreEqual(1, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgOne_RepoOne.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgOne_RepoTwo.Id));
            Assert.AreEqual(1, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgTwo_RepoOne.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgTwo_RepoTwo.Id));
            Assert.AreEqual(1, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgThree_RepoOne.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgThree_RepoTwo.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgThree_RepoThree.Id));
        }
コード例 #3
0
        public static async Task <IEnumerable <string> > GetImageLayersAsync(
            this IManifestService manifestService, string tag, IRegistryCredentialsHost credsHost, bool isDryRun)
        {
            ManifestQueryResult manifestResult = await manifestService.GetManifestAsync(tag, credsHost, isDryRun);

            if (isDryRun)
            {
                return(Enumerable.Empty <string>());
            }

            if (!manifestResult.Manifest.ContainsKey("layers"))
            {
                JsonArray manifests = (JsonArray)(manifestResult.Manifest["manifests"] ??
                                                  throw new InvalidOperationException("Expected manifests property"));
                throw new InvalidOperationException(
                          $"'{tag}' is expected to be a concrete tag with 1 manifest. It has '{manifests.Count}' manifests.");
            }

            return(((JsonArray)manifestResult.Manifest["layers"] !)
                   .Select(layer => (layer !["digest"] ?? throw new InvalidOperationException("Expected digest property")).ToString())
コード例 #4
0
        /// <summary>
        /// invoke as an asynchronous operation.
        /// </summary>
        /// <returns>Task&lt;IViewComponentResult&gt;.</returns>
        ///
        public async Task <IViewComponentResult> InvokeAsync()
        {
            IReadOnlyCollection <RepositoryGrouping> repositoryGroups = await this.service.GetAllRepositoriesGrouped().ConfigureAwait(false);

            List <RepositoryQueryParameter> parameters = repositoryGroups.SelectMany(g => g.Repositories.Select(r => new RepositoryQueryParameter(r))).ToList();
            var repos = (await this.service.GetRepositories(parameters)).ToList();
            ManifestQueryResult result = await this.service.GetCurrentProjects(repos, "", false).ConfigureAwait(false);

            List <ComponentManifest> components = result.Projects.SelectMany(x => x.ProjectInfo.Components).ToList();
            int tags  = components.Sum(x => x.Tags.Count);
            int props = components.Sum(x => x.Properties.Count);

            NavHeaderStatsViewModel model = new NavHeaderStatsViewModel()
            {
                RepositoriesCount  = repositoryGroups.SelectMany(x => x.Repositories).Count(),
                OrganizationsCount = repositoryGroups.Count,
                ProjectsCount      = result.Projects.Count,
                ComponentsCount    = components.Count,
                PropertiesCount    = props,
                TagsCount          = tags
            };

            return(this.View("~/Areas/Catalog/Views/Shared/Components/NavHeaderStats/Default.cshtml", model));
        }