public MainPage() { this.InitializeComponent(); this.CurrentGroupType = SearchResultsGroupType.Song; this.tracklistPlayer = new TracklistPlayer.TracklistPlayer(this.mediaElement); this.tracklistPlayer.SongChanged += this.TracklistPlayer_SongChanged; this.songDBSearcher = new SongDBSearcher(); this.albumDBSearcher = new AlbumDBSearcher(); this.artistDBSearcher = new ArtistDBSearcher(); this.TrackList.ItemsSource = this.tracklistPlayer.TrackList; this.TracklistPlayerControl.SetTracklistPlayer(this.tracklistPlayer); }
public async Task SearchAsync(SearchResultsGroupType groupType, string[] phrases = null) { if (this.loadingSongsCancellationTokenSource != null) { this.loadingSongsCancellationTokenSource.Cancel(); } await Task.Factory.StartNew(() => { this.groupType = groupType; this.dbIds.Clear(); this.loadingSongsCancellationTokenSource = new CancellationTokenSource(); using (MusicLibraryContext dbContext = new MusicLibraryContext()) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string phrase = phrases != null ? phrases[0] : string.Empty; switch (this.groupType) { case SearchResultsGroupType.Song: this.dbIds = dbContext.Songs .Include(song => song.Album) .ThenInclude(album => album.Artist) .Where( song => song.Title.ContainsIgnoreCase(phrase) || song.Album.Name.ContainsIgnoreCase(phrase) || song.Album.Artist.Name.ContainsIgnoreCase(phrase)) .OrderBy(song => song.Title) .Select(song => song.SongId) .ToList(); stopwatch.Stop(); Debug.WriteLine(stopwatch.ElapsedMilliseconds); break; case SearchResultsGroupType.Album: this.dbIds = dbContext.Songs .Where( song => song.Title.ContainsIgnoreCase(phrase) || song.Album.Name.ContainsIgnoreCase(phrase) || song.Album.Artist.Name.ContainsIgnoreCase(phrase)) .OrderBy(song => song.Album.Name) .ThenBy(song => song.Track) .Select(song => song.AlbumId) .ToList(); stopwatch.Stop(); Debug.WriteLine(stopwatch.ElapsedMilliseconds); break; case SearchResultsGroupType.Artist: this.dbIds = dbContext.Songs .Include(song => song.Album) .ThenInclude(album => album.Artist) .Where( song => song.Title.ContainsIgnoreCase(phrase) || song.Album.Name.ContainsIgnoreCase(phrase) || song.Album.Artist.Name.ContainsIgnoreCase(phrase)) .OrderBy(song => song.Album.Artist.Name) .ThenBy(song => song.Album.Name) .ThenBy(song => song.Track) .Select(song => song.Album.ArtistId) .ToList(); stopwatch.Stop(); Debug.WriteLine(stopwatch.ElapsedMilliseconds); break; } } }); }
private async void ChangeViewType_ClickAsync(object sender, RoutedEventArgs e) { this.CurrentGroupType = groupTypesOrder.GetNextAfter(this.CurrentGroupType); await LoadSongsListForSearchExpression(this.SearchTextBox.Text); }