Beispiel #1
0
        /// <summary>
        /// Rebuild the factory
        /// </summary>
        protected override void RebuildFactory()
        {
            NetGraphBuilder       builder = new NetGraphBuilder();
            ClientEndpointFactory client  = builder.AddClient("Client", Guid.NewGuid());

            client.Hidden = true;
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());

            server.Hidden = true;

            SwitchNodeFactory outputSwitch = CreateBaseGraph(builder, server, client, false);
            SwitchNodeFactory inputSwitch  = CreateBaseGraph(builder, client, server, true);

            AddStates(builder, outputSwitch, inputSwitch, client, server);

            NetGraphFactory factory = builder.Factory;

            factory.Properties.Add(_metaName, _defaultState);

            if (_factory == null)
            {
                _factory = factory;
            }
            else
            {
                _factory.UpdateGraph(factory);
            }

            Dirty = true;
        }
Beispiel #2
0
        private void AddStateFromEntry(NetGraphBuilder builder, StateGraphEntry entry, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer)
        {
            BaseNodeFactory currentFactory;

            if (entry.Graph != null)
            {
                currentFactory = builder.AddNode(new NetGraphContainerNodeFactory(String.Format("{0} {1}", entry.StateName,
                                                                                                GetDirection(clientToServer)), Guid.NewGuid(), entry.Graph.Factory,
                                                                                  clientToServer ? NetGraphContainerNode.GraphDirection.ClientToServer : NetGraphContainerNode.GraphDirection.ServerToClient));
                currentFactory.Hidden = true;

                builder.AddLine(inputNode, currentFactory, entry.StateName);
            }
            else
            {
                currentFactory = inputNode;
            }

            if (entry.LogPackets)
            {
                LogPacketNodeFactory log = builder.AddLog(String.Format("{0} Log {1}", entry.StateName, GetDirection(clientToServer)),
                                                          Guid.NewGuid(), entry.Color, null, false);
                log.Hidden = true;

                builder.AddLine(currentFactory, log, null);

                currentFactory = log;
            }

            builder.AddLine(currentFactory, outputNode, null);
        }
Beispiel #3
0
        private LogPacketNodeFactory AddLog(NetGraphBuilder builder, StateGraphEntry entry, BaseNodeFactory currentFactory, bool clientToServer)
        {
            LogPacketNodeFactory log = builder.AddLog(String.Format("{0} Log {1}", entry.StateName,
                                                                    GetDirection(clientToServer)), Guid.NewGuid(), entry.Color, null, false);

            log.Hidden = true;

            builder.AddLine(currentFactory, log, null);

            return(log);
        }
Beispiel #4
0
        private void AddStates(NetGraphBuilder builder, SwitchNodeFactory outputSwitch, SwitchNodeFactory inputSwitch,
                               BaseNodeFactory outputNode, BaseNodeFactory inputNode)
        {
            foreach (StateGraphEntry entry in _entries)
            {
                BaseNodeFactory currentInput  = inputSwitch;
                BaseNodeFactory currentOutput = outputSwitch;
                NetGraphFactory graph         = entry.Graph == null?NetGraphBuilder.CreateDefaultProxyGraph(entry.StateName) : entry.Graph.Factory;

                LayerSectionMasterNodeFactory masterNode = new LayerSectionMasterNodeFactory(String.Format("{0} {1}", entry.StateName,
                                                                                                           GetDirection(false)), Guid.NewGuid(), Guid.NewGuid());

                masterNode.DefaultMode = LayerSectionNodeDefaultMode.PassFrame;
                masterNode.Direction   = LayerSectionGraphDirection.ServerToClient;

                builder.AddNode(masterNode);
                builder.AddNode(masterNode.SlaveFactory);

                LayerSectionFilterFactory[] filters = new LayerSectionFilterFactory[1];

                LayerSectionFilterFactory filter = new LayerSectionFilterFactory();

                filter.GraphFactory   = graph;
                filter.LayerFactories = entry.GetLayerFactories();
                filter.SelectionPath  = "";
                filter.FilterFactory  = DataFrameFilterFactory.CreateDummyFactory();
                filter.IsolatedGraph  = false;

                masterNode.LayerFactories = new LayerSectionFilterFactory[1] {
                    filter
                };

                masterNode.SlaveFactory.Hidden = true;

                builder.AddLine(outputSwitch, masterNode, entry.StateName);
                builder.AddLine(inputSwitch, masterNode.SlaveFactory, entry.StateName);

                if (entry.LogPackets)
                {
                    currentOutput = AddLog(builder, entry, masterNode, false);
                    currentInput  = AddLog(builder, entry, masterNode.SlaveFactory, true);
                }
                else
                {
                    currentOutput = masterNode;
                    currentInput  = masterNode.SlaveFactory;
                }

                builder.AddLine(currentOutput, outputNode, null);
                builder.AddLine(currentInput, inputNode, null);
            }
        }
        /// <summary>
        /// Create the filters
        /// </summary>
        /// <returns>An array of filter factories</returns>
        protected override LayerSectionFilterFactory[] CreateFilterFactories()
        {
            LayerSectionFilterFactory filter = new LayerSectionFilterFactory();

            filter.GraphFactory      = _graph != null ? _graph.Factory : NetGraphBuilder.CreateDefaultProxyGraph(Label);
            filter.LayerFactories    = new INetworkLayerFactory[1];
            filter.LayerFactories[0] = new SslNetworkLayerFactory(_config);
            filter.SelectionPath     = SelectionPath;
            filter.FilterFactory     = DataFrameFilterFactory.CreateDummyFactory();
            filter.IsolatedGraph     = _isolatedGraph;

            return(new LayerSectionFilterFactory[1] {
                filter
            });
        }
