/// <summary> /// Constructor for when created a linked version of the node /// </summary> /// <param name="linkedNode">The linked master node</param> /// <param name="logger">The associated logger</param> public NetGraphContainerNode(NetGraphContainerNode linkedNode, Logger logger) { _graph = linkedNode._graph; // Reverse the nodes _inputNode = linkedNode._outputNode; _outputNode = linkedNode._inputNode; _graph.BindEndpoint(_outputNode.Uuid, new EventDataAdapter(this)); LinkedNode = true; // We don't bind logging and editing from the same graph, we assume the master did that }
/// <summary> /// Constructor for when created a linked version of the node /// </summary> /// <param name="linkedNode">The linked master node</param> /// <param name="logger">The associated logger</param> public NetGraphContainerNode(NetGraphContainerNode linkedNode, Logger logger) { _graph = linkedNode._graph; // Reverse the nodes _inputNode = linkedNode._outputNode; _outputNode = linkedNode._inputNode; _graph.BindEndpoint(_outputNode.Uuid, new EventDataAdapter(this)); LinkedNode = true; // We don't bind logging and editing from the same graph, we assume the master did that }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of the factory</param> /// <param name="factory">Factory</param> /// <param name="direction">Direction of graph</param> /// <param name="containerGraph">The parent graph</param> /// <param name="logger">The logger to use</param> /// <param name="stateDictionary">Forwarded state dictionary</param> /// <param name="linked">If true then we are creating a linked master node</param> public NetGraphContainerNode(string name, NetGraphFactory factory, GraphDirection direction, NetGraph containerGraph, Logger logger, Dictionary <string, object> stateDictionary, bool linked) { var clients = factory.GetNodes <ClientEndpointFactory>(); var servers = factory.GetNodes <ServerEndpointFactory>(); if ((clients.Length > 0) && (servers.Length > 0)) { Guid outputNode = direction == GraphDirection.ClientToServer ? servers[0].Id : clients[0].Id; Guid inputNode = direction == GraphDirection.ClientToServer ? clients[0].Id : servers[0].Id; if (linked) { _graph = factory.Create(name, logger, containerGraph, containerGraph.GlobalMeta, containerGraph.Meta, containerGraph.ConnectionProperties); } else { _graph = factory.CreateFiltered(name, logger, containerGraph, containerGraph.GlobalMeta, containerGraph.Meta, inputNode, containerGraph.ConnectionProperties, stateDictionary); } _graph.BindEndpoint(outputNode, new EventDataAdapter(this)); _inputNode = (PipelineEndpoint)_graph.Nodes[inputNode]; _inputNode.Hidden = true; _outputNode = (PipelineEndpoint)_graph.Nodes[outputNode]; _outputNode.Hidden = true; } else { throw new ArgumentException(CANAPE.Properties.Resources.NetGraphContainerNode_InvalidGraph); } }
private void btnInject_Click(object sender, EventArgs e) { if (_injectGraph != null) { CancelInject(); } else { try { NetGraph selectedGraph = comboBoxConnection.SelectedItem as NetGraph; while ((selectedGraph == null) || (selectedGraph.CheckShutdown())) { PopulateConnections(); if (comboBoxConnection.Items.Count == 0) { selectedGraph = null; break; } comboBoxConnection.SelectedItem = comboBoxConnection.Items[0]; selectedGraph = comboBoxConnection.SelectedItem as NetGraph; } if (selectedGraph != null) { if (logPacketControl.Packets.Length > 0) { if (comboBoxNodes.SelectedItem != null) { int repeatCount = (int)numericRepeatCount.Value; BasePipelineNode node = (BasePipelineNode)comboBoxNodes.SelectedItem; LogPacket[] basePackets = checkBoxInjectSelected.Checked ? logPacketControl.SelectedPackets : logPacketControl.Packets; List<LogPacket> packets = new List<LogPacket>(); for (int i = 0; i < repeatCount; ++i) { packets.AddRange((LogPacket[])GeneralUtils.CloneObject(basePackets)); } NetGraphBuilder builder = new NetGraphBuilder(); ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid()); ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid()); DynamicNodeFactory dyn = null; BaseNodeFactory startNode = client; if (_config.EnablePacketDelay && (_config.PacketDelayMs > 0)) { DelayNodeFactory delay = builder.AddNode(new DelayNodeFactory("delay", Guid.NewGuid()) { PacketDelayMs = (int)_config.PacketDelayMs }); builder.AddLine(startNode, delay, null); startNode = delay; } if (_config.EnableScripting && _config.ScriptDocumentId != Guid.Empty && !String.IsNullOrWhiteSpace(_config.ScriptDocumentClass)) { ScriptDocument doc = CANAPEProject.CurrentProject.GetDocumentByUuid(_config.ScriptDocumentId) as ScriptDocument; if (doc != null) { dyn = new DynamicNodeFactory("dyn", Guid.NewGuid(), doc.Container, _config.ScriptDocumentClass, null); builder.AddNode(dyn); builder.AddLine(startNode, dyn, null); startNode = dyn; } } builder.AddLine(startNode, server, null); _injectGraph = builder.Factory.Create(selectedGraph.Logger, selectedGraph, selectedGraph.GlobalMeta, new MetaDictionary(), new PropertyBag("root")); QueuedDataAdapter inputAdapter = new QueuedDataAdapter(); foreach (LogPacket p in packets) { inputAdapter.Enqueue(p.Frame); } inputAdapter.StopEnqueue(); _injectGraph.BindEndpoint(client.Id, inputAdapter); _injectGraph.BindEndpoint(server.Id, new DelegateDataAdapter( () => this.CancelInject(), frame => node.Input(frame), null )); // Start injection (_injectGraph.Nodes[client.Id] as IPipelineEndpoint).Start(); // Check if the dynamic node was an endpoint (so a generator), start as well if ((dyn != null) && (_injectGraph.Nodes[dyn.Id] is PipelineEndpoint)) { (_injectGraph.Nodes[dyn.Id] as IPipelineEndpoint).Start(); } // Start cancel timer timerCancel.Start(); btnInject.Text = CANAPE.Properties.Resources.InjectPacketControl_CancelButtonText; } else { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_SelectNode, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_SelectGraph, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (NotSupportedException) { MessageBox.Show(this, CANAPE.Properties.Resources.InjectPacketForm_NotSupported, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NodeFactoryException ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// TODO: Should merge with implementation for the general connection so that it is 100% compatible /// <summary> /// /// </summary> /// <param name="graph"></param> /// <param name="token"></param> public void ReconnectClient(NetGraph graph, ProxyToken token) { IDataAdapter client = null; bool connected = false; PropertyBag networkService = graph.ConnectionProperties.GetRelativeBag("NetworkService"); PropertyBag clientProperties = graph.ConnectionProperties.GetRelativeBag("Client"); PropertyBag tokenProperties = graph.ConnectionProperties.GetRelativeBag("Token"); try { while(graph.Parent != null) { graph = graph.Parent; } if (token != null) { // If passed in a token we need to apply filters to it token = FilterToken(token); } else { // Use original post-filtered token = (ProxyToken)networkService.GetRelativeValue("Token"); } if (token.Status == NetStatusCodes.Success) { clientProperties.Clear(); if (token.Client == null) { client = _proxyClient.Connect(token, _logger, graph.Meta, _globalMeta, clientProperties, _credentialManager); } else { client = token.Client.Connect(token, _logger, graph.Meta, _globalMeta, clientProperties, _credentialManager); } tokenProperties.Clear(); token.PopulateBag(tokenProperties); // Negotiate SSL or other bespoke encryption mechanisms if (token.Layers != null) { // Bind but disabling server layer NetworkLayerBinding binding = DefaultBinding & ~NetworkLayerBinding.Server; foreach (INetworkLayer layer in token.Layers) { IDataAdapter server = null; layer.Negotiate(ref server, ref client, token, _logger, graph.Meta, _globalMeta, graph.ConnectionProperties, binding); } } graph.BindEndpoint((Guid)networkService.GetRelativeValue("ClientId"), client); IDataAdapter serverAdapter = networkService.GetRelativeValue("ServerAdapter"); if (token.NetworkDescription != null) { graph.NetworkDescription = token.NetworkDescription; } else { graph.NetworkDescription = String.Format("{0} <=> {1}", serverAdapter.Description, client.Description); } IDataAdapter oldClient = networkService.GetRelativeValue("ClientAdapter"); networkService.AddValue("ClientAdapter", client); networkService.AddValue("Token", token); oldClient.Close(); connected = true; } else { _logger.LogVerbose(CANAPE.Net.Properties.Resources.ProxyNetworkService_ConnectionFiltered); } } catch (Exception ex) { _logger.LogException(ex); } finally { if (!connected) { try { if (client != null) { client.Close(); } } catch (Exception ex) { Logger.GetSystemLogger().LogException(ex); } } } }