コード例 #1
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);
        }
コード例 #2
0
ファイル: BaseNodeConfig.cs プロジェクト: wflk/canape
        /// <summary>
        /// Create a factory
        /// </summary>
        /// <returns>The factory</returns>
        public BaseNodeFactory CreateFactory()
        {
            BaseNodeFactory factory = OnCreateFactory();

            factory.Enabled = _enabled;

            if (_filters != null)
            {
                factory.Filters = _filters.ToArray();
            }
            else
            {
                factory.Filters = new DataFrameFilterFactory[0];
            }

            factory.MatchAllFilters = _matchAllFilters;

            foreach (var pair in _properties)
            {
                factory.Properties.Add(pair.Key, pair.Value);
            }

            factory.SelectionPath = _selectionPath ?? "/";
            factory.Hidden        = _hidden;
            factory.LogInput      = _logInput;
            factory.LogOutput     = _logOutput;

            return(factory);
        }
コード例 #3
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
        /// <summary>
        /// Delete any line which touches this node
        /// </summary>
        /// <param name="factory">The node to delete lines from</param>
        public void DeleteLine(BaseNodeFactory factory)
        {
            List <NetGraphFactory.GraphLineEntry> lines = new List <NetGraphFactory.GraphLineEntry>(_graphFactory.Lines);

            lines.RemoveAll(l => (l.SourceNode == factory.Id) || (l.DestNode == factory.Id));

            _graphFactory.Lines = lines.ToArray();
        }
コード例 #4
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
        /// <summary>
        /// Delete the line between two nodes
        /// </summary>
        /// <param name="nodea">The node factory for the first node</param>
        /// <param name="nodeb">The node factory for the second node</param>
        public void DeleteLine(BaseNodeFactory nodea, BaseNodeFactory nodeb)
        {
            List <NetGraphFactory.GraphLineEntry> lines = new List <NetGraphFactory.GraphLineEntry>(_graphFactory.Lines);

            lines.RemoveAll(l => MatchLine(l, nodea, nodeb));

            _graphFactory.Lines = lines.ToArray();
        }
コード例 #5
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
        /// <summary>
        /// Delete a node
        /// </summary>
        /// <param name="factory">The node to delete</param>
        public void DeleteNode(BaseNodeFactory factory)
        {
            List <NetGraphFactory.GraphNodeEntry> nodes = new List <NetGraphFactory.GraphNodeEntry>(_graphFactory.Nodes);

            nodes.RemoveAll(n => n.Factory == factory);
            DeleteLine(factory);

            _graphFactory.Nodes = nodes.ToArray();
        }
コード例 #6
0
        /// <summary>
        /// Implementation of ILinkedeNodeConfig
        /// </summary>
        /// <param name="linkedNode">The linked node</param>
        /// <returns>The created factory</returns>
        BaseNodeFactory ILinkedNodeConfig.CreateFactory(BaseNodeFactory linkedNode)
        {
            NetGraphContainerNodeFactory ret  = (NetGraphContainerNodeFactory)LinkedNode.CreateFactory();
            NetGraphContainerNodeFactory link = (NetGraphContainerNodeFactory)linkedNode;

            ret.LinkedNode  = link;
            link.LinkedNode = ret;

            return(ret);
        }
コード例 #7
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);
            }
        }
コード例 #8
0
ファイル: NetGraphDocument.cs プロジェクト: wflk/canape
        /// <summary>
        ///
        /// </summary>
        protected virtual void RebuildFactory()
        {
            List <NetGraphFactory.GraphNodeEntry> graphNodes = new List <NetGraphFactory.GraphNodeEntry>();
            List <NetGraphFactory.GraphLineEntry> graphLines = new List <NetGraphFactory.GraphLineEntry>();
            HashSet <Guid> createdNodes = new HashSet <Guid>();

            if (_factory == null)
            {
                _factory = new NetGraphFactory();
            }

            if (_nodes != null)
            {
                foreach (BaseNodeConfig node in _nodes)
                {
                    if (!createdNodes.Contains(node.Id))
                    {
                        BaseNodeFactory   factory      = node.CreateFactory();
                        ILinkedNodeConfig linkedConfig = node as ILinkedNodeConfig;

                        if ((linkedConfig != null) && (linkedConfig.LinkedNode != null))
                        {
                            BaseNodeFactory linked = linkedConfig.CreateFactory(factory);

                            createdNodes.Add(linkedConfig.LinkedNode.Id);
                            graphNodes.Add(new NetGraphFactory.GraphNodeEntry(linked));
                        }

                        graphNodes.Add(new NetGraphFactory.GraphNodeEntry(factory));

                        createdNodes.Add(node.Id);
                    }
                }
            }

            if (_lines != null)
            {
                foreach (LineConfig line in _lines)
                {
                    graphLines.Add(new NetGraphFactory.GraphLineEntry(line.SourceNode.Id, line.DestNode.Id, line.BiDirection, line.PathName, line.WeakPath));
                }
            }

            _factory.Nodes = graphNodes.ToArray();
            _factory.Lines = graphLines.ToArray();

            foreach (KeyValuePair <string, string> pair in _properties)
            {
                _factory.Properties.Add(pair.Key, pair.Value);
            }
        }
