private static AlbumModel CreateWishYouWereHere() { var wywh = new AlbumModel(); wywh.Id = "2"; wywh.SetImageLarge(@"Assets\wywhLarge.png"); // String wywh.SetImageMedium(@"Assets\wywhMedium.png"); // String wywh.Title = "Wish You Were Here"; wywh.RawReleased = new DateTime(1975, 9, 12); wywh.LastFMUrl = string.Empty; wywh.LastFMMbid = string.Empty; wywh.ArtistName = "Pink floyd"; wywh.ArtistMbid = string.Empty; wywh.ArtistUrl = string.Empty; wywh.Wiki = new WikiModel(); wywh.Tracks = new List<TrackModel>(); wywh.Genres = new List<GenreModel>(); return wywh; }
/// <summary> /// Create the mock data /// </summary> /// <returns>the mock data</returns> private static AlbumModel CreateDarkSideOfTheMoon() { var DarkSideOfTheMoon = new AlbumModel(); DarkSideOfTheMoon.Id = "1"; DarkSideOfTheMoon.SetImageLarge(@"Assets\DarkSideOfTheMoonLarge.png"); // String DarkSideOfTheMoon.SetImageMedium(@"Assets\DarkSideOfTheMoonMedium.png"); // String DarkSideOfTheMoon.Title = "DarkSide of the Moon"; DarkSideOfTheMoon.RawReleased = new DateTime(1973, 3, 1); DarkSideOfTheMoon.LastFMUrl = string.Empty; DarkSideOfTheMoon.LastFMMbid = string.Empty; DarkSideOfTheMoon.ArtistName = "Pink floyd"; DarkSideOfTheMoon.ArtistMbid = string.Empty; DarkSideOfTheMoon.ArtistUrl = string.Empty; DarkSideOfTheMoon.Wiki = CreateDarkSideOfTheMoonWiki(); DarkSideOfTheMoon.Tracks = CreateDarkSideOfTheMoonTracks(); DarkSideOfTheMoon.Genres = CreateDarkSideOfTheMoonGenres(); return DarkSideOfTheMoon; }
/// <summary> /// Not implemented as not required /// </summary> /// <param name="lastFMAlbum">the album</param> /// <returns>a string</returns> public async Task<string> ImportAlbumAsync(AlbumModel lastFMAlbum) { throw new NotImplementedException(); }
/// <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; }
// *************************** Supporting methods *************************** // *************************** Supporting methods *************************** // *************************** Supporting methods *************************** /// <summary> /// Private method that initiates loading the data context on startup. /// This is done asynchronously. /// </summary> /// <param name="Id">The Id of the Group.</param> /// <param name="groupType">The Type of the Group (Artist, Genre or Playlist)</param> /// <remarks> /// This call is separated to a private method so the call can be 'await'ed. To call /// this from the mainViewModel constructor would require it to be decorated as /// 'async' which is not possible. /// </remarks> private async void LoadViewModelAsync(int Id, GroupTypeEnum groupType) { // Load the albums this.Albums = await _dataService.LoadAlbumsAsync(Id, groupType); // this.Albums = await Helpers.AlbumModelHelper.LoadAlbumsAsync(Id, groupType, _albumRepository); this.CurrentAlbum = Albums[0]; // Load the Group Name this.GroupName = await _dataService.LoadGroupNameAsync(Id, groupType); // this.GroupName = await Helpers.AlbumModelHelper.LoadGroupNameAsync(Id, groupType, _artistRepository); }
private async Task LoadDesignData() { this.LastFMAlbum = await _dataService.GetLastFMAlbumInfoAsync("Pink Floyd", "Dark side of the Moon"); }
// *************************** Supporting methods *************************** // *************************** Supporting methods *************************** // *************************** Supporting methods *************************** /// <summary> /// Private method that initiates loading the data context on startup. /// This is done asynchronously. /// </summary> /// <param name="Id">The Id of the Group.</param> /// <param name="groupType">The Type of the Group (Artist, Genre or Playlist)</param> /// <remarks> /// This call is separated to a private method so the call can be 'await'ed. To call /// this from the mainViewModel constructor would require it to be decorated as /// 'async' which is not possible. There are also issues with doint this that deal /// with the possibility of causing deadlocks. /// </remarks> private async Task GetLastFMAlbumAsync(string album, string artist) { // Load the album this.LastFMAlbum = await _dataService.GetLastFMAlbumInfoAsync(artist, album); }
/// <summary> /// Maps the LastFMAlbum (AlbumModel> class to the Domain album class /// </summary> /// <param name="lastFMAlbum">The AlbumModel to be mapped</param> /// <returns>The mapped Doamin Album</returns> private Album MapAlbumModelToAlbum(AlbumModel lastFMAlbum) { var newAlbum = _albumFactory.Create(); // Copy the Album specific stuff newAlbum.Id = 0; newAlbum.Title = lastFMAlbum.Title; newAlbum.Released = lastFMAlbum.RawReleased; newAlbum.Mbid = lastFMAlbum.LastFMMbid; newAlbum.Url = lastFMAlbum.LastFMUrl; // Copy the Images newAlbum.Images = new List<Image>(); Image mediumImage = _imageFactory.Create(); mediumImage.Size = ImageSizeEnum.medium; mediumImage.Url = lastFMAlbum.ImagePathMedium; newAlbum.Images.Add(mediumImage); Image largeImage = _imageFactory.Create(); largeImage.Size = ImageSizeEnum.large; largeImage.Url = lastFMAlbum.ImagePathLarge; newAlbum.Images.Add(largeImage); // Copy the Artist newAlbum.Artist = _artistFactory.Create(); newAlbum.Artist.Name = lastFMAlbum.ArtistName; newAlbum.Artist.Mbid = lastFMAlbum.ArtistMbid; newAlbum.Artist.Url = lastFMAlbum.ArtistUrl; // Copy the Tracks newAlbum.Tracks = new List<Track>(); foreach (var tr in lastFMAlbum.Tracks) { Track newtrack = _trackFactory.Create(); newtrack.Title = tr.Title; int no; if (int.TryParse(tr.Number, out no)) newtrack.Number = no; newtrack.Mbid = tr.LastFMMbid; newtrack.Url = tr.LastFMUrl; newtrack.Duration = tr.RawDuration; newtrack.Artist = newAlbum.Artist; newtrack.Playlists = new List<PlayList>(); newAlbum.Tracks.Add(newtrack); } // Copy the Genres newAlbum.Genres = new List<Genre>(); foreach (var genre in lastFMAlbum.Genres) { Genre newGenre = _genreFactory.Create(); newGenre.Name = genre.Name; newGenre.Url = genre.LastFMUrl; newAlbum.Genres.Add(newGenre); } // Copy the Wiki's newAlbum.Wiki = _wikiFactory.Create(); newAlbum.Wiki.Summary = lastFMAlbum.Wiki.Summary; newAlbum.Wiki.Content = lastFMAlbum.Wiki.Content; newAlbum.Wiki.Published = lastFMAlbum.Wiki.RawPublished; return newAlbum; }
/// <summary> /// Adds the Album to the Domain Model. /// </summary> /// <param name="lastFMAlbum">The album to be added</param> /// <returns>A success or failure indicator</returns> public async Task<string> ImportAlbumAsync(AlbumModel lastFMAlbum) { // Check if album exists already. var albumExists = await _albumRepository.IsAlbumAlreadyImported(lastFMAlbum.ArtistName, lastFMAlbum.Title); if (albumExists != null) { return "Album already exists"; } else { // Map the AlbumModel (UI layer) to the Album (domain). var newAlbum = MapAlbumModelToAlbum(lastFMAlbum); // Call the repository to Create the new album in the domain. var returnedAlbum = await _albumRepository.CreateAsync(newAlbum); return (returnedAlbum != null) ? "AlbumImportedOK" : "AlbumImportFailed"; } }
/// <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; }