/// <summary> /// Requests a file access token from the host. /// The file access token allows this client to access any files within the /// current dragdrop or clipboard operation. The token returned from this method /// should be used when requesting to read from the remote filestream along with the GUID /// of the file that you want to read. /// </summary> /// <exception cref="RemoteFileStreamReadFailedException"></exception> /// <exception cref="InvalidNetworkResponseException"></exception>" /// <exception cref="RequestTimedOutException"></exception> /// <param name="fileGroupId">The operation ID of the files to access</param> /// <returns></returns> public async Task <Guid> RequestFileTokenAsync(Guid fileGroupId) { ISLogger.Write("Sending token request"); NetworkMessage response = await SendRequestAsync(new RequestGroupTokenMessage(fileGroupId)); ISLogger.Write("Server responded to token request!"); switch (response.Type) { case MessageType.RequestFileGroupTokenReponse: RequestGroupTokenResponseMessage resp = response as RequestGroupTokenResponseMessage; return(resp.Token); case MessageType.RemoteFileError: FileErrorMessage err = response as FileErrorMessage; ISLogger.Write("File token request returned error: " + err.ErrorMessage); return(Guid.Empty); break; default: ISLogger.Write("Debug: Server sent unexpected reply when requesting file access token"); return(Guid.Empty); } }
/// <summary> /// Sends a request to read a remote filestream from the host and /// waits for a response message. /// </summary> ///<exception cref="RemoteFileStreamReadFailedException"></exception> /// <exception cref="InvalidNetworkResponseException"></exception>" /// <exception cref="RequestTimedOutException"></exception> /// <param name="token">The access token used to access the filestream</param> /// <param name="file">The Guid associated with the file</param> /// <param name="readLen">Ammount of bytes to read</param> /// <returns></returns> public async Task <byte[]> RequestReadStreamAsync(Guid token, Guid file, int readLen) { NetworkMessage response = await SendRequestAsync(new FileStreamReadRequestMessage(token, file, readLen)); switch (response.Type) { case MessageType.FileStreamReadResponse: FileStreamReadResponseMessage resp = response as FileStreamReadResponseMessage; return(resp.ReadData); case MessageType.RemoteFileError: FileErrorMessage errMsg = response as FileErrorMessage; throw new RemoteFileStreamReadFailedException(errMsg.ErrorMessage); default: throw new InvalidNetworkResponseException("Server responded with unexpected message type " + response.Type); } }
/// <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; } } }
private void SetAlertMessage(FileErrorMessage message) { AlertBoxMessage = message.Message; AlertBoxVisible = true; }
private void OnError(object sender, ErrorEventArgs e) { var message = new FileErrorMessage(_fileName, e.GetException().Message); _tailActor.Tell(message, ActorRefs.NoSender); }