コード例 #1
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int progress   = 0;
            int totalCount = _datCacheEntities.Count();

            BackgroundWorker bgw = (BackgroundWorker)sender;

            for (int i = 0; i < totalCount; i++)
            {
                DatCacheEntity datCacheEntity = _datCacheEntities.ElementAt(i);
                RearchiveStarted(datCacheEntity);

                progress = (int)((float)i / (float)totalCount * 100);
                OverallProgressChanged(progress, string.Format("{0}/{1}", i, totalCount));

                if (bgw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }


                _sevenZipProcessor = new SevenZipProcessor();
                _sevenZipProcessor.OnExceptionOccured += _sevenZipProcessor_OnExceptionOccured;
                _sevenZipProcessor.OnProgressChanged  += _sevenZipProcessor_OnProgressChanged;
                _sevenZipProcessor.OnCompleted        += _sevenZipProcessor_OnCompleted;

                IProcessInfo decomprocessInfo = new DecompressInfo(datCacheEntity.FilePath, ConfigReader.Instance.WorkingDirectory);
                _sevenZipProcessor.Run(decomprocessInfo);

                string extractedFilePath = Path.Combine(ConfigReader.Instance.WorkingDirectory, datCacheEntity.FilenameInArchive);

                if (bgw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                _sevenZipProcessor = new SevenZipProcessor();
                _sevenZipProcessor.OnExceptionOccured += _sevenZipProcessor_OnExceptionOccured;
                _sevenZipProcessor.OnProgressChanged  += _sevenZipProcessor_OnProgressChanged;
                _sevenZipProcessor.OnCompleted        += _sevenZipProcessor_OnCompleted;

                IProcessInfo compressInfo = new CompressInfo(extractedFilePath, datCacheEntity.FilePath, ConfigReader.Instance.WorkingDirectory);
                _sevenZipProcessor.Run(compressInfo);

                if (bgw.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                datCacheEntity.IsArchived = true;
                datCacheEntity.IsAltered  = false;

                RearchiveCompleted(datCacheEntity);
            }
            RearchiveOverallCompleted();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kimran777/GZipTest
        static void Main(string[] args)
        {
            try
            {
                CompressInfo cInfo = ArgsReader.Read(args);

                cInfo = new CompressInfo(CompressionMode.Compress, new FileInfo(@"D:\3221225470.data"), new FileInfo(@"D:\3221225470.data.gz"));


                FileHelper.CheckOutputExist(cInfo.OutFileName);

                var compressor = GZipCompressFactory.Get(cInfo.CompressMode, cInfo.InFileName, cInfo.OutFileName);
                compressor.Start();



                cInfo = new CompressInfo(CompressionMode.Decompress, new FileInfo(@"D:\3221225470.data.gz"), new FileInfo(@"D:\3221225470_Out.data"));

                FileHelper.CheckOutputExist(cInfo.OutFileName);

                compressor = GZipCompressFactory.Get(cInfo.CompressMode, cInfo.InFileName, cInfo.OutFileName);
                compressor.Start();

                //FileInfo inputInfo = new FileInfo(@"D:\1024000.txt");
                //FileInfo outInfo = new FileInfo(@"D:\1024000.txt.gz");

                //FileHelper.CheckOutputExist(outInfo);

                //var compressor = GZipCompressFactory.Get(CompressionMode.Compress, inputInfo, outInfo);
                //compressor.Start();

                //FileInfo inputInfo2 = new FileInfo(@"D:\1024000.txt.gz");
                //FileInfo outInfo2 = new FileInfo(@"D:\1024000_test.txt");

                //FileHelper.CheckOutputExist(outInfo2);

                //var compressor2 = GZipCompressFactory.Get(CompressionMode.Decompress, inputInfo2, outInfo2);
                //compressor2.Start();
            }
            catch (InvalidDataException e)
            {
                Console.WriteLine("Архив повреждён");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }