Esempio n. 1
0
 public void CreateArtist(ArtistDTO artistDTO)
 {
     using (var transaction = ArtistRepository.UnitOfWork.BeginTransaction(2))
     {
         ArtistRepository.Add(ArtistFactory.CreateArtist(artistDTO.Name, artistDTO.Description, artistDTO.Country, artistDTO.Year));
         transaction.Commit();
     }
 }
Esempio n. 2
0
        public async Task <OperationResult <bool> > ScanArtist(ApplicationUser user, Guid artistId,
                                                               bool isReadOnly = false)
        {
            var sw = new Stopwatch();

            sw.Start();

            var errors = new List <Exception>();
            var artist = DbContext.Artists.FirstOrDefault(x => x.RoadieId == artistId);

            if (artist == null)
            {
                await LogAndPublish($"ScanArtist Unknown Release [{artistId}]", LogLevel.Warning);

                return(new OperationResult <bool>(true, $"Artist Not Found [{artistId}]"));
            }

            try
            {
                var result =
                    await ArtistFactory.ScanArtistReleasesFolders(artist.RoadieId, Configuration.LibraryFolder,
                                                                  isReadOnly);

                CacheManager.ClearRegion(artist.CacheRegion);
            }
            catch (Exception ex)
            {
                await LogAndPublish(ex.ToString(), LogLevel.Error);

                errors.Add(ex);
            }

            sw.Stop();
            DbContext.ScanHistories.Add(new data.ScanHistory
            {
                UserId            = user.Id,
                ForArtistId       = artist.Id,
                NewReleases       = ReleaseLookupEngine.AddedReleaseIds.Count(),
                NewTracks         = ReleaseFactory.AddedTrackIds.Count(),
                TimeSpanInSeconds = (int)sw.Elapsed.TotalSeconds
            });
            await DbContext.SaveChangesAsync();

            await UpdateArtistRank(artist.Id, true);
            await LogAndPublish($"ScanArtist `{artist}`, By User `{user}`", LogLevel.Information);

            return(new OperationResult <bool>
            {
                IsSuccess = !errors.Any(),
                AdditionalData = new Dictionary <string, object> {
                    { "artistAverage", artist.Rating }
                },
                OperationTime = sw.ElapsedMilliseconds,
                Errors = errors
            });
        }
Esempio n. 3
0
 public void CreateArtist(ArtistDto artistDto)
 {
     using (var transaction = _artistRepository.unitOfWork.BeginTransaction(3))
     {
         _artistRepository.Add(ArtistFactory.CreateArtist(artistDto.DisplayName,
                                                          artistDto.Firstname,
                                                          artistDto.Lastname,
                                                          artistDto.ArtistDetails));
     }
 }
        /// <summary>
        /// Arrange the Design instance of the Music Collection
        /// for use as the unit test context.
        /// </summary>
        /// <returns>An instance of the Design time Music Collection</returns>
        internal static MusicCollection Arrange_Db()
        {
            //  Instantiate the factories for creating the objects
            var _artistFactory = new ArtistFactory();
            var _wikiFactory = new WikiFactory();
            var _albumFactory = new AlbumFactory(_artistFactory, _wikiFactory);
            var _trackFactory = new TrackFactory(_artistFactory, _albumFactory);
            var _imageFactory = new ImageFactory();

            //  Instantiate the DesignMusicCollection which contains static data, used at design time, 
            //return new DesignMusicCollection(_artistFactory, _albumFactory, _trackFactory, _imageFactory);

            return null;
        }
