Пример #1
0
        public static async Task<MusicLibrary> Open(LocalLibrarySource localLibrarySource, params PropertyChangedEventHandler[] propertyChangedEventHandlers)
        {
            MusicLibrary library = new MusicLibrary(localLibrarySource);

            if (propertyChangedEventHandlers != null)
                foreach (var handler in propertyChangedEventHandlers)
                    library.PropertyChanged += handler;
            library.databaseConnection = await ConnectToDatabase();
            library.PlaylistManager = new ListPlaylistManager(library.databaseConnection);
            library.Songs = new ObservableCollection<Song>(await library.databaseConnection.Table<Song>().ToListAsync());
            library.Artists = new ObservableCollection<string>(library.Songs.Select(p => p.AlbumArtist).Where(p => p.Trim() != "").Distinct(StringComparer.CurrentCultureIgnoreCase));
            library.Albums = new ObservableCollection<Album>(library.Songs.Select(p => new Album(p.Album, p.AlbumArtist, library)).Where(p => p.Name.Trim() != "").Distinct());
            library.SavedPlaylists = new ObservableCollection<SavedPlaylist>(await library.databaseConnection.Table<SavedPlaylist>().ToListAsync());
            library.Genres = new ObservableCollection<Genre>(await library.databaseConnection.Table<Genre>().OrderBy(p => p.Name).ToListAsync());
            library.NotifyPropertyChanged("Songs");
            library.NotifyPropertyChanged("Artists");
            library.NotifyPropertyChanged("Albums");
            library.NotifyPropertyChanged("PlaylistManager");
            library.NotifyPropertyChanged("SavedPlaylists");
            library.NotifyPropertyChanged("Genres");

            return library;
        }
Пример #2
0
 private MusicLibrary(LocalLibrarySource localLibrarySource) { this.localLibrarySource = localLibrarySource; }