Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="addFileToDfsResponse"></param>
        /// <param name="channelHandlerContext"></param>
        /// <param name="senderPeerIdentifier"></param>
        /// <param name="correlationId"></param>
        protected override void HandleResponse(AddFileToDfsResponse addFileToDfsResponse,
                                               IChannelHandlerContext channelHandlerContext,
                                               PeerId senderPeerIdentifier,
                                               ICorrelationId correlationId)
        {
            Guard.Argument(addFileToDfsResponse, nameof(addFileToDfsResponse)).NotNull();
            Guard.Argument(channelHandlerContext, nameof(channelHandlerContext)).NotNull();
            Guard.Argument(senderPeerIdentifier, nameof(senderPeerIdentifier)).NotNull();

            // @TODO return int not byte
            // var responseCode = Enumeration.Parse<FileTransferResponseCodes>(deserialised.ResponseCode[0].ToString());

            var responseCode = (FileTransferResponseCodeTypes)addFileToDfsResponse.ResponseCode[0];

            if (responseCode == FileTransferResponseCodeTypes.Successful)
            {
                _rpcFileTransferFactory.FileTransferAsync(correlationId, CancellationToken.None)
                .ConfigureAwait(false);
            }
            else
            {
                var fileTransferInformation = _rpcFileTransferFactory.GetFileTransferInformation(correlationId);
                if (fileTransferInformation != null)
                {
                    _rpcFileTransferFactory.Remove(fileTransferInformation, true);
                }
            }
        }
        public override void OnNext(IObserverDto <ProtocolMessage> messageDto)
        {
            base.OnNext(messageDto);

            var correlationId = messageDto.Payload.CorrelationId.ToCorrelationId();

            if (_fileTransferFactory.GetFileTransferInformation(correlationId) != null)
            {
                _fileTransferFactory.FileTransferAsync(correlationId, CancellationToken.None).ConfigureAwait(false);
            }
        }
        public async Task Can_Upload_File(uint numberOfChunks)
        {
            var uploadFileInformation = Substitute.For <IUploadFileInformation>();
            var correlationId         = CorrelationId.GenerateCorrelationId();

            uploadFileInformation.MaxChunk.Returns(numberOfChunks);
            uploadFileInformation.CorrelationId.Returns(correlationId);

            _uploadFileTransferFactory.RegisterTransfer(uploadFileInformation);

            await _uploadFileTransferFactory.FileTransferAsync(correlationId, CancellationToken.None).ConfigureAwait(false);

            for (uint i = 0; i < numberOfChunks; i++)
            {
                uploadFileInformation.Received(1).GetUploadMessageDto(i);
                uploadFileInformation.Received(1).UpdateChunkIndicator(i, true);
            }

            await uploadFileInformation.RecipientChannel.ReceivedWithAnyArgs((int)numberOfChunks).WriteAndFlushAsync(default);