Esempio n. 1
0
        public ICollection <PackagedFileInfo> ListFiles()
        {
            List <PackagedFileInfo> files = new List <PackagedFileInfo>();

            string directoryPathString       = directoryPath.ToString();
            int    directoryPathStringLength = directoryPathString.Length;

            if (false == directoryPathString.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            {
                directoryPathStringLength++;
            }

            foreach (string fileName in directoryFilesLister.ListFiles(directoryPathString, recursive))
            {
                if (false == fileName.StartsWith(
                        directoryPathString,
                        StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException();
                }

                if (false == LoggingHelper.LogIfFilteredOut(fileName, Filter, logger))
                {
                    continue;
                }

                LocalPath localPath = new LocalPath(
                    fileName.Substring(directoryPathStringLength));
                PackagedFileInfo packagedFileInfo = new PackagedFileInfo(new FullPath(fileName), localPath);
                files.Add(packagedFileInfo);
            }

            return(files);
        }
Esempio n. 2
0
        private bool TryToTransformSingleFileSource(SingleFileSource source, FilesList filesList)
        {
            if (!transformations.ContainsKey(source.Id))
            {
                return(false);
            }

            CopyProcessorTransformation transformation = transformations[source.Id];

            if ((transformation.Options & CopyProcessorTransformationOptions.SingleFile) == 0)
            {
                return(false);
            }

            LocalPath destinationPath = transformation.DestinationPath;

            PackagedFileInfo sourceFile              = source.ListFiles().AsQueryable().First();
            FullPath         destinationFullPath     = destinationRootDir.CombineWith(destinationPath);
            FileFullPath     destinationFileFullPath = destinationFullPath.ToFileFullPath();

            filesList.AddFile(new PackagedFileInfo(destinationFileFullPath));
            copier.Copy(sourceFile.FileFullPath, destinationFileFullPath);

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Defines a transformation for <see cref="SingleFileSource"/> which copies the file to the destination
        /// and renames the file in the process.
        /// </summary>
        /// <param name="sourceId">ID of the <see cref="SingleFileSource"/>.</param>
        /// <param name="destinationFileName">The destination directory and file name (local path).</param>
        /// <returns>This same instance of the <see cref="CopyProcessor"/>.</returns>
        public CopyProcessor AddSingleFileTransformation(string sourceId, LocalPath destinationFileName)
        {
            CopyProcessorTransformation transformation = new CopyProcessorTransformation(
                sourceId, destinationFileName, CopyProcessorTransformationOptions.SingleFile);

            transformations.Add(sourceId, transformation);
            return(this);
        }
Esempio n. 4
0
        public CopyProcessor AddTransformationWithDirFlattening(string sourceId, LocalPath destinationDir)
        {
            CopyProcessorTransformation transformation = new CopyProcessorTransformation(
                sourceId, destinationDir, CopyProcessorTransformationOptions.FlattenDirStructure);

            transformations.Add(sourceId, transformation);
            return(this);
        }
Esempio n. 5
0
        public CopyProcessor AddTransformation(string sourceId, LocalPath destinationDir)
        {
            CopyProcessorTransformation transformation = new CopyProcessorTransformation(
                sourceId, destinationDir, CopyProcessorTransformationOptions.None);

            transformations.Add(sourceId, transformation);
            return(this);
        }
Esempio n. 6
0
        private ICompositeFilesSource ProcessPrivate(
            ICompositeFilesSource compositeFilesSource,
            bool isRoot)
        {
            CompositeFilesSource transformedCompositeSource = isRoot
                                                                  ? new StandardPackageDef(compositeFilesSource.Id)
                                                                  : new CompositeFilesSource(compositeFilesSource.Id);

            foreach (IFilesSource filesSource in compositeFilesSource.ListChildSources())
            {
                if (filesSource is ICompositeFilesSource)
                {
                    throw new NotImplementedException("Child composites are currently not supported");
                }

                FilesList filesList = new FilesList(filesSource.Id);

                LocalPath destinationPath = FindDestinationPathForSource(filesSource.Id);

                foreach (PackagedFileInfo sourceFile in filesSource.ListFiles())
                {
                    if (false == LoggingHelper.LogIfFilteredOut(sourceFile.FullPath.ToString(), filter, logger))
                    {
                        continue;
                    }

                    FullPath destinationFileName = new FullPath(destinationRootDir);
                    destinationFileName = destinationFileName.CombineWith(destinationPath);

                    if (sourceFile.LocalPath != null)
                    {
                        destinationFileName = destinationFileName.CombineWith(sourceFile.LocalPath);
                    }
                    else
                    {
                        destinationFileName =
                            destinationFileName.CombineWith(new LocalPath(Path.GetFileName(
                                                                              sourceFile.FullPath.ToString())));
                    }

                    string destFile = Path.GetFileName(destinationFileName.ToString());
                    if (fileTransformations.ContainsKey(destFile))
                    {
                        destinationFileName = new FullPath(Path.Combine(
                                                               Path.GetDirectoryName(destinationFileName.ToString()),
                                                               fileTransformations[destFile]));
                    }

                    filesList.AddFile(new PackagedFileInfo(destinationFileName));

                    copier.Copy(sourceFile.FullPath.ToString(), destinationFileName.ToString());
                }

                transformedCompositeSource.AddFilesSource(filesList);
            }

            return(transformedCompositeSource);
        }
Esempio n. 7
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            LocalPath that = (LocalPath)obj;

            return(string.Equals(localPath, that.localPath));
        }
Esempio n. 8
0
        private void TransformSource(IFilesSource filesSource, FilesList filesList)
        {
            CopyProcessorTransformation transformation = FindTransformationForSource(filesSource.Id);
            bool flattenDirs = (transformation.Options & CopyProcessorTransformationOptions.FlattenDirStructure) != 0;

            LocalPath destinationPath = transformation.DestinationPath;

            foreach (PackagedFileInfo sourceFile in filesSource.ListFiles())
            {
                if (false ==
                    LoggingHelper.LogIfFilteredOut(sourceFile.FileFullPath.ToString(), filter, taskContext))
                {
                    continue;
                }

                FullPath destinationFullPath = destinationRootDir.CombineWith(destinationPath);

                if (sourceFile.LocalPath != null)
                {
                    LocalPath destLocalPath = sourceFile.LocalPath;
                    if (flattenDirs)
                    {
                        destLocalPath = destLocalPath.Flatten;
                    }

                    destinationFullPath = destinationFullPath.CombineWith(destLocalPath);
                }
                else
                {
                    destinationFullPath =
                        destinationFullPath.CombineWith(new LocalPath(sourceFile.FileFullPath.FileName));
                }

                string destFile = destinationFullPath.FileName;
                if (fileTransformations.ContainsKey(destFile))
                {
                    destinationFullPath = destinationFullPath.ParentPath.CombineWith(
                        fileTransformations[destFile]);
                }

                FileFullPath destinationFileFullPath = destinationFullPath.ToFileFullPath();
                filesList.AddFile(new PackagedFileInfo(destinationFileFullPath));

                copier.Copy(sourceFile.FileFullPath, destinationFileFullPath);
            }
        }
Esempio n. 9
0
        public void ZipFiles(
            FileFullPath zipFileName,
            FullPath baseDir,
            int?compressionLevel,
            IEnumerable <FileFullPath> filesToZip)
        {
            taskContext.WriteInfo("Zipping {0}", zipFileName);

            CreateDirectoryTask createDirectoryTask = new CreateDirectoryTask(
                zipFileName.Directory.ToString(),
                false);

            createDirectoryTask.Execute(taskContext);

            using (FileStream zipFileStream = new FileStream(
                       zipFileName.ToString(),
                       FileMode.Create,
                       FileAccess.ReadWrite,
                       FileShare.None))
            {
                using (ZipOutputStream zipStream = new ZipOutputStream(zipFileStream))
                {
                    if (compressionLevel.HasValue)
                    {
                        zipStream.SetLevel(compressionLevel.Value);
                    }

                    buffer = new byte[1024 * 1024];

                    foreach (FileFullPath fileName in filesToZip)
                    {
                        LocalPath debasedFileName = fileName.ToFullPath().DebasePath(baseDir);
                        string    cleanName       = ZipEntry.CleanName(debasedFileName.ToString());

                        //environment.LogMessage("Zipping file '{0}'", basedFileName);
                        AddFileToZip(fileName, cleanName, zipStream);
                    }
                }
            }
        }
Esempio n. 10
0
        public ICollection <PackagedFileInfo> ListFiles()
        {
            List <PackagedFileInfo> files = new List <PackagedFileInfo>();

            foreach (string fileName in directoryFilesLister.ListFiles(
                         directoryPath.ToString(),
                         recursive))
            {
                FileFullPath fileNameFullPath = new FileFullPath(fileName);
                LocalPath    debasedFileName  = fileNameFullPath.ToFullPath().DebasePath(directoryPath);

                if (false == LoggingHelper.LogIfFilteredOut(fileName, Filter, taskContext))
                {
                    continue;
                }

                PackagedFileInfo packagedFileInfo = new PackagedFileInfo(fileNameFullPath, debasedFileName);
                files.Add(packagedFileInfo);
            }

            return(files);
        }
Esempio n. 11
0
 public CopyProcessor AddTransformation(string sourceId, LocalPath destinationDir)
 {
     transformations.Add(sourceId, destinationDir);
     return(this);
 }
Esempio n. 12
0
 public LocalPath CombineWith(LocalPath path)
 {
     return(new LocalPath(Path.Combine(localPath, path.ToString())));
 }
Esempio n. 13
0
 public FullPath CombineWith(LocalPath localPath)
 {
     return(new FullPath(Path.Combine(fullPath, localPath.ToString())));
 }