Example #1
0
        IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            var fileWithoutExtension = packageFileName.Trim().ToLowerInvariant().EndsWith(".wrap")
                                               ? Path.GetFileNameWithoutExtension(packageFileName)
                                               : packageFileName;

            if (Packages.Any(x => x.FullName.EqualsNoCase(fileWithoutExtension)))
            {
                throw new InvalidOperationException("Package already exists in repository.");
            }

            var inMemoryFile = new InMemoryFile("c:\\" + Guid.NewGuid());

            using (var stream = FileExtensions.OpenWrite(inMemoryFile))
                packageStream.CopyTo(stream);

            var tempFolder = new CachedZipPackage(null, inMemoryFile, null);

            var package = new InMemoryPackage
            {
                Name         = PackageNameUtility.GetName(fileWithoutExtension),
                Version      = PackageNameUtility.GetVersion(fileWithoutExtension),
                Source       = this,
                Dependencies = tempFolder.Dependencies.ToList(),
                Anchored     = tempFolder.Anchored
            };

            Packages.Add(package);
            return(package);
        }
        public void PushPackage(string packageFileName, Stream packageStream)
        {
            packageFileName = PackageNameUtility.NormalizeFileName(packageFileName);

            var packageFile = _directory.GetFile(packageFileName);

            using (var destinationStream = packageFile.OpenWrite())
                StreamExtensions.CopyTo(packageStream, destinationStream);

            var zipPackage = new CachedZipPackage(null, packageFile, null);

            IndexDocument.Document.Root.Add(
                new XElement("wrap",
                             new XAttribute("name", zipPackage.Name),
                             new XAttribute("version", zipPackage.Version),
                             new XElement("link",
                                          new XAttribute("rel", "package"),
                                          new XAttribute("href", packageFile.Name)),
                             zipPackage.Dependencies.Select(x => new XElement("depends", x.ToString()))
                             ));

            SaveIndex(IndexDocument);

            return;
        }
Example #3
0
            protected void when_converting_package()
            {
                var cacheDir = FileSystem.GetDirectory(@"c:\cache\TestPackage-1.0.0.1234");
                var wrapFile = FileSystem.GetFile(@"c:\tmp\TestPackage-1.0.0.1234.wrap");

                //c:\tmp\TestPackage-1.0.0.1234.wrap
                using (var openWrapPackage = wrapFile.OpenWrite())
                    NuGetConverter.Convert(NuPackage, openWrapPackage);

                Package = new CachedZipPackage(Repository, wrapFile, cacheDir);
            }
Example #4
0
            protected void when_converting_package()
            {

                var cacheDir = FileSystem.GetDirectory(@"c:\cache\TestPackage-1.0.0.1234");
                var wrapFile = FileSystem.GetFile(@"c:\tmp\TestPackage-1.0.0.1234.wrap");

                //c:\tmp\TestPackage-1.0.0.1234.wrap
                using(var openWrapPackage = wrapFile.OpenWrite())
                    NuGetConverter.Convert(NuPackage, openWrapPackage);
                
                Package = new CachedZipPackage(Repository, wrapFile, cacheDir);
            }
Example #5
0
            public virtual PackageLocation Publish(IPackageRepository source, string packageFileName, Stream packageStream)
            {
                var wrapFile = PackagesDirectory.GetFile(packageFileName);

                if (wrapFile.Exists)
                {
                    throw new InvalidOperationException(string.Format("Cannot publish package to '{0}' as the file already exists.", wrapFile.Path));
                }

                using (var file = wrapFile.OpenWrite())
                    IO.StreamExtensions.CopyTo(packageStream, file);

                var newPackageCacheDir = _rootCacheDirectory.GetDirectory(wrapFile.NameWithoutExtension);
                var newPackage         = new CachedZipPackage(_parent, wrapFile, newPackageCacheDir);
                var packageLocation    = new PackageLocation(newPackageCacheDir, newPackage);

                PackageLocations.Add(packageLocation);

                return(packageLocation);
            }
Example #6
0
        public IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            packageFileName = PackageNameUtility.NormalizeFileName(packageFileName);

            var wrapFile = BasePath.GetFile(packageFileName);

            if (wrapFile.Exists)
            {
                return(null);
            }

            using (var file = wrapFile.OpenWrite())
                StreamExtensions.CopyTo(packageStream, file);

            var newPackageCacheDir = _rootCacheDirectory.GetDirectory(wrapFile.NameWithoutExtension);
            var newPackage         = new CachedZipPackage(this, wrapFile, newPackageCacheDir);

            Packages.Add(new PackageLocation(newPackageCacheDir, newPackage));
            return(newPackage);
        }
        IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            var fileWithoutExtension = packageFileName.Trim().ToLowerInvariant().EndsWith(".wrap")
                                               ? Path.GetFileNameWithoutExtension(packageFileName)
                                               : packageFileName;
            if (_packages.Any(x => x.FullName.EqualsNoCase(fileWithoutExtension)))
                throw new InvalidOperationException("Package already exists in repository.");

            var inMemoryFile = new InMemoryFile("c:\\" + Guid.NewGuid());
            using (var stream = FileExtensions.OpenWrite(inMemoryFile))
                packageStream.CopyTo(stream);

            var tempFolder = new CachedZipPackage(null, inMemoryFile, null, null);

            var package = new InMemoryPackage
            {
                    Name = PackageNameUtility.GetName(fileWithoutExtension),
                    Version = PackageNameUtility.GetVersion(fileWithoutExtension),
                    Source = this,
                    Dependencies = tempFolder.Dependencies.ToList(),
                    Anchored = tempFolder.Anchored
            };
            _packages.Add(package);
            return package;
        }
