Пример #1
0
        public async Task <JObject> CreatePackageBlob(PackageInput packageInput)
        {
            var rootUri = GetPackageUri(packageInput.Identity);

            var json = JsonUtility.Create(rootUri, new string[] { "Package", "http://schema.nuget.org/catalog#Permalink" });

            var packageDetailsFile = _context.Source.Get(packageInput.PackageDetailsUri);

            if (!await packageDetailsFile.Exists(_context.Log, _context.Token))
            {
                throw new FileNotFoundException($"Unable to find {packageDetailsFile.EntityUri.AbsoluteUri}");
            }

            var detailsJson = await packageDetailsFile.GetJson(_context.Log, _context.Token);

            json.Add("catalogEntry", packageInput.PackageDetailsUri.AbsoluteUri);
            json.Add("packageContent", detailsJson["packageContent"].ToString());
            json.Add("registration", GetIndexUri(packageInput.Identity));

            var copyProperties = new List <string>()
            {
                "listed",
                "published",
            };

            JsonUtility.CopyProperties(detailsJson, json, copyProperties, skipEmpty: true);

            var context = JsonUtility.GetContext("Package");

            json.Add("@context", context);

            return(JsonLDTokenComparer.Format(json));
        }
Пример #2
0
        public async Task <JObject> CreatePackageBlobAsync(PackageInput packageInput)
        {
            var rootUri = GetPackageUri(packageInput.Identity);

            var json = JsonUtility.Create(rootUri, new string[] { "Package", "http://schema.nuget.org/catalog#Permalink" });

            json.Add("catalogEntry", packageInput.PackageDetails.GetIdUri().AbsoluteUri);
            json.Add("packageContent", packageInput.PackageDetails["packageContent"].ToString());
            json.Add("registration", GetIndexUri(packageInput.Identity));

            var copyProperties = new List <string>()
            {
                "listed",
                "published",
            };

            JsonUtility.CopyProperties(packageInput.PackageDetails, json, copyProperties, skipEmpty: true);

            // Copy the catalog entry into the package blob. This allows the feed to
            // save this info even if the catalog is disabled.
            // Note that this is different from NuGet.org, so the sleet: namespace is used.
            var catalogEntry = (JObject)packageInput.PackageDetails.DeepClone();

            // Clear packageEntries, this can be very large in some cases.
            catalogEntry.Remove("packageEntries");

            json.Add("sleet:catalogEntry", catalogEntry);

            var context = await JsonUtility.GetContextAsync("Package");

            json.Add("@context", context);

            return(JsonLDTokenComparer.Format(json));
        }
Пример #3
0
        /// <summary>
        /// Create a package item entry.
        /// </summary>
        public async Task <JObject> CreateItem(PackageInput packageInput)
        {
            var rootUri = GetPackageUri(packageInput.Identity);

            var json = JsonUtility.Create(rootUri, "Package");

            json.Add("commitId", _context.CommitId.ToString().ToLowerInvariant());
            json.Add("commitTimeStamp", DateTimeOffset.UtcNow.GetDateString());

            var packageDetailsFile = _context.Source.Get(packageInput.PackageDetailsUri);
            var detailsJson        = await packageDetailsFile.GetJson(_context.Log, _context.Token);

            json.Add("packageContent", detailsJson["packageContent"].ToString());
            json.Add("registration", GetIndexUri(packageInput.Identity));

            var copyProperties = new List <string>()
            {
                "@id",
                "@type",
                "authors",
                "dependencyGroups",
                "description",
                "iconUrl",
                "id",
                "language",
                "licenseUrl",
                "listed",
                "minClientVersion",
                "packageContent",
                "projectUrl",
                "published",
                "requireLicenseAcceptance",
                "summary",
                "tags",
                "title",
                "version"
            };

            var catalogEntry = new JObject();

            JsonUtility.CopyProperties(detailsJson, catalogEntry, copyProperties, skipEmpty: true);

            json.Add("catalogEntry", catalogEntry);

            return(JsonLDTokenComparer.Format(json));
        }
