BeatMachine.Model.DataModel.StoreDownloadedSongs C# (CSharp) Method

StoreDownloadedSongs() private method

private StoreDownloadedSongs ( BeatMachine.EchoNest.Model.Catalog cat ) : void
cat BeatMachine.EchoNest.Model.Catalog
return void
        private void StoreDownloadedSongs(Catalog cat)
        {
            logger.Debug("Downloaded {0} songs", cat.Items.Count);

            var analyzedSongs = cat.Items.
                Select<Song, AnalyzedSong>(s => new AnalyzedSong
                {
                    ItemId = s.Request.ItemId,
                    ArtistName = s.ArtistName ?? s.Request.ArtistName,
                    SongName = s.SongName ?? s.Request.SongName,
                    AudioSummary = s.AudioSummary != null ?
                    new AnalyzedSong.Summary
                    {
                        Tempo = s.AudioSummary.Tempo,
                        ItemId = s.Request.ItemId
                    } : null
                }).
                Where<AnalyzedSong>(s =>
                {
                    bool matches = SongsToAnalyzeIds.Contains(s.ItemId);
                    if (matches)
                    {
                        logger.Trace("Song '{0}' matches a song we're looking for", s);
                    }
                    return matches;
                });

            int analyzedCount = analyzedSongs.Count();

            logger.Debug("Matched {0} songs", analyzedCount);

            if (analyzedCount > 0)
            {
                using (BeatMachineDataContext context = new BeatMachineDataContext(
                    BeatMachineDataContext.DBConnectionString))
                {
                    context.AnalyzedSongs.InsertAllOnSubmit(analyzedSongs);
                    context.SubmitChanges();
                }

                logger.Debug("Stored all matches to database");

                foreach (AnalyzedSong s in analyzedSongs)
                {
                    SongsToAnalyze.Remove(
                        SongsToAnalyze.Where(x => String.Equals(x.ItemId, s.ItemId)).First());
                    SongsToAnalyzeIds.Remove(s.ItemId);
                }

                logger.Debug("Removed matches from list of songs to analyze");

                NewSongsAdded = true;
            }
        }