Exemple #1
0
        public void Execute(RefreshArtistCommand message)
        {
            var trigger = message.Trigger;
            var isNew   = message.IsNewArtist;

            if (message.ArtistId.HasValue)
            {
                var  artist  = _artistService.GetArtist(message.ArtistId.Value);
                bool updated = false;
                try
                {
                    updated = RefreshEntityInfo(artist, null, true, false);
                    _logger.Trace($"Artist {artist} updated: {updated}");
                    RescanArtist(artist, isNew, trigger, updated);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't refresh info for {0}", artist);
                    RescanArtist(artist, isNew, trigger, updated);
                    throw;
                }
            }
            else
            {
                var allArtists = _artistService.GetAllArtists().OrderBy(c => c.Name).ToList();

                foreach (var artist in allArtists)
                {
                    var manualTrigger = message.Trigger == CommandTrigger.Manual;

                    if (manualTrigger || _checkIfArtistShouldBeRefreshed.ShouldRefresh(artist))
                    {
                        bool updated = false;
                        try
                        {
                            updated = RefreshEntityInfo(artist, null, manualTrigger, false);
                        }
                        catch (Exception e)
                        {
                            _logger.Error(e, "Couldn't refresh info for {0}", artist);
                        }

                        RescanArtist(artist, false, trigger, updated);
                    }
                    else
                    {
                        _logger.Info("Skipping refresh of artist: {0}", artist.Name);
                        RescanArtist(artist, false, trigger, false);
                    }
                }
            }
        }
        public void Execute(RefreshArtistCommand message)
        {
            var trigger = message.Trigger;
            var isNew   = message.IsNewArtist;

            if (message.ArtistId.HasValue)
            {
                RefreshSelectedArtists(new List <int> {
                    message.ArtistId.Value
                }, isNew, trigger);
            }
            else
            {
                var updated   = false;
                var artists   = _artistService.GetAllArtists().OrderBy(c => c.Name).ToList();
                var artistIds = artists.Select(x => x.Id).ToList();

                var updatedMusicbrainzArtists = new HashSet <string>();

                if (message.LastExecutionTime.HasValue && message.LastExecutionTime.Value.AddDays(14) > DateTime.UtcNow)
                {
                    updatedMusicbrainzArtists = _artistInfo.GetChangedArtists(message.LastStartTime.Value);
                }

                foreach (var artist in artists)
                {
                    var manualTrigger = message.Trigger == CommandTrigger.Manual;

                    if ((updatedMusicbrainzArtists == null && _checkIfArtistShouldBeRefreshed.ShouldRefresh(artist)) ||
                        (updatedMusicbrainzArtists != null && updatedMusicbrainzArtists.Contains(artist.ForeignArtistId)) ||
                        manualTrigger)
                    {
                        try
                        {
                            updated |= RefreshEntityInfo(artist, null, manualTrigger, false, message.LastStartTime);
                        }
                        catch (Exception e)
                        {
                            _logger.Error(e, "Couldn't refresh info for {0}", artist);
                        }
                    }
                    else
                    {
                        _logger.Info("Skipping refresh of artist: {0}", artist.Name);
                    }
                }

                Rescan(artists, isNew, trigger, updated);
            }
        }
        public void Handle(AlbumAddedEvent message)
        {
            if (message.DoRefresh)
            {
                var artist = message.Album.Artist.Value;

                if (_checkIfArtistShouldBeRefreshed.ShouldRefresh(artist))
                {
                    _commandQueueManager.Push(new RefreshArtistCommand(artist.Id));
                }
                else
                {
                    _commandQueueManager.Push(new RefreshAlbumCommand(message.Album.Id, true));
                }
            }
        }