Beispiel #1
0
        public void Process(object doneEvent)
        {
            if (!(doneEvent is ManualResetEvent))
            {
                throw new ArgumentException();
            }

            try
            {
                while (!_fileProcessData.Cancelled)
                {
                    ByteBlock block = _queueReader.Dequeue();

                    if (block == null)
                    {
                        return;
                    }

                    using (var memoryStream = new MemoryStream())
                    {
                        using (var gzs = new GZipStream(memoryStream, CompressionMode.Compress))
                        {
                            gzs.Write(block.Buffer, 0, block.Buffer.Length);
                        }

                        byte[] compressedData = memoryStream.ToArray();
                        var    bb             = new ByteBlock
                        {
                            Id     = block.Id,
                            Buffer = compressedData
                        };

                        _queueWriter.EnqueueForWriting(bb);
                    }
                    ((ManualResetEvent)doneEvent).Set();
                }
            }
            catch (Exception ex)
            {
                _fileProcessData.Cancelled = true;
                throw new Exception(ex.Message);
            }
        }
        public void Process(object doneEvent)
        {
            if (!(doneEvent is ManualResetEvent))
            {
                throw new ArgumentException();
            }

            try
            {
                while (!_fileProcessData.Cancelled)
                {
                    ByteBlock byteBlock = _queueReader.Dequeue();
                    if (byteBlock == null)
                    {
                        return;
                    }

                    using (MemoryStream ms = new MemoryStream(byteBlock.CompressedBuffer))
                    {
                        using (GZipStream gzs = new GZipStream(ms, CompressionMode.Decompress))
                        {
                            gzs.Read(byteBlock.Buffer, 0, byteBlock.Buffer.Length);
                            byte[]    decompressedData = byteBlock.Buffer.ToArray();
                            ByteBlock block            = new ByteBlock
                            {
                                Id     = byteBlock.Id,
                                Buffer = decompressedData
                            };
                            _queueWriter.EnqueueForWriting(block);
                        }
                        ((ManualResetEvent)doneEvent).Set();
                    }
                }
            }
            catch (Exception ex)
            {
                _fileProcessData.Cancelled = true;
                throw new Exception(ex.Message);
            }
        }