Beispiel #6
0
        /// <summary>
        /// Guild the default graph factory
        /// </summary>
        /// <returns>The graph factory</returns>
        protected static NetGraphFactory BuildDefaultProxyFactory()
        {
            NetGraphBuilder       builder = new NetGraphBuilder();
            ServerEndpointFactory server  = builder.AddServer("SERVER", Guid.NewGuid());
            ClientEndpointFactory client  = builder.AddClient("CLIENT", Guid.NewGuid());
            LogPacketNodeFactory  logOut  = builder.AddLog("LOGOUT", Guid.NewGuid(), new ColorValue(0xFF, 0xC0, 0xCB, 0xFF), "Out", false);
            LogPacketNodeFactory  logIn   = builder.AddLog("LOGIN", Guid.NewGuid(), new ColorValue(0xB0, 0xE0, 0xE6, 0xFF), "In", false);

            builder.AddLine(server, logOut, null);
            builder.AddLine(logOut, client, null);
            builder.AddLine(client, logIn, null);
            builder.AddLine(logIn, server, null);

            return(builder.Factory);
        }
Beispiel #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="config">Configuration for the server</param>
        public FullHttpProxyServer(HttpProxyServerConfig config, Logger logger)
            : base(logger)
        {
            _config = config;

            NetGraphBuilder builder = new NetGraphBuilder();

            ClientEndpointFactory client = builder.AddClient("Client", Guid.NewGuid());
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());

            DirectNodeFactory nop = builder.AddNode(new DirectNodeFactory("NOP", Guid.NewGuid()));

            builder.AddLines(client, nop, server, client);

            _factory = builder.Factory;
        }
Beispiel #8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="config">Configuration for the server</param>
        public FullHttpProxyServer(HttpProxyServerConfig config, Logger logger)
            : base(logger)
        {
            _config = config;

            NetGraphBuilder builder = new NetGraphBuilder();

            ClientEndpointFactory client = builder.AddClient("Client", Guid.NewGuid());
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());

            DirectNodeFactory nop = builder.AddNode(new DirectNodeFactory("NOP", Guid.NewGuid()));

            builder.AddLines(client, nop, server, client);

            _factory = builder.Factory;
        }
        /// <summary>
        /// Create the filters
        /// </summary>
        /// <returns>An array of filter factories</returns>
        protected override LayerSectionFilterFactory[] CreateFilterFactories()
        {
            LayerSectionFilterFactory filter = new LayerSectionFilterFactory();

            filter.GraphFactory   = _graph != null ? _graph.Factory : NetGraphBuilder.CreateDefaultProxyGraph(Label);
            filter.LayerFactories = new INetworkLayerFactory[_layers.Length];
            for (int i = 0; i < _layers.Length; ++i)
            {
                filter.LayerFactories[i] = _layers[i].Clone();
            }

            filter.SelectionPath = SelectionPath;
            filter.FilterFactory = DataFrameFilterFactory.CreateDummyFactory();
            filter.IsolatedGraph = _isolatedGraph;

            return(new LayerSectionFilterFactory[1] {
                filter
            });
        }
