示例#1
0
 public void OnRequestFileSend(string file, int uploadToken, int size)
 {
     if (size > MaxFileUploadSize)
     {
         _connection.Send(FileServerHelper.FileSendResponse(0, -2));
     }
     else if (/*Service.ValidateUploadToken(uploadToken)*/ true)
     {
         _fileAssembler = FileAssembler.CreateAssembler(BaseDir + "/" + _currentDirectory + "/" + file);
         LogService.Info(this, "Begin receiving file: {0}", _currentDirectory + "/" + file);
         if (_fileAssembler != null)
         {
             _connection.Send(FileServerHelper.FileSendResponse(0, size));
             _toUploadSize = size;
         }
         else
         {
             _connection.Send(FileServerHelper.FileSendResponse(0, -2));
         }
     }
     else
     {
         _connection.Send(FileServerHelper.FileSendResponse(0, -1));
     }
 }
示例#2
0
        public void OnRequestFileBlock(string file, int blockId, int size, ref com.ideadynamo.foundation.buffer.ByteArray stream, int special)
        {
            if (_fileAssembler != null)
            {
                int thisBlockSize = stream.Buffer.Length - ByteArray.HEADERLENGTH;
                _fileAssembler.Append(blockId, stream.Buffer, ByteArray.HEADERLENGTH, thisBlockSize);
                _connection.Send(FileServerHelper.FileBlockResponse(0, size));
                _toUploadSize -= thisBlockSize;

                if (special != 0 || _toUploadSize <= 0)
                {
                    LogService.Info(this, "Receive file {0} success, total size {1}", file, _fileAssembler.Size);
                    _fileAssembler.Dispose();
                    _fileAssembler = null;
                }
            }
        }