コード例 #1
0
 public GraphTabControl(List <MyPacket> data)
 {
     InitializeComponent();
     packets = data;
     FindAllNetworkInterfaces();
     FindAllNetworkConnections();
     CalculateStats();
     graph = new GraphPcap();
     Rand  = new Random();
     GraphAreaPcap_Setup();
     randomGraph();
     RelayoutGraph();
 }
コード例 #2
0
        private BidirectionalGraph <DataVertex, DataEdge> GraphPcap_Setup()
        {
            //Lets make new data graph instance
            var dataGraph = new GraphPcap();

            //Now we need to create edges and vertices to fill data graph
            //This edges and vertices will represent graph structure and connections
            //Lets make some vertices
            foreach (NetworkInterface n in interafaces)
            {
                //Create new vertex with specified Text. Also we will assign custom unique ID.
                //This ID is needed for several features such as serialization and edge routing algorithms.
                //If you don't need any custom IDs and you are using automatic Area.GenerateGraph() method then you can skip ID assignment
                //because specified method automaticaly assigns missing data ids (this behavior is controlled by method param).
                var dataVertex = new DataVertex("MAC : " + n.MAC);
                //Add vertex to data graph
                dataGraph.AddVertex(dataVertex);
            }

            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist = dataGraph.Vertices.ToList();

            //Then create two edges optionaly defining Text property to show who are connected
            foreach (NetworkInterface n in interafaces)
            {
                foreach (Connection connection in n.connections)
                {
                    var dataEdge = new DataEdge(vlist[n.pos], vlist[FindNetworkInteface(FindMacByIP(connection.adress))])
                    {
                        Text = string.Format("{0} Mb", connection.stats.speed)
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }
            //var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            //dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
            //dataGraph.AddEdge(dataEdge);

            return(dataGraph);
        }