Example #1
0
        // 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);
            }
        }
        internal override UserToUserResponse ProcessWithEngagement(Engagement engagement, UserToUserRequest req)
        {
            FileSendRequestResponseRq request  = (FileSendRequestResponseRq)req;
            FileSendRequestResponseRs response = new FileSendRequestResponseRs();

            try
            {
                ((Function)engagement.GetFunction("FileSend")).ProcessFileSendRequestResponse(request.accepted, request.fileSendId);
            }
            catch (Exception e)
            {
                Logger.Error("Failed to process incoming FileSend request response : " + e.Message, e);
                response.error        = "INTERNAL_SERVER_ERROR";
                response.errorMessage = "Failed to process incoming FileSend request response";
            }
            return(response);
        }
Example #3
0
 // 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
             });
         }
     }
 }
Example #4
0
        // 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);
            }
        }