/// <summary> /// Maps the Album returned from the Domain Model, to the AlbumModel of the UI /// </summary> /// <param name="albums">Domain Albums collection</param> /// <returns>AlbumModel collection</returns> private List<AlbumModel> MapAlbumsToAlbumModels(IEnumerable<Album> albums) { // The viewmodel collection var albumsViewModel = new List<AlbumModel>(); // Map the albums to the AlbumViewModel foreach (var a in albums) { var mappedAlbum = new AlbumModel(); //OK to New, UI model only, no injection needed. // Map the album specific data mappedAlbum.Id = a.Id.ToString(); // No localisation needed here, it's won't be actually displayed. mappedAlbum.Title = a.Title; mappedAlbum .RawReleased = a.Released; // Update the DateFormate property. mappedAlbum.ArtistName = a.Artist.Name; // Load the large and medium images only. var largeImage = a.Images.FirstOrDefault(i => i.Size == ImageSizeEnum.large); if (largeImage != null) mappedAlbum.SetImageLarge(largeImage.Url); else mappedAlbum.SetImageLarge(@"Assets\MediumGray.png"); var mediumImage = a.Images.FirstOrDefault(i => i.Size == ImageSizeEnum.medium); if (mediumImage != null) mappedAlbum.SetImageMedium(mediumImage.Url); else mappedAlbum.SetImageMedium(@"Assets\LightGray.png"); // Map the LastFM stuff. mappedAlbum.LastFMUrl = a.Url; mappedAlbum.LastFMMbid = a.Mbid; // Map the Wiki stuff mappedAlbum.Wiki = new WikiModel(); mappedAlbum.Wiki.Summary = a.Wiki.Summary; mappedAlbum.Wiki.Content = a.Wiki.Content; mappedAlbum.Wiki.RawPublished = a.Wiki.Published; // Set the DateTime property // Map the Genres. mappedAlbum.Genres = new List<GenreModel>(); foreach (var g in a.Genres) { var mappedGenre = new GenreModel() { Id = g.Id.ToString(), Name = g.Name, LastFMUrl = g.Url }; mappedAlbum.Genres.Add(mappedGenre); } // Map the tracks mappedAlbum.Tracks = new List<TrackModel>(); foreach (var tr in a.Tracks) { var mappedTrack = new TrackModel() { Id = tr.Id.ToString(), Number = tr.Number.ToString(), // No localisation here, there are unlikely to be more than 99 tracks. Title = tr.Title, RawDuration = tr.Duration, // set the TimeSpan property, not the localised display property LastFMMbid = tr.Mbid, LastFMUrl = tr.Url, MediaFilePath = tr.mediaFilePath }; mappedAlbum.Tracks.Add(mappedTrack); } // Add to the ViewModel albumsViewModel.Add(mappedAlbum); } return albumsViewModel; }
/// <summary> /// Create the mock track information /// </summary> /// <returns>mock tracks</returns> private static List<TrackModel> CreateDarkSideOfTheMoonTracks() { var darkSideTracks = new List<TrackModel>(); var Breathe = new TrackModel(); Breathe.Id = "1"; Breathe.Number = "1"; Breathe.Title = "Speak To Me/Breathe"; Breathe.RawDuration = new TimeSpan(00, 03, 57); Breathe.LastFMUrl = string.Empty; Breathe.LastFMMbid = string.Empty; Breathe.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(Breathe); var OnTheRun = new TrackModel(); OnTheRun.Id = "2"; OnTheRun.Number = "2"; OnTheRun.Title = "On the Run"; OnTheRun.RawDuration = new TimeSpan(00, 03, 55); OnTheRun.LastFMUrl = string.Empty; OnTheRun.LastFMMbid = string.Empty; OnTheRun.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(OnTheRun); var Time = new TrackModel(); Time.Id = "3"; Time.Number = "3"; Time.Title = "Time"; Time.RawDuration = new TimeSpan(00, 07, 04); Time.LastFMUrl = string.Empty; Time.LastFMMbid = string.Empty; Time.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(Time); var Gig = new TrackModel(); Gig.Id = "4"; Gig.Number = "4"; Gig.Title = "The Great Gig in the Sky"; Gig.RawDuration = new TimeSpan(00, 04, 47); Gig.LastFMUrl = string.Empty; Gig.LastFMMbid = string.Empty; Gig.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(Gig); var Money = new TrackModel(); Money.Id = "5"; Money.Number = "5"; Money.Title = "Money"; Money.RawDuration = new TimeSpan(00, 06, 22); Money.LastFMUrl = string.Empty; Money.LastFMMbid = string.Empty; Money.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(Money); var UsAndThem = new TrackModel(); UsAndThem.Id = "6"; UsAndThem.Number = "6"; UsAndThem.Title = "Us and Them"; UsAndThem.RawDuration = new TimeSpan(00, 07, 50); UsAndThem.LastFMUrl = string.Empty; UsAndThem.LastFMMbid = string.Empty; UsAndThem.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(UsAndThem); var AnyColour = new TrackModel(); AnyColour.Id = "7"; AnyColour.Number = "7"; AnyColour.Title = "Any Colour You Like"; AnyColour.RawDuration = new TimeSpan(00, 03, 25); AnyColour.LastFMUrl = string.Empty; AnyColour.LastFMMbid = string.Empty; AnyColour.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(AnyColour); var Brain = new TrackModel(); Brain.Id = "8"; Brain.Number = "8"; Brain.Title = "Brain Damage"; Brain.RawDuration = new TimeSpan(00, 03, 50); Brain.LastFMUrl = string.Empty; Brain.LastFMMbid = string.Empty; Brain.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(Brain); var Eclipse = new TrackModel(); Eclipse.Id = "9"; Eclipse.Number = "9"; Eclipse.Title = "Eclipse"; Eclipse.RawDuration = new TimeSpan(00, 02, 01); Eclipse.LastFMUrl = string.Empty; Eclipse.LastFMMbid = string.Empty; Eclipse.MediaFilePath = @"Assets\SpeakToMe.wma"; darkSideTracks.Add(Eclipse); return darkSideTracks; }
/// <summary> /// Gets the album information from the LastFM album.getInfo service /// </summary> /// <param name="ArtistName">The Artist to search for</param> /// <param name="AlbumName">The Album to search for</param> /// <returns>The Album information as an AlbumModel class.</returns> public async Task<AlbumModel> GetLastFMAlbumInfoAsync(string ArtistName, string AlbumName) { // Call the LastFMService // Check, this will include the returned information for the Artist/Album combination. // It won't necessarily have all the information in it. Search again is the way round // that. var lfmAlbum = await _lastFMService.GetAlbumInfoAsync(AlbumName, ArtistName); // Map the album to the LastFMViewModel var mappedAlbum = new AlbumModel(); //OK to New, UI model only, no injection needed. // Map the album specific data mappedAlbum.Id = string.Empty; // No value for this yet. mappedAlbum.Title = lfmAlbum.name; // Release date DateTime lfmDate = new DateTime(); DateTime.TryParse(lfmAlbum.releasedDate, out lfmDate); mappedAlbum.RawReleased = lfmDate; // mappedAlbum.Released = LocalisationHelper.LocalisedDate(lfmDate); // Artist stuff mappedAlbum.ArtistName = lfmAlbum.artist.name; mappedAlbum.ArtistUrl = lfmAlbum.artist.url; mappedAlbum.ArtistMbid = lfmAlbum.artist.mbid; // Load the large and medium images only. var largeImage = lfmAlbum.images.FirstOrDefault(i => i.size == "large"); if (largeImage != null) mappedAlbum.SetImageLarge(largeImage.imageUrl); else mappedAlbum.SetImageLarge(@"Assets\MediumGray.png"); var mediumImage = lfmAlbum.images.FirstOrDefault(i => i.size == "medium"); if (mediumImage != null) mappedAlbum.SetImageMedium(mediumImage.imageUrl); else mappedAlbum.SetImageMedium(@"Assets\LightGray.png"); // Map the LastFM stuff. mappedAlbum.LastFMUrl = lfmAlbum.url; mappedAlbum.LastFMMbid = lfmAlbum.mbid; // Map the Wiki stuff mappedAlbum.Wiki = new WikiModel(); mappedAlbum.Wiki.Summary = lfmAlbum.wiki.summary; mappedAlbum.Wiki.Content = lfmAlbum.wiki.content; DateTime wikiDate = new DateTime(); DateTime.TryParse(lfmAlbum.wiki.published, out wikiDate); mappedAlbum.Wiki.RawPublished = wikiDate; //mappedAlbum.Wiki.Published = LocalisationHelper.LocalisedDate(wikiDate); // Map the Genres. mappedAlbum.Genres = new List<GenreModel>(); foreach (var g in lfmAlbum.tags) { var mappedGenre = new GenreModel() { Id = string.Empty, Name = g.name, LastFMUrl = g.url }; mappedAlbum.Genres.Add(mappedGenre); } // Map the tracks mappedAlbum.Tracks = new List<TrackModel>(); foreach (var tr in lfmAlbum.tracks) { var mappedTrack = new TrackModel() { Id = string.Empty, Number = tr.rank, Title = tr.name, LastFMMbid = tr.mbid, LastFMUrl = tr.url }; TimeSpan trackDuration = new TimeSpan(); int secs = 0; if (int.TryParse(tr.duration, out secs)) { trackDuration = TimeSpan.FromSeconds(secs); } //mappedTrack.Duration = LocalisationHelper.LocaliseDuration(trackDuration); mappedTrack.RawDuration = trackDuration; mappedAlbum.Tracks.Add(mappedTrack); } return mappedAlbum; }