コード例 #1
0
 public Packet(ModelNode start, ModelNode end, ModelEdge edge, long time) : this()
 {
     Time  = time;
     Start = start;
     End   = end;
     Edge  = edge;
 }
コード例 #2
0
 /// <summary>
 /// Convenience method to create a single packet with the appropriate timestamp.
 /// </summary>
 /// <param name="startNode">The start node of the packet.</param>
 /// <param name="endNode">The end node of the packet.</param>
 /// <param name="edge">The edge on which the packet travels.</param>
 /// <returns>The newly-created packet.</returns>
 private Packet CreatePacket(ModelNode startNode, ModelNode endNode, ModelEdge edge)
 {
     return(new Packet(startNode, endNode, edge, time));
 }
コード例 #3
0
        /// <summary>
        /// Initializes the graph from the supplied GraphML file and creates the model from it.
        /// </summary>
        /// <remarks>
        /// While this reads the graph from a GraphML file and constructs the model from an already-finished graph, a
        /// real-world application would likely create the model from whichever data source is available and then create
        /// the graph from it.
        /// </remarks>
        private void InitGraphAndModel()
        {
            var graph = new DefaultGraph
            {
                NodeDefaults = { Style            = new NodeControlNodeStyle("NodeStyle")
                                 {
                                     OutlineShape = new Ellipse()
                                 } },
                EdgeDefaults = { Style = new EdgeSegmentControlEdgeStyle("EdgeStyle") }
            };
            var ioh = new GraphMLIOHandler();

            // Parse node kinds and other info
            IMapper <INode, NodeKind> nodeKinds = new DictionaryMapper <INode, NodeKind>();
            IMapper <INode, NodeInfo> nodeInfos = new DictionaryMapper <INode, NodeInfo>();

            ioh.AddInputMapper("NetworkMonitoring.NodeKind", nodeKinds);
            ioh.AddInputMapper("NetworkMonitoring.NodeInfo", nodeInfos);

            ioh.Read(graph, @"Resources\network.graphml");

            foreach (var node in graph.Nodes)
            {
                // Create and attach the model node to the graph node.
                var modelNode = new ModelNode
                {
                    Name    = nodeInfos[node].Name,
                    Ip      = nodeInfos[node].Ip,
                    Enabled = true,
                    Kind    = nodeKinds[node]
                };
                node.Tag = modelNode;

                // Add the label
                var label = graph.AddLabel(node, "", FreeLabelModel.Instance.CreateDefaultParameter(), nodeLabelStyle, tag: modelNode);
                // Attach event handler for changing label visibility, so that the graph redraws accordingly.
                // Since visibility can change via clicking on the node *and* from within the label, we have to use an event
                // handler on the model node here.
                modelNode.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args) {
                    if (args.PropertyName == "LabelVisible")
                    {
                        GraphControl.Invalidate();
                    }
                };
            }

            foreach (var edge in graph.Edges)
            {
                // Create and attach the model edge to the graph edge
                var modelEdge = new ModelEdge
                {
                    Source = (ModelNode)edge.GetSourceNode().Tag,
                    Target = (ModelNode)edge.GetTargetNode().Tag
                };
                edge.Tag = modelEdge;

                // Add the edge label
                var label = graph.AddLabel(edge, "", NinePositionsEdgeLabelModel.CenterCentered, edgeLabelStyle, tag: modelEdge);
            }

            // Create the mappings from model items to graph elements.
            modelNodeToINode = graph.Nodes.ToDictionary(node => (ModelNode)node.Tag);
            modelEdgeToIEdge = graph.Edges.ToDictionary(edge => (ModelEdge)edge.Tag);

            model = new NetworkModel(modelNodeToINode.Keys, modelEdgeToIEdge.Keys);
            GraphControl.Graph = graph;
        }