コード例 #9
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);
        }
コード例 #10
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
        /// <summary>
        /// Add a line between two nodes
        /// </summary>
        /// <param name="nodea">The starting node</param>
        /// <param name="nodeb">The endoing node</param>
        /// <param name="pathName">The line name</param>
        /// <param name="weak">Indicates the line is weak</param>
        public void AddLine(BaseNodeFactory nodea, BaseNodeFactory nodeb, string pathName, bool weak)
        {
            bool matched = false;
            List <NetGraphFactory.GraphLineEntry> lines = new List <NetGraphFactory.GraphLineEntry>(_graphFactory.Lines);

            foreach (var line in lines)
            {
                if (MatchLine(line, nodea, nodeb))
                {
                    // Just set bidirection flag
                    line.BiDirection = true;
                    matched          = true;
                    break;
                }
            }

            if (!matched)
            {
                lines.Add(new NetGraphFactory.GraphLineEntry(nodea.Id, nodeb.Id, false, pathName, false));
            }

            _graphFactory.Lines = lines.ToArray();
        }
コード例 #11
0
ファイル: MasterLayerNodeConfig.cs プロジェクト: wflk/canape
        /// <summary>
        /// Create the linked node factory
        /// </summary>
        /// <param name="linkedNode"></param>
        /// <returns></returns>
        BaseNodeFactory ILinkedNodeConfig.CreateFactory(BaseNodeFactory linkedNode)
        {
            LayerSectionMasterNodeFactory factory = linkedNode as LayerSectionMasterNodeFactory;

            return(factory.SlaveFactory);
        }
コード例 #12
0
        /// <summary>
        /// Get master factory
        /// </summary>
        /// <param name="linkedNode">The linked node factory</param>
        /// <returns>The factory</returns>
        public BaseNodeFactory CreateFactory(BaseNodeFactory linkedNode)
        {
            LayerSectionSlaveNodeFactory factory = linkedNode as LayerSectionSlaveNodeFactory;

            return(factory.MasterFactory);
        }
コード例 #13
0
ファイル: InjectPacketControl.cs プロジェクト: wflk/canape
        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);
                }
            }
        }
コード例 #14
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
 /// <summary>
 /// Method to determine if either of these nodes matches this line segment
 /// </summary>
 /// <param name="line"></param>
 /// <param name="nodea"></param>
 /// <param name="nodeb"></param>
 /// <returns></returns>
 private bool MatchLine(NetGraphFactory.GraphLineEntry line, BaseNodeFactory nodea, BaseNodeFactory nodeb)
 {
     return(((line.DestNode == nodea.Id) && (line.SourceNode == nodeb.Id)) ||
            ((line.DestNode == nodeb.Id) && (line.SourceNode == nodea.Id)));
 }
コード例 #15
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
 /// <summary>
 /// Add a line between two nodes
 /// </summary>
 /// <param name="nodea">The starting node</param>
 /// <param name="nodeb">The endoing node</param>
 /// <param name="pathName">The line name</param>
 public void AddLine(BaseNodeFactory nodea, BaseNodeFactory nodeb, string pathName)
 {
     AddLine(nodea, nodeb, pathName, false);
 }
コード例 #16
0
ファイル: NetGraphBuilder.cs プロジェクト: tyranid/canape
 /// <summary>
 /// Add a line between two nodes
 /// </summary>
 /// <param name="nodea">The starting node</param>
 /// <param name="nodeb">The endoing node</param>
 public void AddLine(BaseNodeFactory nodea, BaseNodeFactory nodeb)
 {
     AddLine(nodea, nodeb, null);
 }
コード例 #17
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);
        }