Exemplo n.º 1
0
        public void Reader(string source, ref TaskPool readerTaskPool)
        {
            try
            {
                using (BinaryReader br = new BinaryReader(new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None)))
                {
                    _originLength = br.ReadInt64();
                    _blockCount   = br.ReadInt64();

                    for (int count = 0; count < _blockCount; count++)
                    {
                        int    blockNumber = br.ReadInt32();
                        int    blockLength = br.ReadInt32();
                        byte[] blockValue  = br.ReadBytes(blockLength);

                        if (blockValue == null)
                        {
                            throw new ArgumentNullException("blockValue", "ERROR: некорректное значение блока");
                        }

                        if (!readerTaskPool.TrySet(blockNumber, blockValue))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _isDelete = true;
                Terminate();
                Console.WriteLine(e.Message);
                return;
            }
        }
Exemplo n.º 2
0
        public void Reader(string source, ref TaskPool readerTaskPool)
        {
            try
            {
                FileInfo fi = new FileInfo(source);
                _sourceLength = fi.Length;
                _blockCount   = fi.Length / GZip.BUFFER_SIZE;
                if (fi.Length % GZip.BUFFER_SIZE > 0)
                {
                    _blockCount++;
                }
            }
            catch (Exception e)
            {
                _isDelete = true;
                Terminate();
                Console.WriteLine(e.Message);
                return;;
            }

            try
            {
                using (BinaryReader br = new BinaryReader(new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None)))
                {
                    for (int blockNumber = 0; blockNumber < _blockCount; blockNumber++)
                    {
                        byte[] blockValue = br.ReadBytes(GZip.BUFFER_SIZE);

                        if (blockValue == null)
                        {
                            throw new ArgumentNullException("blockValue", "ERROR: некорректное значение блока");
                        }

                        if (!readerTaskPool.TrySet(blockNumber, blockValue))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _isDelete = true;
                Terminate();
                Console.WriteLine(e.Message);
                return;
            }
        }
Exemplo n.º 3
0
        public void Handler(ref TaskPool readerTaskPool, ref TaskPool writerTaskPool)
        {
            int blockNumber = -1;

            byte[] blockValue = null;

            while (true)
            {
                try
                {
                    if (!readerTaskPool.TryGet(out blockNumber, out blockValue))
                    {
                        return;
                    }

                    if (blockValue == null)
                    {
                        break;
                    }

                    byte[] compressedBlock = GZip.Compress(blockValue);

                    if (!writerTaskPool.TrySet(blockNumber, compressedBlock))
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    _isDelete = true;
                    Terminate();
                    Console.WriteLine(e.Message);
                    return;
                }
            }
        }