Пример #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);
        }
Пример #2
0
 public void AddEdge(TSubGraphsEdge edge)
 {
     Contract.Requires(edge != null);
     Contract.Requires(SubGraphs.Contains(edge.Source), "Edge's source does not belong to the graph.");
     Contract.Requires(SubGraphs.Contains(edge.Destination), "Edge's source does not belong to the graph.");
     edges.Add(edge);
     RaiseChanged();
 }
Пример #3
0
        public Graph AddGraph(string name)
        {
            var gr = new Graph()
            {
                Name = name
            };

            SubGraphs.Add(gr);

            return(gr);
        }
Пример #4
0
        /// <summary>
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public SubGraph ResolveSubgraph(string code)
        {
            var __code = DotLanguageUtils.GetClusterCode(code);

            if (Code == __code)
            {
                return(this);
            }
            var result = SubGraphs.Select(sg => sg.ResolveSubgraph(__code)).FirstOrDefault(_ => null != _);

            return(result);
        }
Пример #5
0
        public void RemoveEmptySubgraphs()
        {
            IList <ISubGraph> emptySubgraphs;

            do
            {
                emptySubgraphs = GetSubGraphs().Where(
                    sg =>
                    !sg.GetSubGraphSubGraphs().Any() &&
                    !sg.GetSubGraphNodes().Any() &&
                    !sg.GetSubGraphEdges().Any()).ToList();
                foreach (var subgraph in emptySubgraphs)
                {
                    SubGraphs.Remove(subgraph);
                }
            } while (emptySubgraphs.Any());
        }
Пример #6
0
 /// <summary>
 /// Перемещает узлы по подграфам
 /// </summary>
 public void MoveNodesToSubgraphs()
 {
     foreach (var n in Nodes.ToArray())
     {
         if (!string.IsNullOrWhiteSpace(n.SubgraphCode))
         {
             var sg = ResolveSubgraph(n.SubgraphCode);
             if (null == sg)
             {
                 sg = new SubGraph {
                     Code = n.SubgraphCode, Parent = this
                 };
                 SubGraphs.Add(sg);
             }
             sg.Nodes.Add(n);
             n.Parent = sg;
             Nodes.Remove(n);
         }
     }
 }
Пример #7
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);
        }
Пример #8
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);
         }
     }
 }
Пример #9
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);
        }