public DetailedPackageMetadata(IPackageSearchMetadata serverData,
                                       PackageDeprecationMetadata deprecationMetadata,
                                       long?downloadCount)
        {
            Id             = serverData.Identity.Id;
            Version        = serverData.Identity.Version;
            Summary        = serverData.Summary;
            Description    = serverData.Description;
            Authors        = serverData.Authors;
            Owners         = serverData.Owners;
            IconUrl        = serverData.IconUrl;
            LicenseUrl     = serverData.LicenseUrl;
            ProjectUrl     = serverData.ProjectUrl;
            ReportAbuseUrl = serverData.ReportAbuseUrl;
            // Some server implementations send down an array with an empty string, which ends up as an empty string.
            // In PM UI, we want Tags to work like most other properties from the server (Authors/Owners), and be null, if there is no value.
            Tags          = string.IsNullOrEmpty(serverData.Tags) ? null : serverData.Tags;
            DownloadCount = downloadCount;
            Published     = serverData.Published;

            IEnumerable <PackageDependencyGroup> dependencySets = serverData.DependencySets;

            if (dependencySets != null && dependencySets.Any())
            {
                DependencySets = dependencySets.Select(e => new PackageDependencySetMetadata(e)).ToArray();
            }
            else
            {
                DependencySets = NoDependenciesPlaceholder;
            }

            PrefixReserved      = serverData.PrefixReserved;
            LicenseMetadata     = serverData.LicenseMetadata;
            DeprecationMetadata = deprecationMetadata;
            Vulnerabilities     = serverData.Vulnerabilities;
            _localMetadata      = serverData as LocalPackageSearchMetadata;

            // Determine the package details URL and text.
            PackageDetailsUrl  = null;
            PackageDetailsText = null;
            if (serverData.PackageDetailsUrl != null &&
                serverData.PackageDetailsUrl.IsAbsoluteUri &&
                serverData.PackageDetailsUrl.Host != null)
            {
                PackageDetailsUrl  = serverData.PackageDetailsUrl;
                PackageDetailsText = serverData.PackageDetailsUrl.Host;

                // Special case the subdomain "www." - we hide it. Other subdomains are not hidden.
                const string wwwDot = "www.";
                if (PackageDetailsText.StartsWith(wwwDot, StringComparison.OrdinalIgnoreCase) &&
                    PackageDetailsText.Length > wwwDot.Length)
                {
                    PackageDetailsText = PackageDetailsText.Substring(wwwDot.Length);
                }
            }
        }
Beispiel #2
0
        public DetailedPackageMetadata(IPackageSearchMetadata serverData, long?downloadCount)
        {
            Id             = serverData.Identity.Id;
            Version        = serverData.Identity.Version;
            Summary        = serverData.Summary;
            Description    = serverData.Description;
            Authors        = serverData.Authors;
            Owners         = serverData.Owners;
            IconUrl        = serverData.IconUrl;
            LicenseUrl     = serverData.LicenseUrl;
            ProjectUrl     = serverData.ProjectUrl;
            ReportAbuseUrl = serverData.ReportAbuseUrl;
            Tags           = serverData.Tags;
            DownloadCount  = downloadCount;
            Published      = serverData.Published;
            DependencySets = serverData.DependencySets?
                             .Select(e => new PackageDependencySetMetadata(e))
                             ?? new PackageDependencySetMetadata[] { };
            HasDependencies = DependencySets.Any(
                dependencySet => dependencySet.Dependencies != null && dependencySet.Dependencies.Count > 0);
            PrefixReserved      = serverData.PrefixReserved;
            LicenseMetadata     = serverData.LicenseMetadata;
            DeprecationMetadata = serverData.DeprecationMetadata;
            _localMetadata      = serverData as LocalPackageSearchMetadata;

            // Determine the package details URL and text.
            PackageDetailsUrl  = null;
            PackageDetailsText = null;
            if (serverData.PackageDetailsUrl != null &&
                serverData.PackageDetailsUrl.IsAbsoluteUri &&
                serverData.PackageDetailsUrl.Host != null)
            {
                PackageDetailsUrl  = serverData.PackageDetailsUrl;
                PackageDetailsText = serverData.PackageDetailsUrl.Host;

                // Special case the subdomain "www." - we hide it. Other subdomains are not hidden.
                const string wwwDot = "www.";
                if (PackageDetailsText.StartsWith(wwwDot, StringComparison.OrdinalIgnoreCase) &&
                    PackageDetailsText.Length > wwwDot.Length)
                {
                    PackageDetailsText = PackageDetailsText.Substring(wwwDot.Length);
                }
            }
        }