Example #8
0
        public IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            packageFileName = PackageNameUtility.NormalizeFileName(packageFileName);

            var wrapFile = BasePath.GetFile(packageFileName);
            if (wrapFile.Exists)
                return null;

            using (var file = wrapFile.OpenWrite())
                StreamExtensions.CopyTo(packageStream, file);

            var newPackageCacheDir = _rootCacheDirectory.GetDirectory(wrapFile.NameWithoutExtension);
            var newPackage = new CachedZipPackage(this, wrapFile, newPackageCacheDir, ExportBuilders.All);
            Packages.Add(new PackageLocation(newPackageCacheDir, newPackage));
            return newPackage;
        }
Example #9
0
        IEnumerable<ICommandOutput> ValidateInputs()
        {
            var namedRepository = GetRemoteRepository(Remote);

            if (namedRepository == null)
            {
                yield return new Errors.UnknownRemoteRepository(Remote);
                foreach (var _ in HintRemoteRepositories()) yield return _;
                yield break;
            }

            if (User != null && Pwd == null)
            {
                yield return new Errors.IncompleteAuthentication();
                yield break;
            }

            _authenticationSupport = namedRepository as ISupportAuthentication;

            if (_authenticationSupport == null)
            {
                yield return new Warning("Remote repository '{0}' does not support authentication, ignoring authentication info.", namedRepository.Name);
                _authenticationSupport = new NullAuthentication();
            }

            _remoteRepository = namedRepository as ISupportPublishing;

            if (_remoteRepository == null)
            {
                yield return new Error("Repository '{0}' doesn't support publishing.", namedRepository.Name);
                yield break;
            }
            if (Path != null)
            {
                var packageFile = FileSystem.GetFile(Path);
                if (!packageFile.Exists)
                {
                    yield return new Errors.FileNotFound(Path);
                    yield break;
                }
                else
                {
                    _packageStream = () => packageFile.OpenRead();
                    _packageFileName = packageFile.Name;
                    var package = new CachedZipPackage(null, packageFile, null, null);
                    _packageName = package.Name;
                    _packageVersion = package.Version;
                }
            }
            else if (Name != null)
            {
                // get latest version of the Named package
                if (!HostEnvironment.CurrentDirectoryRepository.PackagesByName.Contains(Name))
                {
                    yield return new Error("No package named '{0}' was found.", Name);
                    yield break;
                }
                var packageToCopy = HostEnvironment.CurrentDirectoryRepository.PackagesByName[Name].OrderByDescending(x => x.Version).First();
                _packageStream = () => packageToCopy.Load().OpenStream();
                _packageFileName = packageToCopy.FullName + ".wrap";
                _packageName = packageToCopy.Name;
                _packageVersion = packageToCopy.Version;
            }
            else
            {
                yield return new Error("Please specify either a file path using the -Path input, or a name using -Name.");
            }
        }
Example #10
0
        IEnumerable <ICommandOutput> ValidateInputs()
        {
            var namedRepository = GetRemoteRepository(Remote);

            if (namedRepository == null)
            {
                yield return(new Errors.UnknownRemoteRepository(Remote));

                foreach (var _ in HintRemoteRepositories())
                {
                    yield return(_);
                }
                yield break;
            }

            if (User != null && Pwd == null)
            {
                yield return(new Errors.IncompleteAuthentication());

                yield break;
            }

            _authenticationSupport = namedRepository as ISupportAuthentication;

            if (_authenticationSupport == null)
            {
                yield return(new Warning("Remote repository '{0}' does not support authentication, ignoring authentication info.", namedRepository.Name));

                _authenticationSupport = new NullAuthentication();
            }

            _remoteRepository = namedRepository as ISupportPublishing;

            if (_remoteRepository == null)
            {
                yield return(new Error("Repository '{0}' doesn't support publishing.", namedRepository.Name));

                yield break;
            }
            if (Path != null)
            {
                var packageFile = FileSystem.GetFile(Path);
                if (!packageFile.Exists)
                {
                    yield return(new Errors.FileNotFound(Path));

                    yield break;
                }
                else
                {
                    _packageStream   = () => packageFile.OpenRead();
                    _packageFileName = packageFile.Name;
                    var package = new CachedZipPackage(null, packageFile, null);
                    _packageName    = package.Name;
                    _packageVersion = package.Version;
                }
            }
            else if (Name != null)
            {
                // get latest version of the Named package
                if (!HostEnvironment.CurrentDirectoryRepository.PackagesByName.Contains(Name))
                {
                    yield return(new Error("No package named '{0}' was found.", Name));

                    yield break;
                }
                var packageToCopy = HostEnvironment.CurrentDirectoryRepository.PackagesByName[Name].OrderByDescending(x => x.Version).First();
                _packageStream   = () => packageToCopy.Load().OpenStream();
                _packageFileName = packageToCopy.FullName + ".wrap";
                _packageName     = packageToCopy.Name;
                _packageVersion  = packageToCopy.Version;
            }
            else
            {
                yield return(new Error("Please specify either a file path using the -Path input, or a name using -Name."));
            }
        }