Exemplo n.º 1
0
        public IEdge AddEdge(IEdge edge)
        {
            if (edge == null)
            {
                throw new ArgumentNullException(nameof(edge));
            }
            if (!Equals(edge.Parent) && !SubGraphs.ContainsKey(edge.Parent))
            {
                throw new ArgumentException(FormattableString.Invariant($"Parent of Edge {edge} not within Graph!"));
            }
            if ((edge.SourceNode == null) || !Nodes.ContainsKey(edge.SourceNode))
            {
                throw new ArgumentException(
                          FormattableString.Invariant($"SourceNode {edge.SourceNode} not within Graph!"));
            }
            if ((edge.EndNode == null) || !Nodes.ContainsKey(edge.EndNode))
            {
                throw new ArgumentException(FormattableString.Invariant($"EndNode {edge.EndNode} not within Graph!"));
            }
            if (!Edges.ContainsKey(edge))
            {
                Edges[edge] = edge;
            }
            var addedEdge = Edges[edge];

            addedEdge.SetAttributes(edge.GetAttributes());
            return(addedEdge);
        }
Exemplo n.º 2
0
        public ISubGraph AddSubGraph(ISubGraph subgraph)
        {
            if (subgraph == null)
            {
                throw new ArgumentNullException(nameof(subgraph));
            }
            if (!Equals(subgraph.Parent) && !SubGraphs.ContainsKey(subgraph.Parent))
            {
                throw new ArgumentException(
                          FormattableString.Invariant($"Parent of SubGraph {subgraph.Id} not within Graph!"));
            }
            if (!SubGraphs.ContainsKey(subgraph))
            {
                SubGraphs[subgraph] = subgraph;
            }
            var addedSubGraph = SubGraphs[subgraph];

            addedSubGraph.SetAttributes(subgraph.GetAttributes());
            return(addedSubGraph);
        }
Exemplo n.º 3
0
 public void RemoveSubGraph(ISubGraph subgraph)
 {
     if ((subgraph != null) && SubGraphs.ContainsKey(subgraph))
     {
         var subgraphs = SubGraphs[subgraph].GetSubGraphSubGraphs().ToList();
         foreach (var sg in subgraphs)
         {
             RemoveSubGraph(sg);
         }
         var edges = SubGraphs[subgraph].GetSubGraphEdges().ToList();
         foreach (var edge in edges)
         {
             RemoveEdge(edge);
         }
         var nodes = SubGraphs[subgraph].GetSubGraphNodes().ToList();
         foreach (var node in nodes)
         {
             RemoveNode(node);
         }
     }
 }
Exemplo n.º 4
0
        public INode AddNode(INode node, bool checkParent = true)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (!Equals(node.Parent) && !SubGraphs.ContainsKey(node.Parent))
            {
                throw new ArgumentException(FormattableString.Invariant($"Parent of Node {node} not within Graph!"));
            }
            if (!Nodes.ContainsKey(node))
            {
                Nodes[node] = node;
            }
            var addedNode = Nodes[node];

            if (checkParent && (addedNode.Parent != node.Parent))
            {
                throw new ArgumentException(FormattableString.Invariant(
                                                $"Mismatching node Parent ({addedNode.Parent.Id} vs {node.Parent.Id}) for node {node}!"));
            }
            addedNode.SetAttributes(node.GetAttributes());
            return(addedNode);
        }