Exemplo n.º 1
0
        /// <summary>
        /// Prepares a Zipper.ZipFile object based on the ZipperConfiguration provided.
        /// </summary>
        /// <param name="zipFile"></param>
        /// <param name="config"></param>
        private static void PrepareZipFile(ZipFile zipFile, ZipConfiguration config)
        {
            var foundFiles = from file in config.Source.EnumerateFiles()
                             where file.Extension == config.Extension
                             orderby file.LastWriteTime ascending
                             select new ZipItem(file.FullName, file.Length, file.LastWriteTime);

            zipFile.ZipItems.AddRange(foundFiles.ToList());

            if (zipFile.ZipItems.Count == 0)
            {
                return;
            }

            if (zipFile.ZipItems.Count == config.SkipAmount)
            {
                zipFile.ZipItems.Clear();
            }
            else
            {
                int start = 0;
                if (config.Strategy == ZipConfiguration.SkipStrategy.START)
                {
                    zipFile.ZipItems.RemoveRange(start, config.SkipAmount);
                }
                else
                {
                    start = zipFile.ZipItems.Count - config.SkipAmount - 1;
                    zipFile.ZipItems.RemoveRange(start, config.SkipAmount);
                }
            }
        }
Exemplo n.º 2
0
        public static ZipFile Zip(ZipConfiguration config)
        {
            config.Validate();

            var zipFile = new ZipFile();

            zipFile.File = config.Destination;

            using (var zip = new Ionic.Zip.ZipFile(zipFile.File.FullName))
            {
                PrepareZipFile(zipFile, config);

                var fileNames = from f in zipFile.ZipItems select f.Name;

                zip.AddFiles(fileNames.ToList(), directoryPathInArchive: "");
                zip.ParallelDeflateThreshold = -1;
                zip.Save();
            }

            return(zipFile);
        }
Exemplo n.º 3
0
 public ZippingService(IOptions <ZipConfiguration> config)
 {
     _zipConfig = config.Value;
 }