Example #1
0
 public void Run(IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
 {
     using (var iterate = _mainLoop.AddRegularTask(() => Iterate(progress)))
     {
         interrupt.StopWaitHandle.WaitOne();
     }
 }
Example #2
0
        public void Run(IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
        {
            var iterate = mainLoop.AddRegularTask(Iterate);

            interrupt.StopWaitHandle.WaitOne();
            iterate.Cancel();
        }
 public void Run(IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
 {
     if (application.DataHandler.IncompletePieces().Any())
     {
         HashPiecesData(interrupt, progress);
     }
 }
        public void Run(IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
        {
            if (_application.DataHandler.IncompletePieces().Any())
            {
                HashPiecesData(interrupt, progress);
            }

            _logger.LogInformation($"{_application.DataHandler.CompletedPieces.Count} pieces already downloaded");
        }
Example #5
0
        public void Run(Container container, IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
        {
            foreach (var stage in stageFactory)
            {
                var instance = stage.Construct(container);
                instance.Run(interrupt, progress);

                if (interrupt.IsStopRequested)
                {
                    return;
                }
            }
        }
        private void HashPiecesData(IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
        {
            progress.Report(new StatusUpdate(DownloadState.Checking, 0.0));
            using (var sha1 = SHA1.Create())
            {
                foreach (Piece piece in _application.Metainfo.Pieces)
                {
                    // Verify piece hash
                    long   pieceOffset = _application.Metainfo.PieceOffset(piece);
                    byte[] pieceData;
                    if (!_application.DataHandler.TryReadBlockData(pieceOffset, piece.Size, out pieceData))
                    {
                        progress.Report(new StatusUpdate(DownloadState.Checking,
                                                         (piece.Index + 1d) / _application.Metainfo.Pieces.Count));
                        continue;
                    }

                    var hash = new Sha1Hash(sha1.ComputeHash(pieceData));
                    if (hash == piece.Hash)
                    {
                        _application.DataHandler.MarkPieceAsCompleted(piece);
                    }

                    progress.Report(new StatusUpdate(DownloadState.Checking,
                                                     (piece.Index + 1d) / _application.Metainfo.Pieces.Count));

                    if (interrupt.IsPauseRequested)
                    {
                        interrupt.InterruptHandle.WaitOne();
                    }
                    if (interrupt.IsStopRequested)
                    {
                        return;
                    }
                }
            }
        }
Example #7
0
        public void Run(IStageInterrupt interrupt, IProgress <StatusUpdate> progress)
        {
            foreach (var stage in _stages)
            {
                _logger.LogInformation($"Starting pipeline stage {stage.GetType().Name}");
                try
                {
                    stage.Run(interrupt, progress);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Unhandled exception in pipeline stage {stage.GetType().Name}");
                    progress.Report(new StatusUpdate(DownloadState.Error, 0.0));
                    return;
                }
                _logger.LogInformation($"Finished pipeline stage {stage.GetType().Name}");

                if (interrupt.IsStopRequested)
                {
                    _logger.LogInformation("Stopping pipeline due to stop request");
                    return;
                }
            }
        }