Beispiel #10
0
        private static NetGraph BuildGraph(ScriptContainer container, string classname, string selectionPath, out BasePipelineNode input, out ParseWithPipelineNode output)
        {
            DynamicNodeFactory           factory          = new DynamicNodeFactory("", Guid.NewGuid(), container, classname, null);
            ParseWithPipelineNodeFactory parseWithFactory = new ParseWithPipelineNodeFactory();

            factory.SelectionPath = selectionPath;

            NetGraphBuilder builder = new NetGraphBuilder();

            builder.AddNode(factory);
            builder.AddNode(parseWithFactory);
            builder.AddLine(factory, parseWithFactory, null);

            NetGraph graph = builder.Factory.Create(Logger.GetSystemLogger(), null, new MetaDictionary(), new MetaDictionary(), new PropertyBag("Connection"));

            input  = graph.Nodes[factory.Id];
            output = (ParseWithPipelineNode)graph.Nodes[parseWithFactory.Id];

            return(graph);
        }
Beispiel #11
0
        private SwitchNodeFactory CreateBaseGraph(NetGraphBuilder builder, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer)
        {
            SwitchNodeFactory switchNode = builder.AddNode(new SwitchNodeFactory(String.Format("{0} Switch {1}",
                                                                                               _metaName, GetDirection(clientToServer)), Guid.NewGuid(),
                                                                                 false, CANAPE.Nodes.SwitchNodeSelectionMode.ExactMatch));

            switchNode.Hidden        = true;
            switchNode.SelectionPath = "#" + (String.IsNullOrWhiteSpace(_metaName) ? "Invalid" : _metaName.Trim());

            builder.AddLine(inputNode, switchNode, null);

            LogPacketNodeFactory log = builder.AddLog(String.Format("Invalid Traffic {0}", GetDirection(clientToServer)),
                                                      Guid.NewGuid(), new ColorValue(255, 0, 0), null, false);

            log.Hidden = true;
            builder.AddLine(switchNode, log, null);
            builder.AddLine(log, outputNode, null);

            return(switchNode);
        }
Beispiel #12
0
        /// <summary>
        /// Create the test graph
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <param name="globals">The global meta</param>
        /// <returns>The new test graph container</returns>
        /// <exception cref="ArgumentException">Throw if script invalid</exception>
        public override TestGraphContainer CreateTestGraph(Logger logger, MetaDictionary globals)
        {
            if (String.IsNullOrWhiteSpace(_config.ClassName))
            {
                throw new ArgumentException(CANAPE.Documents.Properties.Resources.ScriptTestDocument_MustProvideClassname);
            }

            NetGraphBuilder       builder = new NetGraphBuilder();
            ServerEndpointFactory server  = builder.AddServer("server", Guid.NewGuid());
            DynamicNodeFactory    node    = builder.AddNode((DynamicNodeFactory)_config.CreateFactory());
            LogPacketNodeFactory  log     = builder.AddLog("Test Network", Guid.NewGuid(), new ColorValue(0xFF, 0xFF, 0xFF, 0xFF), "Entry", false);
            ClientEndpointFactory client  = builder.AddClient("client", Guid.NewGuid());

            builder.AddLine(server, node, null);
            builder.AddLine(node, log, null);
            builder.AddLine(log, client, null);

            NetGraph graph = builder.Factory.Create(logger, null, globals, new MetaDictionary(), new PropertyBag("Connection"));

            return(new TestGraphContainer(graph, graph.Nodes[server.Id], graph.Nodes[client.Id]));
        }
