Esempio n. 1
0
        private DisplayPackageViewModel SetupCommon(
            DisplayPackageViewModel viewModel,
            Package package,
            string pushedBy,
            IReadOnlyDictionary <int, PackageDeprecation> packageKeyToDeprecation)
        {
            viewModel.NuGetVersion = NuGetVersion.Parse(NuGetVersionFormatter.ToFullString(package.Version));
            viewModel.Copyright    = package.Copyright;

            viewModel.DownloadCount = package.DownloadCount;
            viewModel.LastEdited    = package.LastEdited;

            viewModel.TotalDaysSinceCreated = 0;
            viewModel.DownloadsPerDay       = 0;

            viewModel.PushedBy = pushedBy;

            viewModel.InitializeRepositoryMetadata(package.RepositoryUrl, package.RepositoryType);

            if (PackageHelper.TryPrepareUrlForRendering(package.ProjectUrl, out string projectUrl))
            {
                viewModel.ProjectUrl = projectUrl;
            }

            viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType;
            viewModel.LicenseExpression   = package.LicenseExpression;

            if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
            {
                viewModel.LicenseUrl = licenseUrl;

                var licenseNames = package.LicenseNames;
                if (!string.IsNullOrEmpty(licenseNames))
                {
                    viewModel.LicenseNames = licenseNames.Split(',').Select(l => l.Trim()).ToList();
                }
            }

            if (packageKeyToDeprecation != null && packageKeyToDeprecation.TryGetValue(package.Key, out var deprecation))
            {
                viewModel.DeprecationStatus = deprecation.Status;
            }
            else
            {
                viewModel.DeprecationStatus = PackageDeprecationStatus.NotDeprecated;
            }

            return(viewModel);
        }
        private DisplayPackageViewModel SetupCommon(
            DisplayPackageViewModel viewModel,
            Package package,
            string pushedBy,
            IReadOnlyDictionary <int, PackageDeprecation> packageKeyToDeprecation,
            IReadOnlyDictionary <int, IReadOnlyList <PackageVulnerability> > packageKeyToVulnerabilities)
        {
            viewModel.NuGetVersion = NuGetVersion.Parse(NuGetVersionFormatter.ToFullString(package.Version));
            viewModel.Copyright    = package.Copyright;

            viewModel.DownloadCount = package.DownloadCount;
            viewModel.LastEdited    = package.LastEdited;

            viewModel.TotalDaysSinceCreated = 0;
            viewModel.DownloadsPerDay       = 0;

            viewModel.PushedBy = pushedBy;

            viewModel.InitializeRepositoryMetadata(package.RepositoryUrl, package.RepositoryType);

            if (PackageHelper.TryPrepareUrlForRendering(package.ProjectUrl, out string projectUrl))
            {
                viewModel.ProjectUrl = projectUrl;
            }

            var fugetUrl = $"https://www.fuget.org/packages/{package.Id}/{package.NormalizedVersion}";

            if (PackageHelper.TryPrepareUrlForRendering(fugetUrl, out string fugetReadyUrl))
            {
                viewModel.FuGetUrl = fugetReadyUrl;
            }

            viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType;
            viewModel.LicenseExpression   = package.LicenseExpression;

            if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
            {
                viewModel.LicenseUrl = licenseUrl;

                var licenseNames = package.LicenseNames;
                if (!string.IsNullOrEmpty(licenseNames))
                {
                    viewModel.LicenseNames = licenseNames.Split(',').Select(l => l.Trim()).ToList();
                }
            }

            PackageDeprecation deprecation = null;

            if (packageKeyToDeprecation != null && packageKeyToDeprecation.TryGetValue(package.Key, out deprecation))
            {
                viewModel.DeprecationStatus = deprecation.Status;
            }
            else
            {
                viewModel.DeprecationStatus = PackageDeprecationStatus.NotDeprecated;
            }

            PackageVulnerabilitySeverity?maxVulnerabilitySeverity = null;

            if (packageKeyToVulnerabilities != null &&
                packageKeyToVulnerabilities.TryGetValue(package.Key, out var vulnerabilities) &&
                vulnerabilities != null && vulnerabilities.Any())
            {
                viewModel.Vulnerabilities          = vulnerabilities;
                maxVulnerabilitySeverity           = viewModel.Vulnerabilities.Max(v => v.Severity); // cache for messaging
                viewModel.MaxVulnerabilitySeverity = maxVulnerabilitySeverity.Value;
            }
            else
            {
                viewModel.Vulnerabilities          = null;
                viewModel.MaxVulnerabilitySeverity = default;
            }

            viewModel.PackageWarningIconTitle =
                GetWarningIconTitle(viewModel.Version, deprecation, maxVulnerabilitySeverity);

            return(viewModel);
        }