using System.ComponentModel; using System.Net.Sockets; using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; using isnd.Data.Packages; using NuGet.Versioning; using System.Collections.Generic; using System; using isnd.Interfaces; using NuGet.Protocol.Core.Types; using NuGet.Protocol; using NuGet.Packaging; using NuGet.Packaging.Core; using System.Threading.Tasks; using isnd.Entities; namespace isnd.Data.Catalog { public class PackageDetails : Permalink, IObject, IPackageSearchMetadata { /// /// Creates a catalog entry /// /// package id /// api Base /// public PackageDetails(PackageVersion pkg, string apiBase): base( apiBase + ApiConfig.Registration + "/" + pkg.PackageId + "/" + pkg.FullString + ".json") { Title = PackageId = pkg.Package.Id; Version = pkg.FullString; Authors = $"{pkg.Package.Owner.FullName} <${pkg.Package.Owner.Email}>"; packageContent = apiBase + pkg.NugetLink; CommitId = pkg.CommitId; Published = CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp; IsListed = !pkg.IsDeleted && pkg.Package.Public; if (pkg.DependencyGroups!=null) { DependencySets = pkg.DependencyGroups.ToDepSetInfo(); } PackageDetailsUrl = new Uri(this.id); // TODO Licence Project Urls, Summary, Title, Owners, etc ... } [JsonProperty("@type")] public string[] RefType { get; protected set; } = new string[] { "PackageDetails" }; /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public PackageDetails(string apiBase, string pkgId, string pkgVersionString, string commitId, DateTimeOffset commitTimeStamp, string authors, Deprecation deprecation, string description, Uri iconUrl, string language, Uri licenseUrl, string licenseExpression, string minClientVersion, Uri projectUrl, bool requireLicenseAcceptance, string summary, string tags, string title, string packageContent, string version, PackageIdentity identity, Uri readmeUrl, Uri reportAbuseUrl, Uri packageDetailsUrl, string owners, bool isListed, bool prefixReserved, LicenseMetadata licenseMetadata) : base( apiBase + ApiConfig.Registration + "/" + pkgId + "/" + pkgVersionString + ".json") { this.CommitId = commitId; this.CommitTimeStamp = commitTimeStamp; this.Authors = authors; this.deprecation = deprecation; this.Description = description; this.IconUrl = iconUrl; this.language = language; this.LicenseUrl = licenseUrl; this.licenseExpression = licenseExpression; this.minClientVersion = minClientVersion; this.ProjectUrl = projectUrl; this.RequireLicenseAcceptance = requireLicenseAcceptance; this.Summary = summary; this.Tags = tags; this.Title = title; this.packageContent = packageContent; this.Version = version; this.Identity = identity; this.ReadmeUrl = readmeUrl; this.ReportAbuseUrl = reportAbuseUrl; this.PackageDetailsUrl = packageDetailsUrl; this.Owners = owners; this.IsListed = isListed; this.PrefixReserved = prefixReserved; this.LicenseMetadata = licenseMetadata; } [JsonProperty("commitId")] public string CommitId { get; set; } [JsonProperty("commitTimeStamp")] public DateTimeOffset CommitTimeStamp { get; set; } /// /// Authors /// /// string or array of strings [JsonProperty("authors")] public string Authors { get; set; } /// /// The deprecation associated with the package /// /// public Deprecation deprecation { get; set; } [JsonProperty("description")] public string Description { get; set; } [JsonProperty("iconUrl")] public Uri IconUrl { get; set; } public string language { get; set; } [JsonProperty("licenseUrl")] public Uri LicenseUrl { get; set; } public string licenseExpression { get; set; } public string minClientVersion { get; set; } [JsonProperty("projectUrl")] public Uri ProjectUrl { get; set; } [JsonProperty("requireLicenseAcceptance")] public bool RequireLicenseAcceptance { get; set; } [JsonProperty("summary")] public string Summary { get; set; } /// /// The tags /// /// [JsonProperty("tags")] public string Tags { get; set; } [JsonProperty("title")] public string Title { get; set; } /// /// The security vulnerabilities of the package /// /// public IEnumerable Vulnerabilities { get; } public string packageContent { get; set; } /// /// A string containing a ISO 8601 timestamp of when the package was published /// /// [JsonProperty("published")] public DateTimeOffset? Published { get; set; } /// /// The full version string after normalization /// /// [Required,JsonRequired] [JsonProperty("version")] public string Version { get; set; } [Required,JsonRequired] [JsonProperty("id")] public string PackageId { get; set; } public long? DownloadCount { get; set; } public PackageIdentity Identity{ get; set; } public Uri ReadmeUrl { get; set; } public Uri ReportAbuseUrl { get; set; } public Uri PackageDetailsUrl { get; set; } public string Owners { get; set; } [JsonProperty("isListed")] public bool IsListed { get; set; } public bool PrefixReserved { get; set; } public LicenseMetadata LicenseMetadata { get; set; } public IEnumerable DependencySets {get; set;} IEnumerable IPackageSearchMetadata.DependencySets => throw new NotImplementedException(); public Task GetDeprecationMetadataAsync() { throw new NotImplementedException(); } public Task> GetVersionsAsync() { throw new NotImplementedException(); } } public class PackageDependencyGroupInfo { private PackageDependencyGroup group; public PackageDependencyGroupInfo(PackageDependencyGroup group) { this.group = group; } } }