private void connectToStandAloneInstances() { var handleManager = new VMConnectHandle(); while (true) { var handles = handleManager.GetAll().Where(x => !_nodes.Exists(y => y.IP.Equals(x.IP) && y.Port.Equals(x.Port))).ToList(); foreach (var handle in handles) { var node = new DiagnosticNode( handle.IP, handle.Port, handle.ProcessID, handle.Token, (m) => node_MessageReceived(handle.Token, new MessageReceivedEventArgs(m))); if (node.IsConnected) { addNode(node); } else { try { File.Delete(handle.File); } catch { } } } Thread.Sleep(5000); } }
private void connectToServerInstance() { DiagnosticNode server = null; var connected = false; while (!connected) { try { server = new DiagnosticNode("127.0.0.1", 9070, 0, "Server"); if (server.IsConnected) { addListItem(new ListItemInfo<string>("Connected")); server.MessageReceived += new EventHandler<VM.Messages.Communication.MessageReceivedEventArgs>(node_MessageReceived); connected = true; } else { Thread.Sleep(5000); } } catch { } } }
private void connectToServerInstance() { DiagnosticNode server = null; var connected = false; while (!connected) { try { server = new DiagnosticNode("127.0.0.1", 9070, 0, "Server"); if (server.IsConnected) { addListItem(new ListItemInfo <string>("Connected")); server.MessageReceived += new EventHandler <VM.Messages.Communication.MessageReceivedEventArgs>(node_MessageReceived); connected = true; } else { Thread.Sleep(5000); } } catch { } } }
void node_MessageReceived(object sender, MessageReceivedEventArgs e) { _syncContext.Post((m) => { if (!sentFromActiveNode(sender.ToString())) { return; } addListItem(new ListItemInfo <object>(e.Message)); if (e.Message.GetType().Equals(typeof(VMSpawnedMessage))) { var message = (VMSpawnedMessage)e.Message; var client = new DiagnosticNode("127.0.0.1", message.Port, 0, "Client"); addListItem(new ListItemInfo <string>("Connected")); addNode(client); } if (e.Message.GetType().Equals(typeof(VMTerminating))) { var message = (VMTerminating)e.Message; var client = _nodes.Where(n => n.IP.Equals("127.0.0.1") && n.Port.Equals(message.Port)).FirstOrDefault(); if (client != null) { addListItem(new ListItemInfo <string>("Disconnected")); removeNode(client); } } }, null); }
private void addNode(DiagnosticNode client) { lock (_nodes) { _nodes.Add(client); _syncContext.Post((state) => listBoxNodes.Items.Add(client), null); } }
void node_MessageReceived(object sender, MessageReceivedEventArgs e) { _syncContext.Post((m) => { if (!sentFromActiveNode(sender.ToString())) return; addListItem(new ListItemInfo<object>(e.Message)); if (e.Message.GetType().Equals(typeof(VMSpawnedMessage))) { var message = (VMSpawnedMessage)e.Message; var client = new DiagnosticNode("127.0.0.1", message.Port, 0, "Client"); addListItem(new ListItemInfo<string>("Connected")); addNode(client); } if (e.Message.GetType().Equals(typeof(VMTerminating))) { var message = (VMTerminating)e.Message; var client = _nodes.Where(n => n.IP.Equals("127.0.0.1") && n.Port.Equals(message.Port)).FirstOrDefault(); if (client != null) { addListItem(new ListItemInfo<string>("Disconnected")); removeNode(client); } } }, null); }