Ejemplo n.º 1
0
        /// <summary>
        /// Add a package to the catalog.
        /// </summary>
        public async Task AddPackageAsync(PackageInput packageInput)
        {
            // Create package details page
            var addFileList = _context.SourceSettings.CatalogEnabled;

            var packageDetails = await CatalogUtility.CreatePackageDetailsAsync(packageInput, CatalogBaseURI, _context.CommitId, addFileList);

            var packageDetailsUri = JsonUtility.GetIdUri(packageDetails);

            // Add output to the package input for other services to use.
            packageInput.PackageDetails = packageDetails;

            var packageDetailsFile = _context.Source.Get(packageDetailsUri);
            await packageDetailsFile.Write(packageDetails, _context.Log, _context.Token);

            // Create commit
            var pageCommit = CatalogUtility.CreatePageCommit(
                packageInput.Identity,
                packageDetailsUri,
                _context.CommitId,
                SleetOperation.Add,
                "nuget:PackageDetails");

            await AddCatalogEntry(pageCommit, "nuget:lastCreated");
        }
Ejemplo n.º 2
0
        public async Task AddPackageAsync(PackageInput packageInput)
        {
            // Create package details page
            var packageDetails = await CatalogUtility.CreatePackageDetailsAsync(packageInput, CatalogBaseURI, _context.CommitId, writeFileList : false);

            packageInput.PackageDetails = packageDetails;
        }
