public AlbumItemViewModel(string albumId, string artistName, string albumName, List<SearchResult> alternativeSearchResults, ServiceAgnosticAlbum originalSearch)
 {
     AlbumId = albumId;
     ArtistName = artistName;
     AlbumName = albumName;
     AlternativeSearchResults = alternativeSearchResults;
     OriginalSearch = originalSearch;
     ShouldImport = true;
 }
        private void AddItemToListOnScreen(SearchResult bestSearchResult, List<SearchResult> albumSearchResults, ServiceAgnosticAlbum originalSearch)
        {
            var itemViewModel = new AlbumItemViewModel(bestSearchResult.Id,
                bestSearchResult.DetailText,
                bestSearchResult.DisplayText,
                albumSearchResults,
                originalSearch);

            if (AlbumsInUI.FirstOrDefault(a => a.AlbumId == itemViewModel.AlbumId) == null)
            {
                AlbumsInUI.Add(itemViewModel);
                if (scrollViewer.VerticalOffset +200 >= scrollViewer.ViewportHeight)
                {
                    scrollViewer.ScrollToBottom();
                }
            }
            progressBar.Value = progress;
            progressText.Text = string.Format("{0} albums scanned (out of {1})", progress, progressBar.Maximum);
        }
        private SearchResult FindBestMatch(ServiceAgnosticAlbum album, List<SearchResult> albumSearchResults)
        {
            if (albumSearchResults == null || !albumSearchResults.Any())
                return null;

            // first try to match based on identical artist and album name
            var directMatch = albumSearchResults.Where(sr =>
                sr.DisplayText.ToLower() == album.AlbumName.ToLower()
                && sr.DetailText.ToLower() == album.ArtistName.ToLower());

            if (directMatch.Count() == 1)
                return directMatch.First();
            else if (directMatch.Count() > 1)
                albumSearchResults = directMatch.ToList();

            // next try to match just based on artist name
            var artistMatch = albumSearchResults.Where(sr => 
                sr.DetailText.ToLower() == album.ArtistName.ToLower());

            if (artistMatch.Count() == 1)
                return artistMatch.First();
            else if (artistMatch.Count() > 1)
                albumSearchResults = artistMatch.ToList();

            // next we'll try to zero down on textually similar artist and albums
            return albumSearchResults
                .Where(sr => 
                textComparisonAlgo.GetSimilarity(sr.DisplayText, album.AlbumName) +
                textComparisonAlgo.GetSimilarity(sr.DetailText, album.ArtistName) > 1)
                .OrderByDescending(sr =>
                textComparisonAlgo.GetSimilarity(sr.DisplayText, album.AlbumName) +
                textComparisonAlgo.GetSimilarity(sr.DetailText, album.ArtistName))
                .FirstOrDefault();

        }