Exemplo n.º 1
0
        private MusicLibrary()
        {
            ArtistGroupDictionary = CreateObservableGroupDictionary <Artist>();
            ArtistsCollection     = new CollectionViewSource()
            {
                IsSourceGrouped = true, Source = ArtistGroupDictionary
            };

            AlbumGroupDictionary = CreateObservableGroupDictionary <Album>();
            AlbumsCollection     = new CollectionViewSource()
            {
                IsSourceGrouped = true, Source = AlbumGroupDictionary
            };

            SongGroupDictionary = CreateObservableGroupDictionary <Song>();
            SongsCollection     = new CollectionViewSource()
            {
                IsSourceGrouped = true, Source = SongGroupDictionary
            };

            _cache = new MusicLibraryCache();
        }
Exemplo n.º 2
0
        public Task LoadCache(CoreDispatcher dispatcher, StorageFile cacheFile = null)
        {
            if (Interlocked.CompareExchange(ref _hasLoadedCache, 1, 0) == 1)
            {
                return(null);
            }

            return(Task.Run(new Action(() =>
            {
                try
                {
                    _cache = AsyncInline.Run(new Func <Task <MusicLibraryCache> >(() => MusicLibraryCache.Deserialize(cacheFile)));
                    var c = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low,
                                                () =>
                    {
                        foreach (Artist artist in _cache.Artists.Values)
                        {
                            AddItemToGroup(ArtistGroupDictionary, artist, a => a.ArtistName[0]);
                        }
                        foreach (List <Album> albums in _cache.Albums.Values)
                        {
                            foreach (Album album in albums)
                            {
                                AddItemToGroup(AlbumGroupDictionary, album, a => a.AlbumName[0]);
                            }
                        }
                        foreach (List <Song> songs in _cache.Songs.Values)
                        {
                            foreach (Song song in songs)
                            {
                                AddItemToGroup(SongGroupDictionary, song, a => song.SongTitle[0]);
                            }
                        }
                    });
                }
                catch { }
            })));
        }