Esempio n. 1
0
        public Option <Link <FolderPath, FilePath> > CreateArchive(FolderPath SrcDir, FilePath DstPath,
                                                                   bool Overwrite = true, AppMessageObserver Observer = null)
        {
            try
            {
                DstPath.Folder.CreateIfMissing();

                var dstPath = Overwrite
                    ? DstPath.DeleteIfExists().Require()
                    : (DstPath.Exists() ? DstPath.UniqueName() : DstPath);

                using (var stream = new FileStream(DstPath, FileMode.OpenOrCreate))
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
                    {
                        foreach (var srcFile in SrcDir.Files("*.*", true))
                        {
                            Observer?.Invoke(AddingFileToArchive(srcFile, dstPath));
                            var entry = CreateEntry(SrcDir, srcFile, archive);
                            using (var writer = new StreamWriter(entry.Open()))
                                using (var reader = new StreamReader(srcFile))
                                    reader.BaseStream.CopyTo(writer.BaseStream);
                        }
                    }
                }
                return(link(SrcDir, dstPath));
            }
            catch (Exception e)
            {
                return(none <Link <FolderPath, FilePath> >(e));
            }
        }
Esempio n. 2
0
 public static IEnumerable <CreateFileArchive> DefineZipFilesCommands(FolderPath srcPath, FolderPath dstPath)
 => from srcFile in srcPath.Files()
 select new CreateFileArchive
 {
     SourceFiles = roitems(FilePath.Parse(srcFile)),
     ArchivePath = dstPath + srcFile.FileName.AddExtension(".zip"),
     Overwrite   = true
 };
Esempio n. 3
0
 /// <summary>
 /// Copies (non-recursively) the files in the folder to a target folder
 /// </summary>
 /// <param name="dstFolder">The target folder</param>
 /// <param name="match">The files to match</param>
 /// <returns></returns>
 public static IEnumerable <FileCopyResult> CopyFilesTo(this FolderPath folder, FolderPath dstFolder, string match = null)
 => from srcFile in folder.Files(match)
 select srcFile.CopyTo(dstFolder);
Esempio n. 4
0
 /// <summary>
 /// Extracts each zip archive in a folder
 /// </summary>
 /// <param name="C"></param>
 /// <param name="SrcFolder">The folder that contains the zip archives</param>
 /// <param name="DstFolder">The folder that will receive the archive extractions</param>
 /// <param name="PLL">Whether operations should be executed concurently</param>
 /// <returns></returns>
 public static IEnumerable <Option <FlowOneToMany> > UnzipDirFiles(this IApplicationContext C,
                                                                   FolderPath SrcFolder, FolderPath DstFolder, bool PLL = true)
 => C.FileArchiveManager().ExpandArchives(SrcFolder.Files("*.zip"), DstFolder, true, PLL);
Esempio n. 5
0
 static IEnumerable <Link <FilePath> > ArchiveFlows(FolderPath SrcFolder, string Match, FolderPath DstFolder)
 => from src in SrcFolder.Files(Match)
 let dst = DstFolder + src.FileName.ChangeExtension("zip")
           select new Link <FilePath>(src, dst);
Esempio n. 6
0
 public static IEnumerable <Option <Link <FilePath, ReadOnlyList <FilePath> > > > ExtractFiles(this IFileArchiveManager ArchiveManager, FolderPath SrcFolder, FolderPath DstFolder)
 => from src in SrcFolder.Files()
 let dst = FolderPath.Parse(DstFolder)
           select ArchiveManager.ExpandArchive(new Link <FilePath, FolderPath>(src, dst));
Esempio n. 7
0
 static IEnumerable <Link <FilePath> > ArchiveFlows(FolderPath Src, FolderPath Dst)
 => from src in Src.Files()
 let dst = Dst + src.FileName.ChangeExtension("zip")
           select new Link <FilePath>(src, dst);
Esempio n. 8
0
 /// <summary>
 /// Searches the folder according to specified filter and recursion options
 /// </summary>
 /// <param name="folder">The folder to search</param>
 /// <param name="match">The pattern to match, if any</param>
 /// <param name="recursive">Whether the search should be recursive</param>
 /// <returns></returns>
 public static IEnumerable <FilePath> search(FolderPath folder, string match = null, bool recursive = false)
 => folder.Files(match, recursive);
Esempio n. 9
0
 public IEnumerable <Option <Link <FilePath, ReadOnlyList <FilePath> > > > ExpandArchives(FolderPath SrcFolder,
                                                                                          FolderPath DstFolder, bool Overwrite = true)
 => from src in SrcFolder.Files()
 let dst = FolderPath.Parse(DstFolder)
           select ExpandArchive(new Link <FilePath, FolderPath>(src, dst), Overwrite);