Esempio n. 5
0
        public async Task <OperationResult <bool> > DeleteArtist(ApplicationUser user, Guid artistId)
        {
            var sw = new Stopwatch();

            sw.Start();
            var errors = new List <Exception>();
            var artist = DbContext.Artists.FirstOrDefault(x => x.RoadieId == artistId);

            if (artist == null)
            {
                await LogAndPublish($"DeleteArtist Unknown Artist [{artistId}]", LogLevel.Warning);

                return(new OperationResult <bool>(true, $"Artist Not Found [{artistId}]"));
            }

            try
            {
                var result = await ArtistFactory.Delete(artist);

                if (!result.IsSuccess)
                {
                    return new OperationResult <bool>
                           {
                               Errors = result.Errors
                           }
                }
                ;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                await LogAndPublish("Error deleting artist.");

                errors.Add(ex);
            }

            sw.Stop();
            await LogAndPublish($"DeleteArtist `{artist}`, By User `{user}`", LogLevel.Information);

            return(new OperationResult <bool>
            {
                IsSuccess = !errors.Any(),
                Data = true,
                OperationTime = sw.ElapsedMilliseconds,
                Errors = errors
            });
        }
 public void NormalArtistConstructNoSongsTest()
 {
     var target = new ArtistFactory();
     var raw = XElement.Parse(@"
     <artist id=""12039"">
     <name>Metallica</name>
     <albums>5</albums>
     <tag id=""2481"" count=""2"">Rock &amp; Roll</tag>
     <tag id=""2482"" count=""1"">Rock</tag>
     <tag id=""2483"" count=""1"">Roll</tag>
     <preciserating>3</preciserating>
     <rating>2.9</rating>
     </artist>");
     var actual = target.Construct(raw);
     Assert.That(actual.AlbumCount, Is.EqualTo(5));
     Assert.That(actual.SongCount, Is.EqualTo(0));
     Assert.That(actual.Name, Is.EqualTo("Metallica"));
     Assert.That(actual.Tags, Is.Not.Null);
 }
Esempio n. 7
0
        public AdminService(IRoadieSettings configuration,
                            IHttpEncoder httpEncoder,
                            IHttpContext httpContext,
                            data.IRoadieDbContext context,
                            ICacheManager cacheManager,
                            ILogger <ArtistService> logger,
                            IHubContext <ScanActivityHub> scanActivityHub
                            )
            : base(configuration, httpEncoder, context, cacheManager, logger, httpContext)
        {
            ScanActivityHub              = scanActivityHub;
            EventMessageLogger           = new EventMessageLogger();
            EventMessageLogger.Messages += EventMessageLogger_Messages;

            MusicBrainzProvider = new MusicBrainzProvider(configuration, cacheManager, MessageLogger);
            LastFmHelper        = new LastFmHelper(configuration, cacheManager, MessageLogger, context, httpEncoder);
            FileNameHelper      = new FileNameHelper(configuration, cacheManager, MessageLogger);
            ID3TagsHelper       = new ID3TagsHelper(configuration, cacheManager, MessageLogger);

            ArtistLookupEngine =
                new ArtistLookupEngine(configuration, httpEncoder, context, cacheManager, MessageLogger);
            LabelLookupEngine   = new LabelLookupEngine(configuration, httpEncoder, context, cacheManager, MessageLogger);
            ReleaseLookupEngine = new ReleaseLookupEngine(configuration, httpEncoder, context, cacheManager,
                                                          MessageLogger, ArtistLookupEngine, LabelLookupEngine);
            ImageFactory = new ImageFactory(configuration, httpEncoder, context, cacheManager, MessageLogger,
                                            ArtistLookupEngine, ReleaseLookupEngine);
            LabelFactory = new LabelFactory(configuration, httpEncoder, context, cacheManager, MessageLogger,
                                            ArtistLookupEngine, ReleaseLookupEngine);
            AudioMetaDataHelper = new AudioMetaDataHelper(configuration, httpEncoder, context, MusicBrainzProvider,
                                                          LastFmHelper, cacheManager,
                                                          MessageLogger, ArtistLookupEngine, ImageFactory, FileNameHelper, ID3TagsHelper);
            ReleaseFactory = new ReleaseFactory(configuration, httpEncoder, context, cacheManager, MessageLogger,
                                                ArtistLookupEngine, LabelFactory, AudioMetaDataHelper, ReleaseLookupEngine);
            ArtistFactory = new ArtistFactory(configuration, httpEncoder, context, cacheManager, MessageLogger,
                                              ArtistLookupEngine, ReleaseFactory, ImageFactory, ReleaseLookupEngine, AudioMetaDataHelper);
        }