Ejemplo n.º 1
0
 protected virtual void Write()
 {
     ExecutedChunksQueue.WaitForInput();
     using (var outputStream = new FileStream(Options.Output, FileMode.Create))
     {
         using (var bufferedSTream = new BufferedStream(outputStream, Options.ReadBufferSize))
         {
             while ((_executing || ExecutedChunksQueue.Count > 0) && !ErrorOccured)
             {
                 IChunk chunk = null;
                 if (ExecutedChunksQueue.TryDequeue(out chunk))
                 {
                     bufferedSTream.Write(chunk.Body, 0, chunk.Body.Length);
                     if (Options.VerboseOutput)
                     {
                         Console.WriteLine("AbstractProcessor: chunk " + chunk.Index + " was written");
                     }
                 }
                 else
                 {
                     Thread.Sleep(10);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 protected virtual void Execute()
 {
     ReadChunksQueue.WaitForInput();
     _executing = true;
     using (var threadPool = new GeneralThreadPool(CancellationToken, Options.MaxBuffers))
     {
         while ((_reading || ReadChunksQueue.Count > 0) && !ErrorOccured)
         {
             IChunk chunk = null;
             if (ReadChunksQueue.TryDequeue(out chunk))
             {
                 threadPool.Enqueue(() =>
                 {
                     ExecuteChunk(chunk);
                     ExecutedChunksQueue.Enqueue(chunk);
                 });
             }
             else
             {
                 Thread.Sleep(10);
             }
         }
         threadPool.StopAdding();
         threadPool.WaitForCompletion();
     }
     _executing = false;
 }