示例#1
0
        public void Test_compress_to_extract_roundtrip()
        {
            const string originalContent = "Hello world!";
            var          originalPath    = _tempDirectoryPath.Join("original.txt");

            originalPath.WriteAllText(originalContent);

            var sevenZip = new SevenZip(silent: false);
            var zipPath  = _tempDirectoryPath.Join("compressed.7z");

            sevenZip.Compress(originalPath, zipPath);
            zipPath.IsFile().Should().BeTrue();

            var extractedDirectoryPath = _tempDirectoryPath.Join("extracted");

            extractedDirectoryPath.CreateDirectory();
            sevenZip.Extract(zipPath, extractedDirectoryPath);

            var extractedPath = extractedDirectoryPath.Join("original.txt");

            extractedDirectoryPath.IsDirectory().Should().BeTrue();
            extractedPath.IsFile().Should().BeTrue();

            var extractedContent = extractedPath.ReadAllText();

            extractedContent.Should().Be(originalContent);
        }
示例#2
0
        public void Test_extract_excluding_path()
        {
            const string originalContent = "Hello world!";
            var          originalDirPath = _tempDirectoryPath.Join("original");

            originalDirPath.CreateDirectory();
            var originalPath1 = originalDirPath.Join("to_be_extracted.txt");
            var originalPath2 = originalDirPath.Join("to_be_excluded.txt");

            originalPath1.WriteAllText(originalContent);
            originalPath2.WriteAllText(originalContent);

            var sevenZip = new SevenZip(silent: false);
            var zipPath  = _tempDirectoryPath.Join("compressed.7z");

            sevenZip.Compress(originalDirPath, zipPath);
            zipPath.IsFile().Should().BeTrue();

            var extractedDirectoryPath = _tempDirectoryPath.Join("extracted");
            var extractedDirPath       = extractedDirectoryPath.Join("original");

            extractedDirectoryPath.CreateDirectory();
            sevenZip.Extract(zipPath, extractedDirectoryPath,
                             excludedFiles: new[] { extractedDirPath.Join("to_be_excluded.txt") });

            extractedDirectoryPath.IsDirectory().Should().BeTrue();
            extractedDirPath.IsDirectory().Should().BeTrue();
            extractedDirPath.Join("to_be_extracted.txt").IsFile().Should().BeTrue();
            extractedDirPath.Join("to_be_excluded.txt").IsFile().Should().BeFalse();
        }
示例#3
0
        public void SaveMessage(DateTime beginTime, string messageBody, string[] contracts)
        {
            messageBody = MessageFormatter.FormatSendTimeStamp(messageBody);

            string compress = SevenZip.Compress(messageBody);

            bool isCompressed = compress.Length < messageBody.Length;

            foreach (var c in contracts)
            {
                Contact contract = SaveContract(c, beginTime);
                SaveContractCoversationDailyDate(contract, beginTime);
                SaveMessage(contract, isCompressed ? compress : messageBody, beginTime, isCompressed);
            }
        }