Beispiel #1
0
        protected void Consume()
        {
            long processedBytes = 0;

            ConsumeAction();
            while (outputStreamLength - 1 > processedBytes)
            {
                try
                {
                    Block nextBlock;
                    if (!buffer.TryGetValue(currentBlockIndex, out nextBlock))
                    {
                        nextBlock = blocksHandler.GetBlock();
                        if (currentBlockIndex == nextBlock.Id)
                        {
                            OutputConsole.ShowMessage("Обработано " + processedBytes / 1024 / 1024 + "Мб");
                            blockWriter.WriteNextBlock(nextBlock);
                            processedBytes += Config.BLOCK_SIZE;
                            currentBlockIndex++;
                        }
                        else
                        {
                            buffer.Add(nextBlock.Id, nextBlock);
                        }
                    }
                    else
                    {
                        buffer.Remove(currentBlockIndex);
                        OutputConsole.ShowMessage("Обработано " + processedBytes / 1024 / 1024 + "Мб");
                        blockWriter.WriteNextBlock(nextBlock);
                        processedBytes += Config.BLOCK_SIZE;
                        currentBlockIndex++;
                    }
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    isAborted = true;
                    OutputConsole.DisplayError(ex);
                    return;
                }
                catch (ThreadAbortException)
                {
                    return;
                }
            }
        }