コード例 #1
0
        private void GetAlbumsForArtistCallback(IEnumerable <SynoItem> albums, long totalAlbumsCount, SynoItem artist)
        {
            foreach (var album in albums)
            {
                AlbumViewModel albumViewModel = _albumViewModelFactory.Create(album);

                // prepare an empty track list
                albumViewModel.Tracks.Clear();

                // album is busy because its tracks are getting loaded.
                albumViewModel.IsBusy = true;

                _searchService.GetTracksForAlbum(album, (synoTracks, count, containingAlbum) =>
                {
                    // Note - would it work, based on the synoitem instead of the ItemID ?
                    // Note - we rely on the fact that there each album is only present once in the artists discography ( based on its ItemID ) otherwise, it crashes !
                    var currentAlbumViewModel = Albums.Single(a => a.Album.ItemID == containingAlbum.ItemID);
                    currentAlbumViewModel.Tracks.Clear();
                    foreach (var track in synoTracks)
                    {
                        // track guid is empty for now : it will be filled when the track gets added to the playqueue
                        currentAlbumViewModel.Tracks.Add(this._trackViewModelFactory.Create(Guid.Empty, track, this._pageSwitchingService));
                    }
                    currentAlbumViewModel.IsBusy = false;
                });

                // TODO : Register Selected event and on event handler : Load the album's tracks and navigate to its index in the artist's albums panorama.
                // Note : So far, the viewmodels are never removed from the list : that means we don't need to unregister that event. If this changes,
                // then it will be necessary to enregister the event for each view model removed from the collection.
                albumViewModel.Selected += (s, e) =>
                {
                    string albumId = ((AlbumViewModel)s).Album.ItemID;
                    _navigatorSevice.UrlParameterToObjectsPlateHeater.RegisterObject(albumId, s);
                    _navigatorSevice.UrlParameterToObjectsPlateHeater.RegisterObject(artist.ItemID, artist);
                    Guid albumsListTicket = Guid.NewGuid();
                    _navigatorSevice.UrlParameterToObjectsPlateHeater.RegisterObject(albumsListTicket.ToString(), this.Albums);
                    _pageSwitchingService.NavigateToArtistPanorama(artist.ItemID, albumId, albumsListTicket.ToString());
                };
                Albums.Add(albumViewModel);
            }
        }