private IConverser handleNewConversation(Message msg) { Log.Debug("Handling a new conversation"); switch (msg.MessageId) { case MessageType.REGISTER_CONTENT_REQUEST: RegisterContentRequest req = (RegisterContentRequest)msg; var content = new Content() { FileName = req.Name, ContentHash = req.Hash, ByteSize = req.FileSize, Host = req.Host, Port = req.Port, Description = req.Description }; Log.Info("Added " + req.Name); return(new RegisterContentReceiver(msg.ConversationId, content)); case MessageType.CONTENT_LIST_REQUEST: return(new ContentListReceiver(msg.ConversationId)); case MessageType.REGISTER_REQUEST: break; default: break; } return(null); }
private void addSeedButton_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(seedTextBox.Text)) { if (File.Exists(seedTextBox.Text)) { var provider = new RSACryptoServiceProvider(); provider.ImportCspBlob(persistenceManager.ReadContent().KeyInfo); using (var sha2 = new SHA256Managed()) { FileInfo file = new FileInfo(seedTextBox.Text); Content newContent = new Content() { FileName = file.Name, LocalPath = file.DirectoryName, Description = descriptionTextBox.Text, ByteSize = (int)file.Length, ContentHash = sha2.ComputeHash(File.ReadAllBytes(file.FullName)), Host = Properties.Settings.Default.HostAddress, Port = Properties.Settings.Default.HostPort, PublicKeyInfo = provider.ExportCspBlob(false) }; persistenceManager.WriteContent(newContent, PersistenceManager.StorageType.Local); seederDataGridView.DataSource = persistenceManager.ReadContent().LocalContent; RegisterContentRequest request = new RegisterContentRequest(Guid.NewGuid(), Guid.NewGuid(), 1, newContent); RegisterContentSender contentSender = new RegisterContentSender(request.ConversationId, request); router.AddConversation(contentSender, RegistryEndpoint); } } else { MessageBox.Show("That file does not exist", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("You must specify a filename", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }