public override void Produce()
 {
     inputStreamLength  = inputStream.Length;
     fileSize           = BitConverter.ToInt64(((CompressedBlockReader)blockReader).ReadFileSize(), 0);
     outputStreamLength = fileSize;
     // streamLength = fileSize;
     while (inputStreamLength - 1 > inputStream.Position)
     {
         try
         {
             Block nextBlock;
             nextBlock = blockReader.GetNextBlock(((CompressedBlockReader)blockReader).ReadBlockSize());
             if (fileSize < bytesReaded + Config.BLOCK_SIZE)
             {
                 nextBlock.Size = (int)(fileSize - bytesReaded);
             }
             blocksHandler.AddBlock(nextBlock);
             bytesReaded += Config.BLOCK_SIZE;
         }
         catch (ArgumentOutOfRangeException ex)
         {
             isAborted = true;
             OutputConsole.DisplayError(ex);
             return;
         }
         catch (ThreadAbortException)
         {
             return;
         }
     }
 }
Exemple #2
0
 public override void Produce()
 {
     inputStreamLength  = inputStream.Length;
     outputStreamLength = inputStreamLength;
     while (inputStreamLength - 1 > inputStream.Position)
     {
         try
         {
             Block nextBlock;
             if (inputStreamLength > bytesReaded + Config.BLOCK_SIZE)
             {
                 nextBlock = blockReader.GetNextBlock(Config.BLOCK_SIZE);
             }
             else
             {
                 nextBlock = blockReader.GetNextBlock((int)(inputStreamLength - bytesReaded));
             }
             blocksHandler.AddBlock(nextBlock);
         }
         catch (ArgumentOutOfRangeException ex)
         {
             isAborted = true;
             OutputConsole.DisplayError(ex);
             return;
         }
         catch (ThreadAbortException)
         {
             return;
         }
     }
 }
Exemple #3
0
 private void Process()
 {
     if (isAborted)
     {
         return;
     }
     try
     {
         producerThread          = new Thread(Produce);
         producerThread.Priority = ThreadPriority.AboveNormal;
         consumerThread          = new Thread(Consume);
         consumerThread.Priority = ThreadPriority.AboveNormal;
         producerThread.Start();
         blocksHandler.Start();
         consumerThread.Start();
         producerThread.Join();
         consumerThread.Join();
         if (!isAborted)
         {
             blocksHandler.Stop();
         }
     }
     catch (Exception ex)
     {
         OutputConsole.DisplayError(ex);
     }
 }
Exemple #4
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;
                }
            }
        }
 protected override void Initialization()
 {
     try
     {
         inputStream  = BlockReader.GetInputStream(option.InputFileName);
         outputStream = BlockWriter.GetOutputStream(option.OutputFileName);
     }
     catch (FileNotFoundException)
     {
         Console.WriteLine("Файл не найден");
         isAborted = true;
         return;
     }
     catch (FileLoadException ex)
     {
         OutputConsole.DisplayError(ex);
         isAborted = true;
         return;
     }
     blockReader   = new CompressedBlockReader(inputStream);
     blockWriter   = new DecompressedBlockWriter(outputStream);
     blocksHandler = new BlockHandler(Environment.ProcessorCount, ex => Callback(ex), CompressionMode.Decompress);
 }
Exemple #6
0
 protected void Callback(Exception ex)
 {
     OutputConsole.DisplayError(ex);
     Abort();
 }