private async Task ProcessFileReqAck(ReqAck mFileReqAck, Metadata mMetadata) { //see if received accepted the file transmition request bool acceptedReq = mFileReqAck.AcceptedFile; FileSentReq fileSendReq = GetSendFileReqFromMeta(mMetadata); if (!acceptedReq) { //didn't accept request sendFileRequests.Remove(fileSendReq); return; } //start sending the file parts foreach (FileTransReq fileTrans in fileSendReq.FileTransReqs) { //for each file while (fileSendReq.FileHasMoreParts(fileTrans)) { //send all its parts FilePartObj filePart = await fileSendReq.GetNextFilePart(fileTrans); await ObjectManager.SendAsyncTCP(fileSendReq.targetIpAddress, filePart); //send update event FileProgUpdate?.Invoke(this, new FileTransferEventArgs(fileTrans, TransDirrection.sending)); } } }
//called when a file part is received private async Task ProcessFilePart(FilePartObj filePart, Metadata metadata) { //check if file part is valid if (filePart == null) { throw new Exception("filePart has not been set."); } //find file recieve request FileReceiveReq fileReceived = GetReceivedFileReqFromMeta(metadata); FileTransReq fileTrans = fileReceived.GetFileTransReqFromFileMeta(filePart.FileMetadata); //dump file data to disk await fileReceived.WriteFilePartToFile(filePart); //log incoming file FileProgUpdate?.Invoke(this, new FileTransferEventArgs(fileTrans, TransDirrection.receiving)); }