/// <summary> /// /// </summary> /// <param name="node"></param> /// <returns>Returns whether the sub-tree has been fully expanded in the hierarchy.</returns> public override void GenerateSubTree(IHierarchyNode node) { ArtistHierarchyNode subTreeNode = (ArtistHierarchyNode)node; ArtistGroup relatedArtistList = Client.GetRelatedArtists(subTreeNode.ArtistViewModel.Artist.ID); //First determine which artists are new; add those. int nodesAdded = 0; foreach (Artist relatedArtist in relatedArtistList.Artists) { if (NodeDictionary.ContainsKey(relatedArtist.Name)) { continue; } if (nodesAdded < AddChildrenLimit) { ArtistViewModel artistViewModel = new ArtistViewModel(relatedArtist); ArtistHierarchyNode relatedArtistNode = new ArtistHierarchyNode(artistViewModel, this, subTreeNode, subTreeNode.Level + 1); subTreeNode.Children.Add(relatedArtistNode); NodeDictionary.Add(relatedArtist.Name, relatedArtistNode); nodesAdded++; } else { return; } } }
/// <summary> /// remove node from the net /// </summary> /// <param name="datas"></param> public void RemoveNodes(params Node[] datas) { if (datas.Length == 0) { nodes = new NodeDictionary(); removedIDs = new List <int>(); uniqueID = 1; return; } foreach (var node in datas) { if (nodes.ContainsKey(node.id)) { // disconnect all the neighbors foreach (var neighborID in node.neighbors) { var neighborNode = GetNode(neighborID); if (neighborNode != null && neighborNode.neighbors.Contains(node.id)) { neighborNode.neighbors.Remove(node.id); } } //reset downstream connection foreach (var nodeID in node.downstreams) //TODO move to neighbor check { var checkNode = GetNode(nodeID); if (checkNode != null && checkNode.downstreams != null && checkNode.downstreams.Contains(node.id)) { checkNode.downstreams.Remove(node.id); } } //Recycle ID if (!removedIDs.Contains(node.id)) { removedIDs.Add(node.id); } //Remove node nodes.Remove(node.id); } } }
public bool TryRemoveNode(Node node) { if (NodeDictionary.ContainsKey(node.ID)) { Nodes.Remove(node); NodeDictionary.Remove(node.ID); return(true); } return(false); }
public bool TryAddNode(Node node) { if (NodeDictionary.ContainsKey(node.ID) == false) { Nodes.Add(node); NodeDictionary.Add(node.ID, node); return(true); } return(false); }
void BuildNodeDictionary() { NodeDictionary.Clear(); foreach (var node in Nodes) { if (NodeDictionary.ContainsKey(node.ID) == false) { NodeDictionary.Add(node.ID, node); } } }
public static MatrixNode At(int x, int y, bool createIfNull = true) { if (nodes.ContainsKey(x, y)) { return(nodes[x, y]); } if (createIfNull) { nodes[x, y] = new MatrixNode(); return(nodes[x, y]); } return(null); }
public Boolean Add([CanBeNull] T item) { if (item is null) { return(false); } if (NodeDictionary.ContainsKey(item)) { return(false); } LinkedListNode <T> node = LinkedList.AddLast(item); NodeDictionary.Add(item, node); return(true); }
/// <summary> /// Generates the tree from the root artist. /// </summary> /// <param name="artist"></param> protected override void GenerateTree(object obj) { Artist artist = (Artist)obj; if (NodeDictionary.ContainsKey(artist.Name)) { return; } ArtistViewModel rootViewModel = new ArtistViewModel(artist); ArtistHierarchyNode root = new ArtistHierarchyNode(rootViewModel, this, null, 0); RootNodes.Add(root); NodeDictionary.Add(artist.Name, root); ArtistGroup relatedArtistList = Client.GetRelatedArtists(artist.ID); //First determine which artists are new; add those. List <Artist> newArtists = new List <Artist>(); int nodesAdded = 0; foreach (Artist relatedArtist in relatedArtistList.Artists) { if (NodeDictionary.ContainsKey(relatedArtist.Name)) { continue; } if (nodesAdded < AddChildrenLimit) { newArtists.Add(relatedArtist); ArtistViewModel artistViewModel = new ArtistViewModel(relatedArtist); ArtistHierarchyNode relatedArtistNode = new ArtistHierarchyNode(artistViewModel, this, root, 1); root.Children.Add(relatedArtistNode); NodeDictionary.Add(relatedArtist.Name, relatedArtistNode); nodesAdded++; } else { break; } } }
public Boolean Insert(Int32 index, T?item) { if (index < 0 || index >= Count) { throw new ArgumentNullException(nameof(index)); } if (item is null) { return(false); } if (NodeDictionary.ContainsKey(item)) { return(false); } LinkedListNode <T> node = LinkedList.Insert(index, item); NodeDictionary.Add(item, node); return(true); }
public static NodeStatus Run(Node node, NodeDictionary nodeDictionary) { NodeState nodeState; if (!nodeDictionary.ContainsKey(node)) { nodeState = new Dictionary <string, object>(); node.OnInitialize(nodeDictionary, nodeState); nodeDictionary[node] = nodeState; } else { nodeState = nodeDictionary[node]; } var status = node.OnTick(nodeDictionary, nodeState); if (status == NodeStatus.Success) { node.OnSuccess(nodeDictionary, nodeState); } return(status); }
public bool HasNode(string id) { return(NodeDictionary.ContainsKey(id)); }