/// <summary>
        /// 计算每个文件块的MD5值
        /// </summary>
        /// <param name="info"></param>
        /// <param name="fs"></param>
        /// <returns></returns>
        private List <BlockTransferRequest> ClacFileEachBlockMd5(FileBlockInfo info, FileStream fs)
        {
            var position      = fs.Position;
            var list          = new List <BlockTransferRequest>();
            int sendBlockSize = info.BlockSize;
            int blockIndex    = 0;

            while (fs.Position < fs.Length)
            {
                var r = new BlockTransferRequest()
                {
                    FileName   = info.FileName,
                    BlockIndex = blockIndex,
                    BlockSize  = sendBlockSize,
                    SeekOffset = (int)fs.Position
                };
                byte[] buffer = new byte[sendBlockSize];
                fs.Read(buffer, 0, buffer.Length);//read之后,Position会变,所以要先生成对象

                r.BlockMd5 = Md5.GetMd5WithBytes(buffer);
                list.Add(r);

                blockIndex++;//增加索引序号,别漏了
                if (sendBlockSize > fs.Length - fs.Position)
                {
                    sendBlockSize = (int)(fs.Length - fs.Position);
                }
            }
            fs.Position = position;
            return(list);
        }
示例#2
0
        public BlockTransferResponsed CheckBlockMessage(BlockTransferRequest blockMessage)
        {
            bool isError = true;

            using (var fs = new FileStream(FileNameTools.GetDownloadingFullPath(blockMessage.FileName), FileMode.Open, FileAccess.ReadWrite))
            {
                try
                {
                    byte[] buffer = new byte[blockMessage.BlockSize];
                    fs.Position = blockMessage.SeekOffset;
                    fs.Read(buffer, 0, buffer.Length);
                    string md5 = Md5.GetMd5WithBytes(buffer);
                    if (md5 == blockMessage.BlockMd5)
                    {
                        isError = false;
                    }
                }
                catch
                {
                    // ignored
                }
            }
            return(new BlockTransferResponsed()
            {
                IsError = isError
            });
        }
示例#3
0
 public BlockTransferResponsed UpdateFileBlockMessage(BlockTransferRequest blockMessage)
 {
     return(_proxy.UpdateFileBlockData(_targetPort, blockMessage));
 }
 public BlockTransferResponsed UpdateFileBlockMessage(BlockTransferRequest blockMessage)
 {
     return(Channel.UpdateFileBlockCheckMessage(blockMessage));
 }
 public Task <BlockTransferResponsed> UpdateFileBlockCheckMessageAsync(BlockTransferRequest blockMessage)
 {
     return(Channel.UpdateFileBlockCheckMessageAsync(blockMessage));
 }
 public BlockTransferResponsed UpdateFileBlockMessage(BlockTransferRequest blockMessage)
 {
     return(writer.CheckBlockMessage(blockMessage));
 }
 public BlockTransferResponsed TransferFileBlockMessage(BlockTransferRequest blockMessage)
 {
     return(_fileWriter.CheckBlockMessage(blockMessage));
 }
示例#8
0
 public Task <BlockTransferResponsed> UpdateFileBlockDataAsync(int port, BlockTransferRequest request)
 {
     return(Channel.UpdateFileBlockDataAsync(port, request));
 }
示例#9
0
 public BlockTransferResponsed UpdateFileBlockData(int port, BlockTransferRequest request)
 {
     return(Channel.UpdateFileBlockData(port, request));
 }
示例#10
0
 public BlockTransferResponsed UpdateFileBlockMessage(BlockTransferRequest blockMessage)
 {
     return(_pushService.TransferFileBlockMessage(blockMessage));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BlockTransferResponsed UpdateFileBlockData(int taskID, BlockTransferRequest request)
        {
            var sendAdapter = _remoteUpdateSenderAdapterDic[taskID];

            return(sendAdapter.UpdateFileBlockMessage(request));
        }