public AmazonAlbum GetAlbumInformation() { main.Cursor = Cursors.WaitCursor; List<AmazonAlbum> albums = new List<AmazonAlbum>(); using (AmazonAlbumInfo amazonInfo = new AmazonAlbumInfo()) { albums = amazonInfo.AmazonAlbumSearch(_selectedArtist, _selectedAlbum); } // Show the Album Selection dialog, if we got more than one album AmazonAlbum amazonAlbum = null; _askForAlbum = true; if (albums.Count > 0) { _askForAlbum = false; if (albums.Count == 1) { amazonAlbum = albums[0]; // If we didn't get any disc info, consider the album as not found if (amazonAlbum.Discs.Count == 0) _askForAlbum = true; } else { dlgSearchResult = new AlbumSearchResult(); for (int i = albums.Count - 1; i >= 0; i--) { AmazonAlbum foundAlbum = albums[i]; // Skip Albums with no Discs returned if (foundAlbum.Discs.Count == 0) { albums.RemoveAt(i); continue; } // count the number of tracks, as we may have multiple discs int trackCount = 0; foreach (List<AmazonAlbumTrack> tracks in foundAlbum.Discs) trackCount += tracks.Count; ListViewItem lvItem = new ListViewItem(foundAlbum.Artist); lvItem.SubItems.Add(foundAlbum.Title); lvItem.SubItems.Add(trackCount.ToString()); lvItem.SubItems.Add(foundAlbum.Year); lvItem.SubItems.Add(foundAlbum.Label); dlgSearchResult.ResultView.Items.Insert(0, lvItem); } main.Cursor = Cursors.Default; // When the Listview contains no items, none of the found albums has track information if (dlgSearchResult.ResultView.Items.Count == 0) _askForAlbum = true; else { if (main.ShowModalDialog(dlgSearchResult) == DialogResult.OK) { if (dlgSearchResult.ResultView.SelectedIndices.Count > 0) { amazonAlbum = albums[dlgSearchResult.ResultView.SelectedIndices[0]]; } else amazonAlbum = albums[0]; } else { // Don't ask for album again, since the user cancelled _askForAlbum = false; dlgSearchResult.Dispose(); return amazonAlbum; } } dlgSearchResult.Dispose(); } } main.Cursor = Cursors.Default; return amazonAlbum; }
private void DoSearchAlbum() { Cursor = Cursors.WaitCursor; tbArtist.Enabled = false; tbAlbum.Enabled = false; btSearch.Enabled = false; btUpdate.Enabled = false; using (AmazonAlbumInfo amazonInfo = new AmazonAlbumInfo()) { _albums = amazonInfo.AmazonAlbumSearch(_artist, _album); } if (_albums.Count > 0) { btUpdate.Enabled = true; groupBoxAmazonMultipleAlbums.Text = ServiceScope.Get<ILocalisation>().ToString("AmazonAlbumSearch", "GroupBoxResults"); if (_albums.Count == 1) { _amazonAlbum = _albums[0]; btUpdate.PerformClick(); // Close the Dialog } else { FillResults(); } } else { groupBoxAmazonMultipleAlbums.Text = ServiceScope.Get<ILocalisation>().ToString("AmazonAlbumSearch", "NotFound"); ServiceScope.Get<ILogger>().GetLogger.Debug("No Cover Art found"); btUpdate.Enabled = false; } tbArtist.Enabled = true; tbAlbum.Enabled = true; btSearch.Enabled = true; Cursor = Cursors.Default; }