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)); } } }
private async Task ProcessIncomingFilesRequest(FileReqMeta fileRequest, Metadata mMetadata) { //determine whether or not to accept the incoming file request bool validFileRequest = IsValidFileRequest(fileRequest, mMetadata); FileReceiveReq fileReceiveReq = null; if (validFileRequest) { //add to a file recieved request fileReceiveReq = await CreateFileReceiveReq(fileRequest, mMetadata); receivedFileRequests.Add(fileReceiveReq); } //send message back to sender ReqAck fileRequestResp = new ReqAck(validFileRequest); await ObjectManager.SendAsyncTCP(mMetadata.SourceIp, fileRequestResp); }
private async void ObjManager_objReceived(object sender, ObjReceivedEventArgs e) { BObject bObj = e.Obj; Metadata metadata = bObj.GetMetadata(); ObjReceived?.Invoke(this, e); string objType = bObj.GetType(); switch (objType) { case "FilePartObj": FilePartObj filePart = e.Obj.GetObject <FilePartObj>(); await ProcessFilePart(filePart, metadata); break; /* * case "FileAck": * FileAck ackMsg = e.Obj.GetObject<FileAck>(); * await ProcessAckMessage(ackMsg, metadata); * break; */ case "FileReqMeta": FileReqMeta fileRequestMetadata = e.Obj.GetObject <FileReqMeta>(); await ProcessIncomingFilesRequest(fileRequestMetadata, metadata); break; case "ReqAck": ReqAck fileReqAck = e.Obj.GetObject <ReqAck>(); await ProcessFileReqAck(fileReqAck, metadata); break; default: break; } }