Example #1
0
        public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
        {
            long position = 0;
            int  pieces   = context.Metainfo.Properties.Pieces;

            int pieceSize = context.Metainfo.Properties.PieceSize;
            int blockSize = context.Metainfo.Properties.BlockSize;

            RepositoryAllocation    allocation = new RepositoryAllocation(pieces);
            RepositoryViewAllocator allocator  = new RepositoryViewAllocator(context.Dependencies.Files);

            foreach (MetainfoEntry entry in context.Metainfo.Entries)
            {
                string   path = entry.GetPath(context.Parameters.Destination);
                FileInfo info = new FileInfo(path);

                if (info.Exists == false)
                {
                    EnsureDirectoryExists(path);
                    allocation.Add(entry, new RepositoryAllocationRange((int)(position / pieceSize), (int)((position + entry.Size) / pieceSize)));
                }

                position += entry.Size;
            }

            MetainfoEntry[]     entries = context.Metainfo.Entries;
            RepositoryViewCache cache   = allocator.Allocate(context.Parameters.Destination, entries, pieceSize, blockSize);

            context.View = new RepositoryView(cache);
            context.Hooks.CallDataAllocated(context.Metainfo.Hash, context.Parameters.Destination);
        }
        public RepositoryViewReadRoutine(RepositoryViewCache cache, int piece, FileBuffer buffer, RepositoryViewReadCallback callback)
        {
            this.piece    = piece;
            this.buffer   = buffer;
            this.callback = callback;

            this.entries = cache.Find(piece);
            this.offset  = piece * (long)cache.PieceSize;
        }
Example #3
0
        public RepositoryViewWriteRoutine(RepositoryViewCache cache, int piece, int block, FileBuffer buffer, RepositoryViewWriteCallback callback)
        {
            this.piece    = piece;
            this.block    = block;
            this.buffer   = buffer;
            this.callback = callback;

            this.entries = cache.Find(piece, block, 1);
            this.offset  = piece * (long)cache.PieceSize + block * cache.BlockSize;
        }
Example #4
0
 public RepositoryView(RepositoryViewCache cache)
 {
     this.cache = cache;
 }