public async Task <IActionResult> WhoAmI([FromBody] WhoAmICommand command) { var(accepted, rejected) = await _whoAmIRequestClient.GetResponse <IWhoAmIAccepted, IWhoAmIRejected>(command); if (accepted.IsCompletedSuccessfully) { var response = await accepted; return(Ok(response.Message)); } else { var response = await rejected; return(BadRequest(response.Message)); } }
private static void UploadFileToCurrentChannel(QueryClient queryClient, string sourceFilePath) { // get the channel we're currenlty in uint channelId = new WhoAmICommand().Execute(queryClient).ChannelId; // create a rondom id for the file transfer uint randomClientId = (uint)_randomForFileClientTransferId.Next(1, 10000); // get only the filename FileInfo sourceFileInfo = new FileInfo(sourceFilePath); // initialize the file transfer to get the server file transfer key FtInitUploadCommandResponse ftInitUploadCommandResponse = new FtInitUploadCommand(randomClientId, "/" + sourceFileInfo.Name, channelId, (ulong)sourceFileInfo.Length, true, false).Execute(queryClient); // create the file transfer cleint with the host of the query client and the port we got from the init download response FileTransferClient transferClient = new FileTransferClient(queryClient.Host, ftInitUploadCommandResponse.FileTransferPort ?? 30033); // upload the file synchron transferClient.UploadFile(ftInitUploadCommandResponse.FileTransferKey, (ulong)sourceFileInfo.Length, sourceFileInfo.FullName); }
private static void DownloadFirstFileInCurrentChannel(QueryClient queryClient, string targetDirectory) { // get the channel we're currenlty in uint channelId = new WhoAmICommand().Execute(queryClient).ChannelId; // create a rondom id for the file transfer uint randomClientId = (uint)_randomForFileClientTransferId.Next(1, 10000); // get the first file in the current channel FileTransferFileEntry firstFile = new FtGetFileListCommand(channelId, "/").Execute(queryClient).Values.FirstOrDefault(); // initialize the file transfer to get the server file transfer key FtInitDownloadCommandResponse ftInitDownloadResponse = new FtInitDownloadCommand(randomClientId, "/" + firstFile.Name, firstFile.ChannelId, 0).Execute(queryClient); // calculate the target file path string fileName = firstFile.Name.Substring(firstFile.Name.LastIndexOf("/", StringComparison.Ordinal) + 1); string targetFilePath = Path.Combine(targetDirectory, fileName); // create the file transfer cleint with the host of the query client and the port we got from the init download response FileTransferClient transferClient = new FileTransferClient(queryClient.Host, ftInitDownloadResponse.FileTransferPort ?? 30033); // download the file synchron transferClient.DownloadFile(ftInitDownloadResponse.FileTransferKey, ftInitDownloadResponse.FileSize.Value, targetFilePath); }
public virtual void Visit(WhoAmICommand command) => Default(command);