Ejemplo n.º 3
0
        private async Task CreateDetailsForAdd(PackageInput packageInput)
        {
            // Create a a details page and assign it to the input
            var nupkgUri       = packageInput.GetNupkgUri(_context);
            var packageDetails = await CatalogUtility.CreatePackageDetailsAsync(packageInput, CatalogBaseURI, nupkgUri, _context.CommitId, writeFileList : false);

            packageInput.PackageDetails = packageDetails;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add an entry to the catalog.
        /// </summary>
        private async Task AddCatalogCommits(IEnumerable <JObject> newPageCommits, string lastUpdatedPropertyName)
        {
            // Add catalog page entry
            var catalogIndexJson = await RootIndexFile.GetJson(_context.Log, _context.Token);

            catalogIndexJson["commitId"]        = _context.CommitId.ToString().ToLowerInvariant();
            catalogIndexJson["commitTimeStamp"] = DateTimeOffset.UtcNow.GetDateString();

            var pages = JsonUtility.GetItems(catalogIndexJson);

            var currentPageUri  = GetCurrentPage(catalogIndexJson);
            var currentPageFile = _context.Source.Get(currentPageUri);

            var pageCommits = new List <JObject>();

            var currentPageJson = await currentPageFile.GetJsonOrNull(_context.Log, _context.Token);

            if (currentPageJson != null)
            {
                pageCommits = JsonUtility.GetItems(currentPageJson);
            }
            else
            {
                var newPageEntry = CatalogUtility.CreateCatalogIndexPageEntry(currentPageUri, _context.CommitId);

                var pageArray = (JArray)catalogIndexJson["items"];
                pageArray.Add(newPageEntry);

                // Update pages
                pages = JsonUtility.GetItems(catalogIndexJson);
            }

            // Add all commits, this might go over the max catalog page size.
            // This could be improved to create new pages once over the limit if needed.
            pageCommits.AddRange(newPageCommits);

            // Write catalog page
            var pageJson = await CatalogUtility.CreateCatalogPageAsync(RootIndexFile.EntityUri, currentPageUri, pageCommits, _context.CommitId);

            await currentPageFile.Write(pageJson, _context.Log, _context.Token);

            // Update index
            CatalogUtility.UpdatePageIndex(catalogIndexJson, pageJson, _context.CommitId);

            catalogIndexJson[lastUpdatedPropertyName] = DateTimeOffset.UtcNow.GetDateString();

            catalogIndexJson = JsonLDTokenComparer.Format(catalogIndexJson);

            await RootIndexFile.Write(catalogIndexJson, _context.Log, _context.Token);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add an entry to the catalog.
        /// </summary>
        private async Task AddCatalogEntry(JObject pageCommit, string lastUpdatedPropertyName)
        {
            // Add catalog page entry
            var catalogIndexJson = await RootIndexFile.GetJson(_context.Log, _context.Token);

            catalogIndexJson["commitId"]        = _context.CommitId.ToString().ToLowerInvariant();
            catalogIndexJson["commitTimeStamp"] = DateTimeOffset.UtcNow.GetDateString();

            var pages = JsonUtility.GetItems(catalogIndexJson);

            var currentPageUri  = GetCurrentPage(catalogIndexJson);
            var currentPageFile = _context.Source.Get(currentPageUri);

            var pageCommits = new List <JObject>();

            var currentPageJson = await currentPageFile.GetJsonOrNull(_context.Log, _context.Token);

            if (currentPageJson != null)
            {
                pageCommits = JsonUtility.GetItems(currentPageJson);
            }
            else
            {
                var newPageEntry = CatalogUtility.CreateCatalogIndexPageEntry(currentPageUri, _context.CommitId);

                var pageArray = (JArray)catalogIndexJson["items"];
                pageArray.Add(newPageEntry);

                // Update pages
                pages = JsonUtility.GetItems(catalogIndexJson);
            }

            pageCommits.Add(pageCommit);

            // Write catalog page
            var pageJson = await CatalogUtility.CreateCatalogPageAsync(RootIndexFile.EntityUri, currentPageUri, pageCommits, _context.CommitId);

            await currentPageFile.Write(pageJson, _context.Log, _context.Token);

            // Update index
            CatalogUtility.UpdatePageIndex(catalogIndexJson, pageJson, _context.CommitId);

            catalogIndexJson[lastUpdatedPropertyName] = DateTimeOffset.UtcNow.GetDateString();

            catalogIndexJson = JsonLDTokenComparer.Format(catalogIndexJson);

            await RootIndexFile.Write(catalogIndexJson, _context.Log, _context.Token);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a remove entry and return the page commit.
        /// </summary>
        private async Task <JObject> GetRemoveCommit(PackageIdentity package)
        {
            // Create package details page for the delete
            var packageDetails = await CatalogUtility.CreateDeleteDetailsAsync(package, string.Empty, CatalogBaseURI, _context.CommitId);

            var packageDetailsFile = _context.Source.Get(packageDetails.GetEntityId());

            await packageDetailsFile.Write(packageDetails, _context.Log, _context.Token);

            // Create commit
            return(CatalogUtility.CreatePageCommit(
                       package,
                       packageDetailsFile.EntityUri,
                       _context.CommitId,
                       SleetOperation.Remove,
                       "nuget:PackageDelete"));
        }
Ejemplo n.º 7
0
        // Copy the symbols nupkg to the symbols folder and create a catalog details page for it.
        private async Task AddSymbolsNupkgToFeed(PackageInput package)
        {
            // Write .nupkg to feed
            var packagePath = SymbolsIndexUtility.GetSymbolsNupkgPath(package.Identity);
            var packageFile = _context.Source.Get(packagePath);

            await packageFile.Write(File.OpenRead(package.PackagePath), _context.Log, _context.Token);

            // Write catalog entry to the symbols folder for the package
            var detailsPath = SymbolsIndexUtility.GetSymbolsPackageDetailsPath(package.Identity);
            var detailsFile = _context.Source.Get(detailsPath);

            var commitId = Guid.NewGuid();

            var detailsJson = await CatalogUtility.CreatePackageDetailsWithExactUriAsync(package, detailsFile.EntityUri, packageFile.EntityUri, commitId, writeFileList : false);

            await detailsFile.Write(detailsJson, _context.Log, _context.Token);
        }
Ejemplo n.º 8
0
        public async Task RemovePackageAsync(PackageIdentity package)
        {
            // Create package details page for the delete
            var packageDetails = await CatalogUtility.CreateDeleteDetailsAsync(package, string.Empty, CatalogBaseURI, _context.CommitId);

            var packageDetailsFile = _context.Source.Get(packageDetails.GetEntityId());

            await packageDetailsFile.Write(packageDetails, _context.Log, _context.Token);

            // Create commit
            var pageCommit = CatalogUtility.CreatePageCommit(
                package,
                packageDetailsFile.EntityUri,
                _context.CommitId,
                SleetOperation.Remove,
                "nuget:PackageDelete");

            await AddCatalogEntry(pageCommit, "nuget:lastDeleted");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds a catalog page and returns the commit.
        /// </summary>
        private async Task <JObject> AddPackageToCatalogAndGetCommit(PackageInput packageInput)
        {
            // Create package details page
            var nupkgUri       = packageInput.GetNupkgUri(_context);
            var packageDetails = await CatalogUtility.CreatePackageDetailsAsync(packageInput, CatalogBaseURI, nupkgUri, _context.CommitId, writeFileList : true);

            var packageDetailsUri = JsonUtility.GetIdUri(packageDetails);

            // Add output to the package input for other services to use.
            packageInput.PackageDetails = packageDetails;

            var packageDetailsFile = _context.Source.Get(packageDetailsUri);
            await packageDetailsFile.Write(packageDetails, _context.Log, _context.Token);

            // Create commit
            return(CatalogUtility.CreatePageCommit(
                       packageInput.Identity,
                       packageDetailsUri,
                       _context.CommitId,
                       SleetOperation.Add,
                       "nuget:PackageDetails"));
        }