Beispiel #1
0
        public void CompressionAsyncTest()
        {
            AutoResetEvent          waitHandle = new AutoResetEvent(false);
            CustomCancellationToken token      = CustomCancellationTokenSource.GetToken();

            compressor = new GZipCompressor(waitHandle);
            string decompressedFileName = @"Decompressed_" + startFileName;

            GZipCompressionDelegate del = compressor.Compress;

            del.BeginInvoke(startFileName, endFileName, token, OnCompressionComplete, del);
            waitHandle.WaitOne();
            string startFileHash        = "";
            string decompressedFileHash = "";

            MD5 md5hash = MD5.Create();

            del = compressor.Decompress;
            del.BeginInvoke(endFileName, decompressedFileName, token, OnCompressionComplete, del);
            waitHandle.WaitOne();

            using (Stream startFileStream = File.OpenRead(startFileName))
                using (Stream decompressedFIleStream = File.OpenRead(decompressedFileName))
                {
                    startFileHash        = Encoding.Default.GetString(md5hash.ComputeHash(startFileStream));
                    decompressedFileHash = Encoding.Default.GetString(md5hash.ComputeHash(decompressedFIleStream));
                }
            Assert.AreEqual(startFileHash, decompressedFileHash);
        }
Beispiel #2
0
        public void CompressionWithCancellationTest()
        {
            AutoResetEvent          waitHandle = new AutoResetEvent(false);
            CustomCancellationToken token      = CustomCancellationTokenSource.GetToken();

            compressor = new GZipCompressor(waitHandle);
            //startFileName = @"video.avi";
            GZipCompressionDelegate del = compressor.Decompress;

            compressor.OnCompressionComplete += compressor_OnCompressionCompleteWithCancellation;
            del.BeginInvoke(startFileName, endFileName, token, null, del);
            Thread.Sleep(6000);
            token.IsCancelled = true;
            waitHandle.WaitOne();
        }