コード例 #1
0
        /// <summary>
        /// Returns all packages in the feed.
        /// Id -> Version
        /// </summary>
        private async Task <PackageSets> GetPackageSetsAsync()
        {
            var index = new PackageSets();

            if (await File.ExistsWithFetch(Context.Log, Context.Token))
            {
                var json = await GetJsonOrTemplateAsync();

                var packagesNode = json["packages"] as JObject;

                if (packagesNode == null)
                {
                    throw new InvalidDataException("Packages node missing from sleet.packageindex.json");
                }

                index.Packages = GetPackageSetFromJson(packagesNode);

                var symbolsNode = json["symbols"] as JObject;

                // This node may not exist for older feeds
                if (symbolsNode != null)
                {
                    index.Symbols = GetPackageSetFromJson(symbolsNode);
                }
            }

            return(index);
        }
コード例 #2
0
ファイル: SleetOperations.cs プロジェクト: zdarovka/Sleet
 public SleetOperations(PackageSets originalIndex, PackageSets updatedIndex, List <PackageInput> toAdd, List <PackageInput> toRemove)
 {
     OriginalIndex = originalIndex ?? throw new ArgumentNullException(nameof(originalIndex));
     UpdatedIndex  = updatedIndex ?? throw new ArgumentNullException(nameof(updatedIndex));
     ToAdd         = toAdd ?? throw new ArgumentNullException(nameof(toAdd));
     ToRemove      = toRemove ?? throw new ArgumentNullException(nameof(toRemove));
 }
コード例 #3
0
        private Task Save(PackageSets index)
        {
            // Create updated index
            var json    = CreateJson(index);
            var isEmpty = (index.Packages.Index.Count < 1) && (index.Symbols.Index.Count < 1);

            return(SaveAsync(json, isEmpty));
        }
コード例 #4
0
        public static async Task <HashSet <PackageIdentity> > ResolvePackageSets(PackageSets packageSets)
        {
            var set = new HashSet <PackageIdentity>();

            set.UnionWith(await packageSets.Packages.GetPackagesAsync());
            set.UnionWith(await packageSets.Symbols.GetPackagesAsync());

            return(set);
        }
コード例 #5
0
        private static JObject CreateJson(PackageSets index)
        {
            var json = new JObject
            {
                { "packages", CreatePackageSetJson(index.Packages) },
                { "symbols", CreatePackageSetJson(index.Symbols) }
            };

            return(json);
        }
コード例 #6
0
 /// <summary>
 /// Create the file directly without loading the previous file.
 /// </summary>
 public async Task CreateAsync(PackageSets index)
 {
     using (var timer = PerfEntryWrapper.CreateModifyTimer(File, Context))
     {
         // Create updated index
         var json    = CreateJson(index);
         var isEmpty = (index.Packages.Index.Count < 1) && (index.Symbols.Index.Count < 1);
         await SaveAsync(json, isEmpty);
     }
 }
コード例 #7
0
ファイル: SleetOperations.cs プロジェクト: zdarovka/Sleet
        public static SleetOperations CreateDelete(PackageSets originalIndex, IEnumerable <PackageIdentity> packagesToRemove, IEnumerable <PackageIdentity> symbolsPackagesToRemove)
        {
            var toAdd    = new List <PackageInput>();
            var toRemove = new List <PackageInput>();

            toRemove.AddRange(packagesToRemove.Select(e => PackageInput.CreateForDelete(e, isSymbols: false)));
            toRemove.AddRange(symbolsPackagesToRemove.Select(e => PackageInput.CreateForDelete(e, isSymbols: true)));

            return(Create(originalIndex, toAdd, toRemove));
        }
