Esempio 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");
        }
Esempio n. 2
0
        /// <summary>
        /// Write settings.
        /// </summary>
        public static void Set(JObject settingsJson, IDictionary <string, string> settings)
        {
            var id = JsonUtility.GetIdUri(settingsJson);

            settingsJson["feedSettings"] = new JArray(
                settings.OrderBy(e => e.Key, StringComparer.OrdinalIgnoreCase)
                .Where(e => !string.IsNullOrEmpty(e.Key) && !string.IsNullOrEmpty(e.Value))
                .Select(e => CreateSettingEntry(id, e)));

            settingsJson["lastEdited"] = DateTimeOffset.UtcNow.GetDateString();
        }
Esempio n. 3
0
        /// <summary>
        /// Update the catalog page and index.json file.
        /// </summary>
        public static void UpdatePageIndex(JObject catalogIndexJson, JObject currentPageJson, Guid commitId)
        {
            var pages          = JsonUtility.GetItems(catalogIndexJson);
            var currentPageUri = JsonUtility.GetIdUri(currentPageJson);
            var pageCommits    = JsonUtility.GetItems(currentPageJson);

            var pageEntry = pages.Where(e => JsonUtility.GetIdUri(e).Equals(currentPageUri)).Single();

            pageEntry["commitId"]        = commitId.ToString().ToLowerInvariant();
            pageEntry["commitTimeStamp"] = DateTimeOffset.UtcNow.GetDateString();
            pageEntry["count"]           = pageCommits.Count;
            catalogIndexJson["count"]    = pages.Count;
        }
Esempio n. 4
0
        /// <summary>
        /// Uri of the latest index page.
        /// </summary>
        public Uri GetCurrentPage(JObject indexJson)
        {
            var entries = JsonUtility.GetItems(indexJson);
            var nextId  = entries.Count;

            var latest = entries.OrderByDescending(GetCommitTime).FirstOrDefault();

            if (latest != null)
            {
                if (latest["count"].ToObject <int>() < _context.SourceSettings.CatalogPageSize)
                {
                    return(JsonUtility.GetIdUri(latest));
                }
            }

            // next page
            return(UriUtility.GetPath(CatalogBaseURI, $"page.{nextId}.json"));
        }
Esempio n. 5
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"));
        }
Esempio n. 6
0
 /// <summary>
 /// Returns the @id as a URI
 /// </summary>
 public static Uri GetIdUri(this JObject json)
 {
     return(JsonUtility.GetIdUri(json));
 }