Пример #4
0
        /// <summary>
        /// Create a package item entry.
        /// </summary>
        public JObject CreateItem(PackageInput packageInput)
        {
            var rootUri = GetPackageUri(packageInput.Identity);

            var json = JsonUtility.Create(rootUri, "Package");

            json.Add("commitId", _context.CommitId.ToString().ToLowerInvariant());
            json.Add("commitTimeStamp", DateTimeOffset.UtcNow.GetDateString());

            json.Add("packageContent", packageInput.PackageDetails["packageContent"].ToString());
            json.Add("registration", GetIndexUri(packageInput.Identity));

            var copyProperties = new List <string>()
            {
                "@id",
                "@type",
                "authors",
                "dependencyGroups",
                "description",
                "iconUrl",
                "id",
                "language",
                "licenseUrl",
                "listed",
                "minClientVersion",
                "packageContent",
                "projectUrl",
                "published",
                "requireLicenseAcceptance",
                "summary",
                "tags",
                "title",
                "version"
            };

            var catalogEntry = new JObject();

            JsonUtility.CopyProperties(packageInput.PackageDetails, catalogEntry, copyProperties, skipEmpty: true);

            json.Add("catalogEntry", catalogEntry);

            // Format package details at creation time, and avoid doing it again later to improve perf.
            return(JsonLDTokenComparer.Format(json));
        }
Пример #5
0
        /// <summary>
        /// Create a result containing all versions of the package. The passed in identity
        /// may or may not be the latest one that is shown.
        /// </summary>
        private async Task <JObject> CreatePackageEntry(PackageIdentity package, bool add)
        {
            var packageIndex = new PackageIndex(_context);
            var versions     = await packageIndex.GetPackageVersions(package.Id);

            if (add)
            {
                versions.Add(package.Version);
            }
            else
            {
                versions.Remove(package.Version);
            }

            var latest         = versions.Max();
            var latestIdentity = new PackageIdentity(package.Id, latest);

            var packageUri   = Registrations.GetPackageUri(_context.Source.BaseURI, latestIdentity);
            var packageEntry = JsonUtility.Create(packageUri, "Package");

            var registrationUri = Registrations.GetIndexUri(_context.Source.BaseURI, package.Id);

            // Read the catalog entry from the package blob. The catalog may not be enabled.
            var registrations = new Registrations(_context);
            var catalogEntry  = await registrations.GetCatalogEntryFromPackageBlob(latestIdentity);

            Debug.Assert(catalogEntry != null);

            packageEntry.Add("registration", registrationUri.AbsoluteUri);

            var copyProperties = new[]
            {
                "id",
                "version",
                "description",
                "summary",
                "title",
                "iconUrl",
                "licenseUrl",
                "projectUrl",
                "tags"
            };

            JsonUtility.CopyProperties(catalogEntry, packageEntry, copyProperties, skipEmpty: false);

            var copyPropertiesDelimited = new[]
            {
                "authors",
                "owners"
            };

            JsonUtility.CopyDelimitedProperties(catalogEntry, packageEntry, copyPropertiesDelimited, ',');

            JsonUtility.RequireArrayWithEmptyString(packageEntry, new[] { "tags", "authors" });

            packageEntry.Add("totalDownloads", 0);

            var versionsArray = new JArray();

            packageEntry.Add("versions", versionsArray);

            foreach (var version in versions.OrderBy(v => v))
            {
                var versionIdentity = new PackageIdentity(package.Id, version);
                var versionUri      = Registrations.GetPackageUri(_context.Source.BaseURI, versionIdentity);

                var versionEntry = JsonUtility.Create(versionUri, "Package");
                versionEntry.Add("downloads", 0);
                versionEntry.Add("version", version.ToFullVersionString());

                versionsArray.Add(versionEntry);
            }

            return(JsonLDTokenComparer.Format(packageEntry));
        }