コード例 #8
0
ファイル: AssetIndexFile.cs プロジェクト: zdarovka/Sleet
        private async Task <PackageSets> GetAssetIndexEntriesAsync()
        {
            var result = new PackageSets();

            var json = await GetJsonOrTemplateAsync();

            result.Packages = GetAssets(json, "packages");
            result.Symbols  = GetAssets(json, "symbols");

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Remove packages from feed without committing
        /// </summary>
        private static async Task RemovePackages(SleetContext context, PackageSets existingPackageSets, HashSet <PackageIdentity> packagesToRemove, bool dryRun, ILogger log)
        {
            var toRemove        = new HashSet <PackageIdentity>();
            var toRemoveSymbols = new HashSet <PackageIdentity>();

            foreach (var package in packagesToRemove)
            {
                var exists        = existingPackageSets.Packages.Exists(package);
                var symbolsExists = existingPackageSets.Symbols.Exists(package);

                if (exists)
                {
                    toRemove.Add(package);
                }

                if (symbolsExists)
                {
                    toRemoveSymbols.Add(package);
                }

                if (exists || symbolsExists)
                {
                    await log.LogAsync(LogLevel.Information, $"Pruning {package.ToString()}");
                }
            }

            if (toRemove.Count < 1 && toRemoveSymbols.Count < 1)
            {
                await log.LogAsync(LogLevel.Information, $"No packages need pruning.");
            }
            else if (!dryRun)
            {
                // Add/Remove packages
                var changeContext = SleetOperations.CreateDelete(existingPackageSets, toRemove, toRemoveSymbols);
                await SleetUtility.ApplyPackageChangesAsync(context, changeContext);
            }
        }
コード例 #10
0
        private static async Task PushPackages(List <PackageInput> packageInputs, SleetContext context, PackageSets existingPackageSets, bool force, bool skipExisting, ILogger log)
        {
            var toAdd    = new List <PackageInput>();
            var toRemove = new List <PackageInput>();

            foreach (var package in packageInputs)
            {
                var packageString = $"{package.Identity.Id} {package.Identity.Version.ToFullString()}";

                if (package.IsSymbolsPackage)
                {
                    packageString += " Symbols";

                    if (!context.SourceSettings.SymbolsEnabled)
                    {
                        await log.LogAsync(LogLevel.Warning, $"Skipping {packageString}, to push symbols packages enable the symbols server on this feed.");

                        // Skip this package
                        continue;
                    }
                }

                var exists = false;

                if (package.IsSymbolsPackage)
                {
                    exists = existingPackageSets.Symbols.Exists(package.Identity);
                }
                else
                {
                    exists = existingPackageSets.Packages.Exists(package.Identity);
                }

                if (exists)
                {
                    if (skipExisting)
                    {
                        await log.LogAsync(LogLevel.Minimal, $"Skip existing package: {packageString}");

                        continue;
                    }
                    else if (force)
                    {
                        toRemove.Add(package);
                        await log.LogAsync(LogLevel.Information, $"Replace existing package: {packageString}");
                    }
                    else
                    {
                        throw new InvalidOperationException($"Package already exists: {packageString}.");
                    }
                }
                else
                {
                    await log.LogAsync(LogLevel.Minimal, $"Add new package: {packageString}");
                }

                // Add to list of packages to push
                toAdd.Add(package);
            }

            await log.LogAsync(LogLevel.Minimal, $"Processing feed changes");

            // Add/Remove packages
            var changeContext = SleetOperations.Create(existingPackageSets, toAdd, toRemove);
            await SleetUtility.ApplyPackageChangesAsync(context, changeContext);
        }
コード例 #11
0
        private static async Task RemovePackages(bool force, ILogger log, SleetContext context, PackageSets existingPackageSets, HashSet <PackageIdentity> packages)
        {
            var toRemove        = new HashSet <PackageIdentity>();
            var toRemoveSymbols = new HashSet <PackageIdentity>();

            foreach (var package in packages)
            {
                var exists        = existingPackageSets.Packages.Exists(package);
                var symbolsExists = existingPackageSets.Symbols.Exists(package);

                if (!exists && !symbolsExists)
                {
                    log.LogInformation($"{package.ToString()} does not exist.");

                    if (force)
                    {
                        // ignore failures
                        continue;
                    }
                    else
                    {
                        throw new InvalidOperationException($"Package does not exists: {package.ToString()}");
                    }
                }

                if (exists)
                {
                    toRemove.Add(package);
                }

                if (symbolsExists)
                {
                    toRemoveSymbols.Add(package);
                }

                var message = $"Removing {package.ToString()}";

                if (exists && symbolsExists)
                {
                    message = $"Removing {package.ToString()} and symbols package for {package.ToString()}";
                }
                else if (symbolsExists)
                {
                    message = $"Removing symbols package {package.ToString()}";
                }

                await log.LogAsync(LogLevel.Information, message);
            }

            // Update feed
            await log.LogAsync(LogLevel.Information, "Removing packages from feed locally");

            // Add/Remove packages
            var changeContext = SleetOperations.CreateDelete(existingPackageSets, toRemove, toRemoveSymbols);
            await SleetUtility.ApplyPackageChangesAsync(context, changeContext);
        }
コード例 #12
0
ファイル: SleetOperations.cs プロジェクト: zdarovka/Sleet
        public static SleetOperations Create(PackageSets originalIndex, List <PackageInput> toAdd, List <PackageInput> toRemove)
        {
            var updated = GetUpdatedIndex(toAdd, toRemove, originalIndex);

            return(new SleetOperations(originalIndex, updated, toAdd, toRemove));
        }
コード例 #13
0
ファイル: SleetOperations.cs プロジェクト: zdarovka/Sleet
 public static SleetOperations CreateDelete(PackageSets originalIndex, IEnumerable <PackageIdentity> packagesToRemove)
 {
     return(CreateDelete(originalIndex, packagesToRemove, new List <PackageIdentity>()));
 }
コード例 #14
0
ファイル: SleetOperations.cs プロジェクト: zdarovka/Sleet
        /// <summary>
        /// Create a new PackageSets with the inputs applied.
        /// </summary>
        private static PackageSets GetUpdatedIndex(List <PackageInput> toAdd, List <PackageInput> toRemove, PackageSets packageIndexBeforeChanges)
        {
            var updatedIndex = packageIndexBeforeChanges.Clone();

            foreach (var input in toRemove)
            {
                var set = input.IsSymbolsPackage ? updatedIndex.Symbols : updatedIndex.Packages;
                set.Index.Remove(input.Identity);
            }

            foreach (var input in toAdd)
            {
                var set = input.IsSymbolsPackage ? updatedIndex.Symbols : updatedIndex.Packages;
                set.Index.Add(input.Identity);
            }

            return(updatedIndex);
        }