Beispiel #13
0
        private static NetGraph BuildGraph(ScriptContainer container, string classname, string selectionPath, out BasePipelineNode input, out ParseWithPipelineNode output)
        {
            DynamicNodeFactory factory = new DynamicNodeFactory("", Guid.NewGuid(), container, classname, null);
            ParseWithPipelineNodeFactory parseWithFactory = new ParseWithPipelineNodeFactory();

            factory.SelectionPath = selectionPath;

            NetGraphBuilder builder = new NetGraphBuilder();

            builder.AddNode(factory);
            builder.AddNode(parseWithFactory);
            builder.AddLine(factory, parseWithFactory, null);

            NetGraph graph = builder.Factory.Create(Logger.GetSystemLogger(), null, new MetaDictionary(), new MetaDictionary(), new PropertyBag("Connection"));

            input = graph.Nodes[factory.Id];
            output = (ParseWithPipelineNode)graph.Nodes[parseWithFactory.Id];

            return graph;
        }
 /// <summary>
 /// Get a default netgraph
 /// </summary>
 /// <returns>The default graph</returns>
 public static NetGraphFactory GetDefault()
 {
     return(NetGraphBuilder.CreateDefaultProxyGraph("Default"));
 }
Beispiel #15
0
        private SwitchNodeFactory CreateBaseGraph(NetGraphBuilder builder, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer)
        {
            SwitchNodeFactory switchNode = builder.AddNode(new SwitchNodeFactory(String.Format("{0} Switch {1}",
                _metaName, GetDirection(clientToServer)), Guid.NewGuid(),
                false, CANAPE.Nodes.SwitchNodeSelectionMode.ExactMatch));
            switchNode.Hidden = true;
            switchNode.SelectionPath = "#" + (String.IsNullOrWhiteSpace(_metaName) ? "Invalid" : _metaName.Trim());

            builder.AddLine(inputNode, switchNode, null);

            LogPacketNodeFactory log = builder.AddLog(String.Format("Invalid Traffic {0}", GetDirection(clientToServer)),
                    Guid.NewGuid(), new ColorValue(255, 0, 0), null, false);

            log.Hidden = true;
            builder.AddLine(switchNode, log, null);
            builder.AddLine(log, outputNode, null);

            return switchNode;
        }
Beispiel #16
0
        private void AddStates(NetGraphBuilder builder, SwitchNodeFactory outputSwitch, SwitchNodeFactory inputSwitch, 
            BaseNodeFactory outputNode, BaseNodeFactory inputNode)
        {
            foreach (StateGraphEntry entry in _entries)
            {
                BaseNodeFactory currentInput = inputSwitch;
                BaseNodeFactory currentOutput = outputSwitch;
                NetGraphFactory graph = entry.Graph == null ? NetGraphBuilder.CreateDefaultProxyGraph(entry.StateName) : entry.Graph.Factory;

                LayerSectionMasterNodeFactory masterNode = new LayerSectionMasterNodeFactory(String.Format("{0} {1}", entry.StateName,
                    GetDirection(false)), Guid.NewGuid(), Guid.NewGuid());

                masterNode.DefaultMode = LayerSectionNodeDefaultMode.PassFrame;
                masterNode.Direction = LayerSectionGraphDirection.ServerToClient;

                builder.AddNode(masterNode);
                builder.AddNode(masterNode.SlaveFactory);

                LayerSectionFilterFactory[] filters = new LayerSectionFilterFactory[1];

                LayerSectionFilterFactory filter = new LayerSectionFilterFactory();

                filter.GraphFactory = graph;
                filter.LayerFactories = entry.GetLayerFactories();
                filter.SelectionPath = "";
                filter.FilterFactory = DataFrameFilterFactory.CreateDummyFactory();
                filter.IsolatedGraph = false;

                masterNode.LayerFactories = new LayerSectionFilterFactory[1] { filter };

                masterNode.SlaveFactory.Hidden = true;

                builder.AddLine(outputSwitch, masterNode, entry.StateName);
                builder.AddLine(inputSwitch, masterNode.SlaveFactory, entry.StateName);

                if (entry.LogPackets)
                {
                    currentOutput = AddLog(builder, entry, masterNode, false);
                    currentInput = AddLog(builder, entry, masterNode.SlaveFactory, true);
                }
                else
                {
                    currentOutput = masterNode;
                    currentInput = masterNode.SlaveFactory;
                }

                builder.AddLine(currentOutput, outputNode, null);
                builder.AddLine(currentInput, inputNode, null);
            }
        }
