public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
            {
                algorithm.Push(read.Buffer.Data, read.Buffer.Offset, Math.Min(read.Buffer.Count, read.Count));

                Metainfo metainfo = context.Metainfo;

                byte[] expected = metainfo.Pieces[read.Piece].ToBytes();

                byte[] hash   = algorithm.Complete();
                bool   result = Bytes.Equals(hash, expected);

                bitfield[read.Piece] = result;
                algorithm.Dispose();

                int  next   = Next(scope, read.Piece + 1);
                bool exists = context.View.Exists(next, 0);

                if (exists)
                {
                    context.Queue.Add(new Start(bitfield, scope, next, block));
                }
                else
                {
                    block.Release();
                    onCompleted.Invoke(this);

                    context.Bitfile.Write(bitfield);
                    context.Hooks.CallDataVerified(metainfo.Hash, bitfield);
                }
            }
            public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
            {
                onCompleted.Invoke(this);

                Action <byte[]> release = context.Dependencies.Memory.Release;
                DataBlock       data    = new FileBufferDataBlock(read, release);

                context.Hooks.CallBlockRead(context.Parameters.Hash, index, data);
            }
            public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
            {
                algorithm.Push(read.Buffer.Data, read.Buffer.Offset, Math.Min(read.Buffer.Count, read.Count));

                Metainfo metainfo = context.Metainfo;

                byte[] expected = metainfo.Pieces[piece.Index].ToBytes();

                byte[] hash   = algorithm.Complete();
                bool   result = Bytes.Equals(hash, expected);

                AcceptIfRequired(context, result);
                RejectIfRequired(context, result);

                algorithm.Dispose();
                block.Release();

                onCompleted.Invoke(this);
            }
        public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
        {
            int      length   = context.Metainfo.Pieces.Length;
            Bitfield bitfield = context.Bitfile.Read();

            bitfield = bitfield ?? new Bitfield(length);
            Bitfield reduced = ReduceScope(bitfield);
            int      next    = Next(reduced, 0);

            if (next < length)
            {
                int bufferSize = context.Configuration.BufferSize;
                RepositoryMemoryBlock block = context.Dependencies.Memory.Allocate(bufferSize);

                context.Queue.Add(new Start(bitfield, reduced, next, block));
            }
            else
            {
                onCompleted.Invoke(this);
                context.Hooks.CallDataVerified(context.Metainfo.Hash, bitfield);
            }
        }
 public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
 {
     data.Release();
     onCompleted.Invoke(this);
     context.Hooks.CallBlockWritten(context.Metainfo.Hash, index);
 }