public async Task <string> GetFile(byte[] fileHash) { var requestMessage = new GetFileMessage(fileHash); var subDir = new DirectoryInfo(Path.Combine(TempStorageDirectory, Hasher.GetDirectoryNameFromHash(fileHash))); if (!subDir.Exists) { subDir.Create(); } var fileName = Hasher.GetFileNameFromHash(fileHash); var filePath = Path.Combine(subDir.FullName, fileName); FilesInProgress.Add(fileHash, File.OpenWrite(filePath)); await Communicator.SendMessage(requestMessage); // wait for transfer var gotVerificationMessage = false; string resultsPath = null; while (!gotVerificationMessage) { if (VerificationMessages.ContainsKey(fileHash)) { var verifyMessage = VerificationMessages[fileHash] as FileStoredVerificationMessage; resultsPath = (verifyMessage?.Success ?? false) ? verifyMessage.FilePath : null; VerificationMessages.Remove(fileHash); gotVerificationMessage = true; } await Task.Delay(1); } return(resultsPath); }
private void lwFiles_ItemActivate(object sender, EventArgs e) { if (lwFiles.SelectedItems.Count == 1) { var fileMetaData = new FileMetaData(); fileMetaData.FileId = Convert.ToInt32(lwFiles.SelectedItems[0].Text); GetFileMessage gfm = new GetFileMessage(); gfm.Metadata = fileMetaData; //Library.File activeFile = fileClient.GetFile(gfm).file; activeFile = fileClient.GetFile(gfm).file; lblFIleInfo.Text = activeFile.Title; txtFileDesc.Text = activeFile.Description; btnDownload.Visible = true; ChatMessage[] messages = chatService.GetLast20MessagesFromFile(activeFile); listBox_Filechat.Items.Clear(); LastDate = DateTime.MinValue; UpdateChat(messages); } }