/// <summary> /// /// </summary> /// <param name="graphNodeId"></param> public bool RemoveGraphNode(int graphnodeId) { GraphNode node = GetGraphNodeById(graphnodeId); node.Edges.RemoveRange(0, node.Edges.Count); return(GraphNodeCollection.Remove(node)); }
// make a clone of all GraphNode except that only a few GraphEdge are kept // remove all uneeded GraphEdge to have only one GraphEdge between 2 GraphNodes (direct or indirect link) private GraphNode GenerateSimplifiedGraph(GraphNodeCollection nodes, GraphNode centralNode) { List <GraphNode> nodeAlreadyExamined = new List <GraphNode>(); GraphNode output = GraphNode.CloneWithoutTrusts(centralNode); Dictionary <DomainKey, GraphNode> graph = new Dictionary <DomainKey, GraphNode>(); graph.Add(output.Domain, output); List <GraphNode> nodesToExamine = new List <GraphNode>(); nodesToExamine.Add(centralNode); // proceed layer by layer for (int currentLevel = 0; ; currentLevel++) { List <GraphNode> nodesToExamineForNextLevel = new List <GraphNode>(); // this first iteration is important // it avoid a recursing exploration foreach (GraphNode nodeToExamine in nodesToExamine) { nodeAlreadyExamined.Add(nodeToExamine); } foreach (GraphNode nodeToExamine in nodesToExamine) { foreach (GraphEdge edge in nodeToExamine.Trusts.Values) { if (!nodeAlreadyExamined.Contains(edge.Destination) && !nodesToExamine.Contains(edge.Destination) && !nodesToExamineForNextLevel.Contains(edge.Destination)) { // make a clone and add one GraphEdge nodesToExamineForNextLevel.Add(edge.Destination); graph.Add(edge.Destination.Domain, GraphNode.CloneWithoutTrusts(edge.Destination)); GraphEdge newEdge = new GraphEdge(graph[nodeToExamine.Domain], graph[edge.Destination.Domain], null, false); graph[nodeToExamine.Domain].Trusts.Add(edge.Destination.Domain, newEdge); } } } if (nodesToExamineForNextLevel.Count == 0) { break; } nodesToExamine = nodesToExamineForNextLevel; } return(output); }