// Called when this user accepts a file private void ProcessAcceptFile(FileSendInfo fileInfo) { Logger.Info("Accepted request from " + _engagement.SecondParty.Party.Username + " to send the file " + fileInfo.Filename); //Chat.LogSystemMessage("Accepted " + fileInfo.Filename + "."); FileSendRequestResponseRq request = new FileSendRequestResponseRq() { shortCode = _engagement.SecondParty.ActiveShortCode, username = _engagement.SecondParty.Party.Username, interactionId = _engagement.Interactions.CurrentOrNewInteraction.Id, fileSendId = fileInfo.FileSendId, accepted = true }; try { fileInfo.State = FileSendState.Receiving; fileInfo.FilePath = OsUtils.IsWinVistaOrHigher ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", fileInfo.Filename) : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileInfo.Filename); fileInfo.FileReceiver = new FileSendListener(fileInfo); var notification = ShowFileProgressNotification(fileInfo); fileInfo.Notification = notification; notification.Cancelled += delegate { CancelFileReceive(fileInfo); }; fileInfo.FileReceiver.ServerConnectionClosed += (o, eventArgs) => FileReceiverOnConnectionClosed(fileInfo); fileInfo.FileReceiver.DataRead += delegate { notification.Progress = (int)((fileInfo.FileReceiver.DataReadSize * 100) / fileInfo.FileSize); }; fileInfo.FileReceiver.Listen(); // Now we have started our listener, we can send our filesendrequest response to the requester, to tell him to send. _appContext.ConnectionManager.Connection.RequestAsync<FileSendRequestResponseRq, FileSendRequestResponseRs>(request, (rq, rs, ex) => FileSendRequestResponseResponseHandler(fileInfo, rq, rs, ex)); } catch (Exception e) { Logger.Error("Failed to send a file acceptance request for file " + fileInfo.Filename + "[" + fileInfo.FileSendId + "] to " + _engagement.SecondParty.Party.Username); } }
// We call this when we denies secondparty the request to send the file to us private void ProcessDenyFile(FileSendInfo fileInfo) { fileInfo.State = FileSendState.ReceiveCancelled; RemovePendingFileReceive(fileInfo.FileSendId); Logger.Info("Denied request from " + _engagement.SecondParty.Party.Name + " to send the file " + fileInfo.Filename); Chat.LogSystemMessage("You refused " + fileInfo.Filename + " from " + _engagement.SecondParty.Party.Firstname + "."); FileSendRequestResponseRq request = new FileSendRequestResponseRq() { shortCode = _engagement.SecondParty.ActiveShortCode, username = _engagement.SecondParty.Party.Username, fileSendId = fileInfo.FileSendId, accepted = false, interactionId = _engagement.Interactions.CurrentOrNewInteraction.Id }; try { _appContext.ConnectionManager.Connection.RequestAsync<FileSendRequestResponseRq, FileSendRequestResponseRs>(request, delegate(FileSendRequestResponseRq rq, FileSendRequestResponseRs rs, Exception e) { if (e != null) { Logger.Error( "Failed to send the FileSendRequestResponse for file " + request.fileSendId + " : " + e.Message, e); } else { OnNewActivity(new FileSendActivity(_engagement, FileSendActivity.FILE_SEND_RESPONSE) { From = "_SELF", To = _engagement.SecondParty.Party.Username, FileInfo = fileInfo, Answer = false }); } }); } catch (Exception e) { Logger.Error("Failed to send a file acceptance request for file " + fileInfo.Filename + "[" + fileInfo.FileSendId + "] to " + _engagement.SecondParty.Party.Username); } }
// Async callback from our file send request response private void FileSendRequestResponseResponseHandler(FileSendInfo fileInfo, FileSendRequestResponseRq request, FileSendRequestResponseRs response, Exception e) { { if (e != null) { RemovePendingFileReceive(request.fileSendId); Logger.Error("Failed to send the FileSendRequestResponse for file " + request.fileSendId + " : " + e.Message, e); fileInfo.FileReceiver.Close(); _appContext.NotificationManager.DeleteNotification(fileInfo.Notification); Chat.LogSystemMessage("An error occured receiving the file"); } else { OnNewActivity(new FileSendActivity(_engagement, FileSendActivity.FILE_SEND_RESPONSE) { From = "_SELF", To = _engagement.SecondParty.Party.Username, FileInfo = fileInfo, Answer = true }); } } }