Exemple #1
0
        public bool Deploy(ZipPackage package, ILog logger)
        {
            var options = package.GetPackageOptions <XCopyOptions>();

            if (!_fileSystem.DirectoryExists(options.Destination))
            {
                logger.Error("{0} doesn't exist. Please create the folder before deploying!");

                return(false);
            }

            logger.Info("Deploying xcopy package to {0}".Fmt(options.Destination));

            foreach (var file in package.GetFiles())
            {
                _fileSystem.EnsureDirectoryExists(options.Destination);

                using (var stream = file.GetStream())
                {
                    var destination = Path.Combine(options.Destination, file.Path);

                    new FileInfo(destination).Directory.Create(); // ensure directory is created
                    FileStream targetFile = File.OpenWrite(destination);
                    stream.CopyTo(targetFile);
                    targetFile.Close();
                }
            }

            return(true);
        }
        public bool Deploy(ZipPackage package, ILog logger)
        {
            var options = package.GetPackageOptions<XCopyOptions>();

            if (!_fileSystem.DirectoryExists(options.Destination))
            {
                logger.Error("{0} doesn't exist. Please create the folder before deploying!");

                return false;
            }

            logger.Info("Deploying xcopy package to {0}".Fmt(options.Destination));

            foreach (var file in package.GetFiles())
            {
                _fileSystem.EnsureDirectoryExists(options.Destination);

                using (var stream = file.GetStream())
                {
                    var destination = Path.Combine(options.Destination, file.Path);

                    new FileInfo(destination).Directory.Create(); // ensure directory is created
                    FileStream targetFile = File.OpenWrite(destination);
                    stream.CopyTo(targetFile);
                    targetFile.Close();
                }
            }

            return true;
        }
        public void AddFolder(string folderPath)
        {
            log.Debug("Using package versions from folder: " + folderPath);
            foreach (var file in Directory.GetFiles(folderPath, "*.nupkg", SearchOption.AllDirectories))
            {
                log.Debug("Package file: " + file);
                var package = new NuGet.ZipPackage(file);

                Add(package.Id, package.Version.ToString());
            }
        }
        public void AddFolder(string folderPath)
        {
            log.Debug("Using package versions from folder: " + folderPath);
            foreach (var file in Directory.GetFiles(folderPath, "*.nupkg", SearchOption.AllDirectories))
            {
                log.Debug("Package file: " + file);
                var package = new NuGet.ZipPackage(file);

                Add(package.Id, package.Version.ToString());
            }
        }
Exemple #5
0
        private MetadataEntry[] GetPackageMetadata(string path, string packageFormat)
        {
            var gateway = gatewayVersionExtractors.SingleOrDefault(g => g.GetType().FullName.Contains(packageFormat));

            if (gateway != null)
            {
                var zipPackage = new NuGet.ZipPackage(Path.Combine(configuration.DataPath, path));
                var version    = gateway.Extract(zipPackage);
                return(version.Metadata);
            }
            return(null);
        }
Exemple #6
0
        private static void UnzipNuGetPackage()
        {
            Console.WriteLine();
            Console.WriteLine("Unpacking downloaded NuGet Package");

            string root = "c:\\";


            Console.WriteLine("Directory to unpack: " + unzipDir);

            foreach (var package in attachments)
            {
                NuGet.ZipPackage myPack = new NuGet.ZipPackage(downloadDir + package);
                var content             = myPack.GetFiles();
                myPack.ExtractContents(new NuGet.PhysicalFileSystem(root), unzipDir);
                Console.WriteLine("Package Id: " + myPack.Id);
                //Console.WriteLine("Content Files Count: " + content.Count());
            }
        }
Exemple #7
0
        internal PackageItem GetPackageByFilePath(string filePath)
        {
            // todo: currently requires nupkg file in place.

            if (PackageHelper.IsPackageFile(filePath))
            {
                var package = new ZipPackage(filePath);
                var source  = ResolvePackageSource(filePath);

                return(new PackageItem {
                    FastPath = MakeFastPath(source, package.Id, package.Version.ToString()),
                    PackageSource = source,
                    Package = package,
                    IsPackageFile = true,
                    FullPath = filePath,
                });
            }
            return(null);
        }
        private async Task DownloadAndExtractRelease(HttpClient webClient, DataModel.Release releaseToDownload)
        {
            // download latest, based on package id and version (storage in {hordebasedir}\packages
            _log.InfoFormat("Downloading {packageName} - {version}", releaseToDownload.Id, releaseToDownload.Version);
            var fileResult = await webClient.GetAsync("/.well-known/releases/" + releaseToDownload.Id + "/" + releaseToDownload.Version);

            fileResult.EnsureSuccessStatusCode();

            var fileName = fileResult
                .Content
                .Headers
                .First(x => x.Key.Equals("Content-Disposition", StringComparison.InvariantCultureIgnoreCase))
                .Value
                .Single()
                .Replace("attachment; filename=", string.Empty).Replace("\"", string.Empty);

            var destinationFileNameAndPath = Path.Combine(_configurationManager.WorkingDirectory, "packages", fileName);
            var destinationFolder = Path.GetDirectoryName(destinationFileNameAndPath);

            if (!Directory.Exists(destinationFolder))
            {
                _log.TraceFormat("Creating '{destination}'", destinationFolder);
                Directory.CreateDirectory(destinationFolder);
            }

            if (File.Exists(destinationFileNameAndPath))
            {
                _log.Trace("Package exists.  Removing existing package before we store the latest downloaded file.");
                File.Delete(destinationFileNameAndPath);
            }

            _log.InfoFormat("File will be stored at: '{0}'", destinationFileNameAndPath);

            using (var fStream = File.OpenWrite(destinationFileNameAndPath))
            {
                await fileResult.Content.CopyToAsync(fStream);
            }

            var pkg = new NuGet.ZipPackage(destinationFileNameAndPath);
            var zipFileInfo = new FileInfo(fileName);
            var zipFolderName = zipFileInfo.Name;
            zipFolderName = zipFolderName.Substring(0, zipFolderName.Length - zipFileInfo.Extension.Length);
            pkg.ExtractContents(new NuGet.PhysicalFileSystem(_configurationManager.HoardeBaseDirectory), zipFolderName);
        }