// Fill the control with data private void PopulateControls(ECommerce.CdShop.Entity.Product pd) { // Display product recommendations string productId = pd.Id.ToString(); recommendations.LoadProductRecommendations(productId); // Display product details titleLabel.Text = pd.Name; descriptionLabel.Text = pd.Description; priceLabel.Text = String.Format("{0:c}", pd.Price); productImage.ImageUrl = "ProductImages/" + pd.Image; // Set the title of the page this.Title = CdShopConfiguration.SiteName + pd.Name; // obtain the attributes of the product DataTable attrTable = CatalogAccess.GetProductAttributes(pd.Id.ToString()); // temp variables string prevAttributeName = ""; string attributeName, attributeValue, attributeValueId; // current DropDown for attribute values Label attributeNameLabel; DropDownList attributeValuesDropDown = new DropDownList(); // read the list of attributes foreach (DataRow r in attrTable.Rows) { // get attribute data attributeName = r["AttributeName"].ToString(); attributeValue = r["AttributeValue"].ToString(); attributeValueId = r["AttributeValueID"].ToString(); // if starting a new attribute (e.g. Color, Size) if (attributeName != prevAttributeName) { prevAttributeName = attributeName; attributeNameLabel = new Label(); attributeNameLabel.Text = attributeName + ": "; attributeValuesDropDown = new DropDownList(); attrPlaceHolder.Controls.Add(attributeNameLabel); attrPlaceHolder.Controls.Add(attributeValuesDropDown); } // add a new attribute value to the DropDownList attributeValuesDropDown.Items.Add(new ListItem(attributeValue, attributeValueId)); } SongDao songDao = new SongDao(); int productIdAsInt = int.Parse(productId); grid.DataSource = songDao.GetAllByProductId(productIdAsInt); grid.DataBind(); }
public void SelectSongsByAlbumTest() { SongDao dal = new SongDao(); string[] expected1 = { "bohemio de aficion", "entre el amor y yo", "me voy a quitar de en medio" }; string[] expected2 = { "cenizas", "payaso" }; Response <IEnumerable <SongDto> > actual1 = dal.SelectSongsByAlbum(1); Response <IEnumerable <SongDto> > actual2 = dal.SelectSongsByAlbum(4); Assert.AreEqual(true, actual1.Status); Assert.AreEqual(true, actual2.Status); Assert.AreEqual(expected1[0], actual1.Data.ElementAt(0).Title); Assert.AreEqual(expected1[1], actual1.Data.ElementAt(1).Title); Assert.AreEqual(expected1[2], actual1.Data.ElementAt(2).Title); Assert.AreEqual(expected2[0], actual2.Data.ElementAt(0).Title); Assert.AreEqual(expected2[1], actual2.Data.ElementAt(1).Title); }
public bool SongExists(Song song) { return(SongDao.SongExists(song)); }
public bool UpdateSong(Song song) { return(SongDao.UpdateSong(song)); }
public List <Song> GetFavoriteSongs() { return(SongDao.GetFavoriteSongs()); }
public bool SetFavoriteState(Song song, bool state) { return(SongDao.SetSongFavoriteState(song, state)); }
public List <Song> GetSongsByArtist(Artist artist) { return(SongDao.GetSongsByArtist(artist)); }
public List <Song> GetSongsByAlbum(Album album) { return(SongDao.GetSongsByAlbum(album)); }
public List <Song> GetSongsByPath(string uri) { return(SongDao.GetSongsByPath(uri)); }
public Song GetSong(Song song) { return(SongDao.GetSong(song)); }
public List <string> GetAllSongsPaths() { return(SongDao.GetAllSongsPaths()); }
public List <Song> GetSongs(bool sort) { return(SongDao.GetSongs(sort)); }
public void AddSong(Song song) { SongDao.AddSong(song); }
public bool RemoveSong(Song song) { return(SongDao.RemoveSong(song)); }
/// <summary> /// Searches for differences between the database and the music collection. Then, if needed, it adds or removes the songs that doesn't exist on both lists /// </summary> public static async void LoadCollectionChanges() { if (LoadCollectionCompleted == false) { return; } Debug.WriteLine("INICIANDO BUSCA"); LoadCollectionCompleted = false; bool changed = false; if (ApplicationSettings.IsCollectionLoaded) { List <Song> currentSongs = SongDao.GetSongs(false); List <string> folderSongs = new List <string>(); if (currentSongs != null) { List <Song> listOfSongs = currentSongs; Song aux = null; StorageFolder coversFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Covers", CreationCollisionOption.OpenIfExists); var songs = await StorageHelper.ScanFolder(KnownFolders.MusicLibrary); int totalCount = songs.Count; try { foreach (StorageFile file in songs) { if (Stop) { Stop = false; break; } folderSongs.Add(file.Path); } } catch { } try { // Searches for new songs in the music library foreach (StorageFile file in songs) { if (Stop) { Stop = false; break; } if (currentSongs.Any(s => s.SongURI == file.Path) == false) { if (Stop) { Stop = false; break; } aux = await CreateSongObjectByFile(file, listOfSongs); changed = true; listOfSongs.Add(aux); } } } catch { } try { // Removes any registry for a song that doesn't exist anymore in music library foreach (Song song in currentSongs) { if (Stop) { Stop = false; break; } if (folderSongs.Contains(song.SongURI) == false) { SongDao.RemoveSong(song); changed = true; } } } catch { } } } Debug.WriteLine("BUSCA CONCLUÍDA"); LoadCollectionCompleted = true; }
private static async Task <Song> CreateSongObjectByFile(StorageFile file, List <Song> listOfSongs) { Song song = null; Stream fileStream = null; TagLib.File tagFile = null; string title = ""; string artist = ""; string album = ""; string genre = ""; string trackNumber = ""; string year = ""; try { if (Stop) { Stop = false; return(new Song()); } fileStream = await file.OpenStreamForReadAsync(); tagFile = TagLib.File.Create(new StreamFileAbstraction(file.Name, fileStream, fileStream)); if (tagFile.Tag.Album != null || string.IsNullOrWhiteSpace(tagFile.Tag.Album) == false) { album = tagFile.Tag.Album; } else { album = "Unknown"; } if (tagFile.Tag.Title == null || string.IsNullOrWhiteSpace(tagFile.Tag.Title)) { title = file.DisplayName; } else { title = tagFile.Tag.Title; } if (tagFile.Tag.FirstAlbumArtist != null && string.IsNullOrWhiteSpace(tagFile.Tag.FirstAlbumArtist) == false) { artist = tagFile.Tag.FirstAlbumArtist; } else if (tagFile.Tag.FirstPerformer != null && string.IsNullOrWhiteSpace(tagFile.Tag.FirstPerformer) == false) { artist = tagFile.Tag.FirstPerformer; } else { artist = "Unknown"; } trackNumber = Convert.ToString(tagFile.Tag.Track); year = Convert.ToString(tagFile.Tag.Year); if (tagFile.Tag.FirstGenre != null && string.IsNullOrWhiteSpace(tagFile.Tag.FirstGenre) == false) { genre = tagFile.Tag.FirstGenre; } else { genre = string.Empty; } var matchingResults = listOfSongs.Where(s => s.Artist == artist && s.Album == album).ToList(); string albumid; string hexColor = string.Empty; if (matchingResults.Count() > 0) { albumid = matchingResults[0].AlbumID; hexColor = matchingResults[0].HexColor; } else { albumid = Guid.NewGuid().ToString(); if (tagFile.Tag.Pictures.Length > 0) { var dataVector = tagFile.Tag.Pictures[0].Data.Data; SaveCoverImageResult imageResult = await ImageHelper.SaveAlbumCover(dataVector, albumid); hexColor = imageResult.HexColor; //ImageHelper.BlurAlbumCover(albumid); } } fileStream.Dispose(); string songid = Guid.NewGuid().ToString(); song = new Song() { Title = title, Artist = artist, Album = album, AlbumID = albumid, ID = songid, Year = year, Track = trackNumber, Genre = genre, SongURI = file.Path, HexColor = hexColor }; SongDao.AddSong(song); } catch { } return(song); }