Example #1
0
        /// <summary>
        /// Se gatilla cuando se recibe un mensaje
        /// </summary>
        /// <param name="message">El mensaje recibido</param>
        public void proccessMessage(Message message)
        {
            switch (message.Type)
            {
            case SubProtocol.FileTransfer.Types.FILEREQUESTMESSAGE:
            {
                FileRequestMessage fileRequestMessage = (FileRequestMessage)message;
                FileInformation    fileInformation    = fileData.FileList.getFileInformation(fileRequestMessage.FileId);
                if (fileInformation != null)
                {
                    FileMessageSender fileMessageSender = new FileMessageSender(fileRequestMessage.SenderNetUser, fileRequestMessage.FileHandlerId, sendMessageDelegate, fileInformation, fileData);
                    lock (fileMessageHandlerLock)
                    {
                        if (!activeUploads.Contains(fileMessageSender.Id))
                        {
                            if (fileMessageUploadQueue.put(fileMessageSender))
                            {
                                controlFileHandler.uploadFileQueued(fileRequestMessage.SenderNetUser, fileMessageSender.Id.ToString(), fileInformation.Name);
                            }
                        }
                    }
                }
                else
                {
                    FileErrorMessage fileErrorMessage = new FileErrorMessage(fileRequestMessage.SenderNetUser, fileRequestMessage.FileHandlerId);
                    sendMessageEvent(fileErrorMessage);
                }
                break;
            }

            case SubProtocol.FileTransfer.Types.FILEERRORMESSAGES:
            {
                FileErrorMessage fileErrorMessage = (FileErrorMessage)message;
                lock (fileMessageHandlerLock)
                {
                    if (activeUploads.Contains(fileErrorMessage.FileHandlerId))
                    {
                        FileMessageHandler fileMessageHandler = (FileMessageHandler)activeUploads[fileErrorMessage.FileHandlerId];
                        controlFileHandler.uploadFileFailed(fileMessageHandler.Id.ToString());
                        fileMessageHandler.close();
                        activeUploads.Remove(fileMessageHandler.Id);
                    }
                    else if (activeDownloads.Contains(fileErrorMessage.FileHandlerId))
                    {
                        FileMessageHandler fileMessageHandler = (FileMessageHandler)activeDownloads[fileErrorMessage.FileHandlerId];
                        controlFileHandler.downloadFileFailed(fileMessageHandler.Id.ToString());
                        fileMessageHandler.close();
                        activeDownloads.Remove(fileMessageHandler.Id);
                    }
                }
                break;
            }

            case SubProtocol.FileTransfer.Types.FILEPARTMESSAGE:
            {
                FilePartMessage filePartMessage = (FilePartMessage)message;
                lock (fileMessageHandlerLock)
                {
                    if (activeDownloads.Contains(filePartMessage.FileHandlerId))
                    {
                        FileMessageHandler fileMessageHandler = (FileMessageHandler)activeDownloads[filePartMessage.FileHandlerId];
                        fileMessageHandler.attendMessage(filePartMessage);
                        fileMessageHandler.waitUp(fileData.FileRiseUp);
                    }
                    else
                    {
                        FileErrorMessage fileErrorMessage = new FileErrorMessage(filePartMessage.SenderNetUser, filePartMessage.FileHandlerId);
                        sendMessageEvent(fileErrorMessage);
                    }
                }
                break;
            }

            case SubProtocol.FileTransfer.Types.FILEWAITMESSAGE:
            {
                FileWaitMessage fileWaitMessage = (FileWaitMessage)message;
                lock (fileMessageHandlerLock)
                {
                    if (activeDownloads.Contains(fileWaitMessage.FileHandlerId))
                    {
                        FileMessageHandler fileMessageHandler = (FileMessageHandler)activeDownloads[fileWaitMessage.FileHandlerId];
                        fileMessageHandler.waitUp(fileData.FileRiseUp);
                    }
                    else if (activeUploads.Contains(fileWaitMessage.FileHandlerId))
                    {
                        FileMessageHandler fileMessageHandler = (FileMessageHandler)activeUploads[fileWaitMessage.FileHandlerId];
                        fileMessageHandler.waitUp(fileData.FileRiseUp);
                    }
                    else
                    {
                        if (!fileMessageDownloadQueue.contains(fileWaitMessage.FileHandlerId) && !fileMessageUploadQueue.contains(fileWaitMessage.FileHandlerId))
                        {
                            FileErrorMessage fileErrorMessage = new FileErrorMessage(fileWaitMessage.SenderNetUser, fileWaitMessage.FileHandlerId);
                            sendMessageEvent(fileErrorMessage);
                        }
                    }
                }
                break;
            }

            case SubProtocol.FileTransfer.Types.FILECOMPLETEMESSAGE:
            {
                FileCompleteMessage fileCompleteMessage = (FileCompleteMessage)message;
                lock (fileMessageHandlerLock)
                {
                    if (activeUploads.Contains(fileCompleteMessage.FileHandlerId))
                    {
                        FileMessageHandler fileMessageHandler = (FileMessageHandler)activeUploads[fileCompleteMessage.FileHandlerId];
                        fileMessageHandler.State = FileMessageHandlerState.COMPLETED;
                    }
                }
                break;
            }

            case SubProtocol.FileTransfer.Types.FILELISTREQUESTMESSAGE:
            {
                FileListRequestMessage fileListRequestMessage = (FileListRequestMessage)message;
                FileListMessage        fileListMessage        = new FileListMessage(fileListRequestMessage.SenderNetUser, fileData.FileList);
                sendMessageEvent(fileListMessage);
                break;
            }

            case SubProtocol.FileTransfer.Types.FILELISTMESSAGE:
            {
                FileListMessage fileListMessage = (FileListMessage)message;
                controlFileListHandler.addFileList(fileListMessage.SenderNetUser, fileListMessage.FileList);
                break;
            }
            }
        }
 /// <summary>
 /// Se gatilla cuando se recibe un mensaje
 /// </summary>
 /// <param name="message">El mensaje recibido</param>
 public void proccessMessage(Message message)
 {
     switch (message.Type)
     {
         case SubProtocol.FileTransfer.Types.FILEREQUESTMESSAGE:
             {
                 FileRequestMessage fileRequestMessage = (FileRequestMessage)message;
                 FileInformation fileInformation = fileData.FileList.getFileInformation(fileRequestMessage.FileId);
                 if (fileInformation != null)
                 {
                     FileMessageSender fileMessageSender = new FileMessageSender(fileRequestMessage.SenderNetUser, fileRequestMessage.FileHandlerId, sendMessageDelegate, fileInformation, fileData);
                     lock (fileMessageHandlerLock)
                     {
                         if (!activeUploads.Contains(fileMessageSender.Id))
                         {
                             if (fileMessageUploadQueue.put(fileMessageSender))
                             {
                                 controlFileHandler.uploadFileQueued(fileRequestMessage.SenderNetUser, fileMessageSender.Id.ToString(), fileInformation.Name);
                             }
                         }
                     }
                 }
                 else
                 {
                     FileErrorMessage fileErrorMessage = new FileErrorMessage(fileRequestMessage.SenderNetUser, fileRequestMessage.FileHandlerId);
                     sendMessageEvent(fileErrorMessage);
                 }
                 break;
             }
         case SubProtocol.FileTransfer.Types.FILEERRORMESSAGES:
             {
                 FileErrorMessage fileErrorMessage = (FileErrorMessage)message;
                 lock (fileMessageHandlerLock)
                 {
                     if (activeUploads.Contains(fileErrorMessage.FileHandlerId))
                     {
                         FileMessageHandler fileMessageHandler = (FileMessageHandler)activeUploads[fileErrorMessage.FileHandlerId];
                         controlFileHandler.uploadFileFailed(fileMessageHandler.Id.ToString());
                         fileMessageHandler.close();
                         activeUploads.Remove(fileMessageHandler.Id);
                     }
                     else if (activeDownloads.Contains(fileErrorMessage.FileHandlerId))
                     {
                         FileMessageHandler fileMessageHandler = (FileMessageHandler)activeDownloads[fileErrorMessage.FileHandlerId];
                         controlFileHandler.downloadFileFailed(fileMessageHandler.Id.ToString());
                         fileMessageHandler.close();
                         activeDownloads.Remove(fileMessageHandler.Id);
                     }
                 }
                 break;
             }
         case SubProtocol.FileTransfer.Types.FILEPARTMESSAGE:
             {
                 FilePartMessage filePartMessage = (FilePartMessage)message;
                 lock (fileMessageHandlerLock)
                 {
                     if (activeDownloads.Contains(filePartMessage.FileHandlerId))
                     {
                         FileMessageHandler fileMessageHandler = (FileMessageHandler)activeDownloads[filePartMessage.FileHandlerId];
                         fileMessageHandler.attendMessage(filePartMessage);
                         fileMessageHandler.waitUp(fileData.FileRiseUp);
                     }
                     else
                     {
                         FileErrorMessage fileErrorMessage = new FileErrorMessage(filePartMessage.SenderNetUser, filePartMessage.FileHandlerId);
                         sendMessageEvent(fileErrorMessage);
                     }
                 }
                 break;
             }
         case SubProtocol.FileTransfer.Types.FILEWAITMESSAGE:
             {
                 FileWaitMessage fileWaitMessage = (FileWaitMessage)message;
                 lock (fileMessageHandlerLock)
                 {
                     if (activeDownloads.Contains(fileWaitMessage.FileHandlerId))
                     {
                         FileMessageHandler fileMessageHandler = (FileMessageHandler)activeDownloads[fileWaitMessage.FileHandlerId];
                         fileMessageHandler.waitUp(fileData.FileRiseUp);
                     }
                     else if (activeUploads.Contains(fileWaitMessage.FileHandlerId))
                     {
                         FileMessageHandler fileMessageHandler = (FileMessageHandler)activeUploads[fileWaitMessage.FileHandlerId];
                         fileMessageHandler.waitUp(fileData.FileRiseUp);
                     }
                     else
                     {
                         if (!fileMessageDownloadQueue.contains(fileWaitMessage.FileHandlerId) && !fileMessageUploadQueue.contains(fileWaitMessage.FileHandlerId))
                         {
                             FileErrorMessage fileErrorMessage = new FileErrorMessage(fileWaitMessage.SenderNetUser, fileWaitMessage.FileHandlerId);
                             sendMessageEvent(fileErrorMessage);
                         }
                     }
                 }
                 break;
             }
         case SubProtocol.FileTransfer.Types.FILECOMPLETEMESSAGE:
             {
                 FileCompleteMessage fileCompleteMessage = (FileCompleteMessage)message;
                 lock (fileMessageHandlerLock)
                 {
                     if (activeUploads.Contains(fileCompleteMessage.FileHandlerId))
                     {
                         FileMessageHandler fileMessageHandler = (FileMessageHandler)activeUploads[fileCompleteMessage.FileHandlerId];
                         fileMessageHandler.State = FileMessageHandlerState.COMPLETED;
                     }
                 }
                 break;
             }
         case SubProtocol.FileTransfer.Types.FILELISTREQUESTMESSAGE:
             {
                 FileListRequestMessage fileListRequestMessage = (FileListRequestMessage)message;
                 FileListMessage fileListMessage = new FileListMessage(fileListRequestMessage.SenderNetUser, fileData.FileList);
                 sendMessageEvent(fileListMessage);
                 break;
             }
         case SubProtocol.FileTransfer.Types.FILELISTMESSAGE:
             {
                 FileListMessage fileListMessage = (FileListMessage)message;
                 controlFileListHandler.addFileList(fileListMessage.SenderNetUser, fileListMessage.FileList);
                 break;
             }
     }
 }