Ejemplo n.º 1
0
        public async Task <DateTime> DetermineMusicLibraryLastUpdateDate()
        {
            var sections = await DiscoverMusicSections();

            if (MusicSections == null)
            {
                sections = MusicSections;
            }
            return(MusicSections.Max(p => p.LastUpdated));
        }
Ejemplo n.º 2
0
        public async Task GetMusicSectionDetails()
        {
            DoProgress("Getting music section details");

            var sections = await DiscoverMusicSections();

            if (MusicSections == null)
            {
                DoProgress("No existing data; rebuilding from scratch");
                MusicSections = sections;
            }
            else
            {
                //TODO: Delete Old Ones..
                //TODO: Add New Ones..
                //Yeah this needs to go into one linq statement, but have a three year old bothering me right now..

                DoProgress("Merging music data");

                foreach (var section in sections)
                {
                    if (MusicSections.Exists(p => p.Key == section.Key))
                    {
                        var ms = MusicSections.Single(p => p.Key == section.Key);
                        if (ms.LastUpdated < section.LastUpdated)
                        {
                            //Puke, need to just figure out what changed, not reload whole collection
                            ms.LastProcessed = null;
                        }
                    }
                    else
                    {
                        MusicSections.Add(section);
                        section.LastProcessed = null;
                    }
                }
            }

            var sectionsNeverUpdated = MusicSections.Where(p => p.LastProcessed == null);

            foreach (var section in sectionsNeverUpdated)
            {
                var artists = await GetMusicSectionArtists(section);

                section.LastProcessed = DateTime.Now;
                section.Artists       = artists;

                DoProgress(String.Format("Added section '{0}', {1} artists", section.Name, artists.Count));
            }
            PopulateIndicies();
        }
Ejemplo n.º 3
0
        private void PopulateIndicies()
        {
            lock (this)
            {
                var artists = MusicSections.SelectMany(p => p.Artists ?? Enumerable.Empty <Artist>());
                var albums  = artists.SelectMany(p => p.Albums ?? Enumerable.Empty <Album>());

                trackIndex = albums
                             .SelectMany(p => p.Tracks ?? Enumerable.Empty <Track>())
                             .Select(p => new KeyValuePair <string, Track>(p.Key, p))
                             .ToDictionary(kv => kv.Key, kv => kv.Value);
                albumIndex = albums
                             .Select(p => new KeyValuePair <string, Album>(p.Key, p))
                             .ToDictionary(kv => kv.Key, kv => kv.Value);
                artistIndex = artists
                              .Select(p => new KeyValuePair <string, Artist>(p.Key, p))
                              .ToDictionary(kv => kv.Key, kv => kv.Value);
            }
        }