-
Notifications
You must be signed in to change notification settings - Fork 693
/
Copy pathDetailedPackageMetadata.cs
122 lines (91 loc) · 4.58 KB
/
DetailedPackageMetadata.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using NuGet.Packaging;
using NuGet.Versioning;
using NuGet.VisualStudio.Internal.Contracts;
namespace NuGet.PackageManagement.UI
{
public class DetailedPackageMetadata
{
public DetailedPackageMetadata()
{
}
public DetailedPackageMetadata(PackageSearchMetadataContextInfo serverData, PackageDeprecationMetadataContextInfo 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;
ReadmeUrl = serverData.ReadmeUrl;
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;
PackagePath = serverData.PackagePath;
// 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);
}
}
}
public string Id { get; set; }
public NuGetVersion Version { get; set; }
public string Summary { get; set; }
public string Description { get; set; }
public string Authors { get; set; }
public string Owners { get; set; }
public Uri IconUrl { get; set; }
public Uri LicenseUrl { get; set; }
public Uri ProjectUrl { get; set; }
public Uri ReadmeUrl { get; set; }
public Uri ReportAbuseUrl { get; set; }
public Uri PackageDetailsUrl { get; set; }
public string PackageDetailsText { get; set; }
public string Tags { get; set; }
public long? DownloadCount { get; set; }
public DateTimeOffset? Published { get; set; }
public IEnumerable<PackageDependencySetMetadata> DependencySets { get; set; }
public bool PrefixReserved { get; set; }
public LicenseMetadata LicenseMetadata { get; set; }
public PackageDeprecationMetadataContextInfo DeprecationMetadata { get; set; }
public IEnumerable<PackageVulnerabilityMetadataContextInfo> Vulnerabilities { get; set; }
public IReadOnlyList<IText> LicenseLinks => PackageLicenseUtilities.GenerateLicenseLinks(this);
private static readonly IReadOnlyList<PackageDependencySetMetadata> NoDependenciesPlaceholder = new PackageDependencySetMetadata[] { new PackageDependencySetMetadata(dependencyGroup: null) };
public string PackagePath { get; set; }
}
}