Exemplo n.º 1
0
        public void IgnoresInvalidFiles()
        {
            using (new TemporaryFile(CreatePackage("1.0.0.1")))
            using (new TemporaryFile(CreateEmptyFile("1.0.0.2")))
            {
                var store = new PackageStore();

                var packages = store.GetNearestPackages("Acme.Web", new SemanticVersion(1, 1, 1, 1));

                CollectionAssert.AreEquivalent(packages.Select(c => c.Metadata.Version.ToString()), new[] { "1.0.0.1" });
            }
        }
Exemplo n.º 2
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageId, "No package ID was specified. Please pass --packageId YourPackage");
            Guard.NotNullOrWhiteSpace(packageVersion, "No package version was specified. Please pass --packageVersion 1.0.0.0");
            Guard.NotNullOrWhiteSpace(packageHash, "No package hash was specified. Please pass --packageHash YourPackageHash");
            
            SemanticVersion version;
            if(!SemanticVersion.TryParse(packageVersion, out version))
                throw new CommandException(String.Format("Package version '{0}' is not a valid Semantic Version", packageVersion));

            var packageStore = new PackageStore();
            var packageMetadata = new PackageMetadata {Id = packageId, Version = packageVersion, Hash = packageHash};
            var package = packageStore.GetPackage(packageMetadata);
            if (package == null)
            {
                Log.VerboseFormat("Package {0} version {1} hash {2} has not been uploaded.", 
                    packageMetadata.Id, packageMetadata.Version, packageMetadata.Hash);

                Log.VerboseFormat("Finding earlier packages that have been uploaded to this Tentacle.");
                var nearestPackages = packageStore.GetNearestPackages(packageId, version).ToList();
                if (!nearestPackages.Any())
                {
                    Log.VerboseFormat("No earlier packages for {0} has been uploaded", packageId);
                    return 0;
                }

                Log.VerboseFormat("Found {0} earlier {1} of {2} on this Tentacle", 
                    nearestPackages.Count, nearestPackages.Count == 1 ? "version" : "versions", packageId);
                foreach(var nearestPackage in nearestPackages)
                {
                    Log.VerboseFormat("  - {0}: {1}", nearestPackage.Metadata.Version, nearestPackage.FullPath);
                    Log.ServiceMessages.PackageFound(nearestPackage.Metadata.Id, nearestPackage.Metadata.Version, nearestPackage.Metadata.Hash, nearestPackage.FullPath);
                }

                return 0;
            }

            Log.VerboseFormat("Package {0} {1} hash {2} has already been uploaded", package.Metadata.Id, package.Metadata.Version, package.Metadata.Hash);
            Log.ServiceMessages.PackageFound(package.Metadata.Id, package.Metadata.Version, package.Metadata.Hash, package.FullPath, true);
            return 0;
        }