Beispiel #17
0
        private void AddStateFromEntry(NetGraphBuilder builder, StateGraphEntry entry, BaseNodeFactory inputNode, BaseNodeFactory outputNode, bool clientToServer)
        {
            BaseNodeFactory currentFactory;

            if (entry.Graph != null)
            {
                currentFactory = builder.AddNode(new NetGraphContainerNodeFactory(String.Format("{0} {1}", entry.StateName,
                    GetDirection(clientToServer)), Guid.NewGuid(), entry.Graph.Factory,
                    clientToServer ? NetGraphContainerNode.GraphDirection.ClientToServer : NetGraphContainerNode.GraphDirection.ServerToClient));
                currentFactory.Hidden = true;

                builder.AddLine(inputNode, currentFactory, entry.StateName);
            }
            else
            {
                currentFactory = inputNode;
            }

            if (entry.LogPackets)
            {
                LogPacketNodeFactory log = builder.AddLog(String.Format("{0} Log {1}", entry.StateName, GetDirection(clientToServer)),
                    Guid.NewGuid(), entry.Color, null, false);
                log.Hidden = true;

                builder.AddLine(currentFactory, log, null);

                currentFactory = log;
            }

            builder.AddLine(currentFactory, outputNode, null);
        }
Beispiel #18
0
        private LogPacketNodeFactory AddLog(NetGraphBuilder builder, StateGraphEntry entry, BaseNodeFactory currentFactory, bool clientToServer)
        {
            LogPacketNodeFactory log = builder.AddLog(String.Format("{0} Log {1}", entry.StateName,
                GetDirection(clientToServer)), Guid.NewGuid(), entry.Color, null, false);
            log.Hidden = true;

            builder.AddLine(currentFactory, log, null);

            return log;
        }
Beispiel #19
0
        /// <summary>
        /// Rebuild the factory
        /// </summary>
        protected override void RebuildFactory()
        {
            NetGraphBuilder builder = new NetGraphBuilder();
            ClientEndpointFactory client = builder.AddClient("Client", Guid.NewGuid());
            client.Hidden = true;
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());
            server.Hidden = true;

            SwitchNodeFactory outputSwitch = CreateBaseGraph(builder, server, client, false);
            SwitchNodeFactory inputSwitch = CreateBaseGraph(builder, client, server, true);

            AddStates(builder, outputSwitch, inputSwitch, client, server);

            NetGraphFactory factory = builder.Factory;
            factory.Properties.Add(_metaName, _defaultState);

            if (_factory == null)
            {
                _factory = factory;
            }
            else
            {
                _factory.UpdateGraph(factory);
            }

            Dirty = true;
        }
Beispiel #20
0
        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);
                }
            }
        }
Beispiel #21
0
        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);
                }
            }
        }
Beispiel #22
0
        /// <summary>
        /// Create the test graph
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <param name="globals">The global meta</param>
        /// <returns>The new test graph container</returns>
        /// <exception cref="ArgumentException">Throw if script invalid</exception>
        public override TestGraphContainer CreateTestGraph(Logger logger, MetaDictionary globals)
        {
            if (String.IsNullOrWhiteSpace(_config.ClassName))
            {
                throw new ArgumentException(CANAPE.Documents.Properties.Resources.ScriptTestDocument_MustProvideClassname);
            }

            NetGraphBuilder builder = new NetGraphBuilder();
            ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid());
            DynamicNodeFactory node = builder.AddNode((DynamicNodeFactory)_config.CreateFactory());
            LogPacketNodeFactory log = builder.AddLog("Test Network", Guid.NewGuid(), new ColorValue(0xFF, 0xFF, 0xFF, 0xFF), "Entry", false);
            ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid());

            builder.AddLine(server, node, null);
            builder.AddLine(node, log, null);
            builder.AddLine(log, client, null);

            NetGraph graph = builder.Factory.Create(logger, null, globals, new MetaDictionary(), new PropertyBag("Connection"));

            return new TestGraphContainer(graph, graph.Nodes[server.Id], graph.Nodes[client.Id]);
        }
Beispiel #23
0
 /// <summary>
 /// Guild the default graph factory
 /// </summary>
 /// <returns>The graph factory</returns>
 protected static NetGraphFactory BuildDefaultProxyFactory()
 {
     return(NetGraphBuilder.CreateDefaultProxyGraph());
 }