Exemple #1
0
        private void GenerateTree(String artistName)
        {
            //Going to separate artists based on the genres used to describe them.
            //Assume that the first artist is what we're pivoting on.

            if (NodeDictionary.ContainsKey(artistName))
            {
                return;
            }

            ArtistList rootArtistList = Client.GetArtist(artistName);

            //TODO: Using the first one for now.  Since there could be multiple roots, we'll need to handle this.
            Artist          rootArtist    = rootArtistList.Artists.Items[0];
            ArtistViewModel rootViewModel = new ArtistViewModel(rootArtist);
            HierarchyNode   root          = new HierarchyNode(rootViewModel, null, 0);

            RootNodes.Add(root);
            rootViewModel.SetHierarchyNode(root);
            NodeDictionary.Add(rootArtist.Name, root);

            ArtistGroup relatedArtistList = Client.GetRelatedArtists(rootArtist.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 < MaxChildren)
                {
                    newArtists.Add(relatedArtist);

                    ArtistViewModel artistViewModel   = new ArtistViewModel(relatedArtist);
                    HierarchyNode   relatedArtistNode = new HierarchyNode(artistViewModel, root, 1);
                    root.Children.Add(relatedArtistNode);
                    artistViewModel.SetHierarchyNode(relatedArtistNode);
                    NodeDictionary.Add(relatedArtist.Name, relatedArtistNode);

                    nodesAdded++;
                }
                else
                {
                    break;
                }
            }
        }