/// <summary> /// Gets the user data key. /// </summary> /// <returns>System.String.</returns> protected override string CreateUserDataKey() { if (ConfigurationManager.Configuration.EnableStandaloneMusicKeys) { var songKey = IndexNumber.HasValue ? IndexNumber.Value.ToString("0000") : string.Empty; if (ParentIndexNumber.HasValue) { songKey = ParentIndexNumber.Value.ToString("0000") + "-" + songKey; } songKey += Name; if (!string.IsNullOrWhiteSpace(Album)) { songKey = Album + "-" + songKey; } var albumArtist = AlbumArtists.FirstOrDefault(); if (!string.IsNullOrWhiteSpace(albumArtist)) { songKey = albumArtist + "-" + songKey; } return(songKey); } var parent = AlbumEntity; if (parent != null) { var parentKey = parent.GetUserDataKey(); if (IndexNumber.HasValue) { var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "") + (IndexNumber.Value.ToString("0000 - ")); return(parentKey + songKey); } } return(base.CreateUserDataKey()); }
/// <summary> /// Method to add a track to Player /// </summary> /// <param name="track"></param> private void AddTrack(XmlTrack track) { string albumName = track.AlbumArtist; if (string.IsNullOrEmpty(albumName)) { albumName = Path.GetFileName(Path.GetDirectoryName(track.Location)); } XmlAlbumArtist tempBand = GetBand(albumName); if (tempBand == null) { tempBand = new XmlAlbumArtist(albumName); Library.Add(tempBand.Name, tempBand); AlbumArtists.Add(tempBand); } XmlAlbum tempAlbum = tempBand.GetAlbum(track.GetAlbumKey()); if (tempAlbum == null) { tempAlbum = new XmlAlbum(track.GetAlbumKey()); Library[albumName].AddAlbum(tempAlbum); Albums.Add(tempAlbum); } XmlDisc tempDisc = tempAlbum.GetDisc(track.GetDiscKey()); if (tempDisc == null) { tempDisc = new XmlDisc(track.GetDiscKey()); Library[albumName].GetAlbum(track.GetAlbumKey()).AddDisc(tempDisc); Discs.Add(tempDisc); } if (Library[albumName].GetAlbum(track.GetAlbumKey()).GetDisc(track.GetDiscKey()).AddTrack(track)) { Tracks.Add(track); } }
public Dictionary <string, Tuple <string, string> > Diff(AudioTag other) { var output = new Dictionary <string, Tuple <string, string> >(); if (!IsValid || !other.IsValid) { return(output); } if (Title != other.Title) { output.Add("Title", Tuple.Create(Title, other.Title)); } if ((Performers != null && Performers.Any()) ^ (other.Performers != null && other.Performers.Any()) || ( other.Performers != null && other.Performers.Any() && Performers != null && Performers.Any() && !Performers.SequenceEqual(other.Performers))) { var oldValue = Performers != null && Performers.Any() ? string.Join(" / ", Performers) : null; var newValue = other.Performers != null && other.Performers.Any() ? string.Join(" / ", other.Performers) : null; output.Add("Artist", Tuple.Create(oldValue, newValue)); } if (Album != other.Album && other.Album != null) { output.Add("Album", Tuple.Create(Album, other.Album)); } if ((AlbumArtists != null && AlbumArtists.Any()) ^ (other.AlbumArtists != null && other.AlbumArtists.Any()) || ( other.AlbumArtists != null && other.AlbumArtists.Any() && AlbumArtists != null && AlbumArtists.Any() && !AlbumArtists.SequenceEqual(other.AlbumArtists))) { var oldValue = AlbumArtists != null && AlbumArtists.Any() ? string.Join(" / ", AlbumArtists) : null; var newValue = other.AlbumArtists != null && other.AlbumArtists.Any() ? string.Join(" / ", other.AlbumArtists) : null; output.Add("Album Artist", Tuple.Create(oldValue, newValue)); } if (Track != other.Track) { output.Add("Track", Tuple.Create(Track.ToString(), other.Track.ToString())); } if (TrackCount != other.TrackCount) { output.Add("Track Count", Tuple.Create(TrackCount.ToString(), other.TrackCount.ToString())); } if (Disc != other.Disc) { output.Add("Disc", Tuple.Create(Disc.ToString(), other.Disc.ToString())); } if (DiscCount != other.DiscCount) { output.Add("Disc Count", Tuple.Create(DiscCount.ToString(), other.DiscCount.ToString())); } if (Media != other.Media) { output.Add("Media Format", Tuple.Create(Media, other.Media)); } if (Date != other.Date) { var oldValue = Date.HasValue ? Date.Value.ToString("yyyy-MM-dd") : null; var newValue = other.Date.HasValue ? other.Date.Value.ToString("yyyy-MM-dd") : null; output.Add("Date", Tuple.Create(oldValue, newValue)); } if (OriginalReleaseDate != other.OriginalReleaseDate) { // Id3v2.3 tags can only store the year, not the full date if (OriginalReleaseDate.HasValue && OriginalReleaseDate.Value.Month == 1 && OriginalReleaseDate.Value.Day == 1) { if (OriginalReleaseDate.Value.Year != other.OriginalReleaseDate.Value.Year) { output.Add("Original Year", Tuple.Create(OriginalReleaseDate.Value.Year.ToString(), other.OriginalReleaseDate.Value.Year.ToString())); } } else { var oldValue = OriginalReleaseDate.HasValue ? OriginalReleaseDate.Value.ToString("yyyy-MM-dd") : null; var newValue = other.OriginalReleaseDate.HasValue ? other.OriginalReleaseDate.Value.ToString("yyyy-MM-dd") : null; output.Add("Original Release Date", Tuple.Create(oldValue, newValue)); } } if (Publisher != other.Publisher) { output.Add("Label", Tuple.Create(Publisher, other.Publisher)); } if ((Genres != null && Genres.Any()) ^ (other.Genres != null && other.Genres.Any()) || ( other.Genres != null && other.Genres.Any() && Genres != null && Genres.Any() && !Genres.SequenceEqual(other.Genres))) { var oldValue = Genres != null && Genres.Any() ? string.Join(" / ", Genres) : null; var newValue = other.Genres != null && other.Genres.Any() ? string.Join(" / ", other.Genres) : null; output.Add("Genres", Tuple.Create(oldValue, newValue)); } if (ImageSize != other.ImageSize) { output.Add("Image Size", Tuple.Create(ImageSize.ToString(), other.ImageSize.ToString())); } return(output); }
internal string GetFormattedArtists() { return(AlbumArtists.IsNullorEmpty() ? Consts.UnknownArtists : string.Join(Consts.CommaSeparator, AlbumArtists)); }
internal string GetFormattedArtists() { return(AlbumArtists.IsNullorEmpty() ? (IsOnedrive ? "Not cache in local" : Consts.UnknownArtists) : string.Join(Consts.CommaSeparator, AlbumArtists)); }
public string getArtistString() { string ArtistString; if (this.AlbumArtists == null || this.AlbumArtists.Count == 0) { return("No Artist"); } if (this.AlbumArtists.Count == 1) { ArtistString = AlbumArtists.ElementAt(0).ArtistName; return(ArtistString); } if (AlbumArtists.Count == 2) { ArtistString = AlbumArtists.ElementAt(0).ArtistName + " ft. " + AlbumArtists.ElementAt(1).ArtistName; return(ArtistString); } if (AlbumArtists.Count == 3) { ArtistString = AlbumArtists.ElementAt(0).ArtistName + " ft. " + AlbumArtists.ElementAt(1).ArtistName + ", " + AlbumArtists.ElementAt(2).ArtistName; return(ArtistString); } else { string tempstring = AlbumArtists.ElementAt(0).ArtistName; tempstring = tempstring + " ft. " + AlbumArtists.ElementAt(1).ArtistName; List <Artist> temp = new List <Artist>(); temp.Add(AlbumArtists.ElementAt(0)); temp.Add(AlbumArtists.ElementAt(1)); foreach (Artist ArtistName in AlbumArtists) { if (temp.Contains(ArtistName)) { } else { tempstring = tempstring + ", " + ArtistName.ArtistName; } } ArtistString = tempstring; return(ArtistString); } }
public async Task<bool> Handle(UpdateAlbumCommand request, CancellationToken cancellationToken) { if (request.AlbumId <= 0 || string.IsNullOrEmpty(request.AlbumName) || request.Stock < 0 || request.Type <= 0 || request.Artist == null || string.IsNullOrEmpty(request.Artist.Name)) { _logger.Information("Requesting to update album with invalid request {@request}, returning false.", request); return false; } try { _logger.Information("Request to update album {@Request}", request); using (var context = AlbumsDbContext.Create()) { using (var transaction = context.Database.BeginTransaction()) { var album = context.Albums.SingleOrDefault(a => a.Id == request.AlbumId); if (album != null) { var typeid = context.AlbumTypes.SingleOrDefault(t => t.Id == request.Type); album.AlbumName = request.AlbumName; album.TypeId = typeid.Id; var artist = context.Artists.FirstOrDefault(a => a.Name.Replace(" ", "").Equals(request.Artist.Name.Replace(" ", ""), StringComparison.InvariantCultureIgnoreCase)); if (artist == null) { artist = new Artist { Name = request.Artist.Name }; context.Artists.Add(artist); await context.SaveChangesAsync(); } var albumArtist = context.AlbumArtists.FirstOrDefault(ar => ar.AlbumId == request.AlbumId); if (albumArtist == null) { var ar = new AlbumArtists { AlbumId = album.Id, ArtistId = artist.Id }; context.AlbumArtists.Add(ar); await context.SaveChangesAsync(); } else { albumArtist.ArtistId = artist.Id; await context.SaveChangesAsync(); } var inventory = context.Inventory.SingleOrDefault(i => i.SKU.Equals(album.SKU, StringComparison.InvariantCultureIgnoreCase)); if (inventory == null) { // insert inventory record inventory = new Data.Models.Inventory { SKU = album.SKU, Stock = request.Stock }; context.Inventory.Add(inventory); } else { // update inventory record inventory.Stock = request.Stock; } await context.SaveChangesAsync(); } transaction.Commit(); } } _logger.Information("Album was updated succesfully"); return true; } catch (Exception ex) { _logger.Error(ex, "Errored while updating album with message {message}", ex.Message); return false; } }
public async Task <int> Handle(CreateAlbumCommand request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.AlbumName) || request.Stock < 0 || request.Type <= 0 || string.IsNullOrEmpty(request.ArtistName)) { _logger.Information("Requesting to create album with invalid request {@request}, returning 0.", request); return(0); } var albumId = 0; try { _logger.Information("Request for creating album {@request}", request); using (var context = AlbumsDbContext.Create()) { using (var transaction = context.Database.BeginTransaction()) { var typeid = context.AlbumTypes.SingleOrDefault(t => t.Id == request.Type); var album = new Album { AlbumName = request.AlbumName, TypeId = typeid.Id, SKU = GenerateSku() }; context.Albums.Add(album); await context.SaveChangesAsync(); albumId = album.Id; var artist = context.Artists.FirstOrDefault(a => a.Name.Replace(" ", "").Equals(request.ArtistName.Replace(" ", ""), StringComparison.InvariantCultureIgnoreCase)); if (artist == null) { artist = new Artist { Name = request.ArtistName }; context.Artists.Add(artist); await context.SaveChangesAsync(); } var albumArtist = new AlbumArtists { AlbumId = album.Id, ArtistId = artist.Id }; context.AlbumArtists.Add(albumArtist); var inventory = new Inventory { SKU = album.SKU, Stock = request.Stock }; context.Inventory.Add(inventory); await context.SaveChangesAsync(); transaction.Commit(); } } _logger.Information("Album was created with id {id}", albumId); return(albumId); } catch (Exception ex) { _logger.Error(ex, "Errored creating album with message {message}", ex.Message); return(0); } }