Example #1
1
        /// <summary>
        /// Metodo encargado de buscarcanciones en una carpeta para su importaci'on en la biblioteca de usuario
        /// </summary>
        /// <param name="directoryPath">Ruta de acceso a directorio</param>
        public void ImportSongsToLibrary(String directoryPath)
        {
            List<TrackInfo> tracksToInsert = new List<TrackInfo>();
            SessionManager sessionManager= SessionManager.Instance;
            string unknownFrame = "Unknown";
            string[] musicFiles = Directory.GetFiles(directoryPath, "*.mp3");
            foreach (string musicFile in musicFiles)
            {
                UserTrackRepository userTrackRepository = new UserTrackRepository();
                TrackRepository trackRepository = new TrackRepository();

                using (var mp3 = new Mp3File(musicFile))
                {
                    TrackInfo currentTrack = new TrackInfo() {TrackId = Guid.NewGuid()};

                    if (mp3.HasTags)
                    {
                        Id3Tag tag = mp3.GetTag(Id3TagFamily.FileStartTag);
                        if (tag != null)
                        {
                            currentTrack.Title = tag.Title.IsAssigned ? tag.Title.Value : unknownFrame;
                            currentTrack.AlbumTitle = tag.Album.IsAssigned ? tag.Album.Value : unknownFrame;
                            currentTrack.ArtistTitle = tag.Artists.IsAssigned ? tag.Artists : unknownFrame;
                            currentTrack.Genre = getGenre(tag.Genre.Value);
                            if (tag.Lyrics.Count != 0)
                            {
                                currentTrack.Lyric = tag.Lyrics[0].IsAssigned ? tag.Lyrics[0].Lyrics : "";
                            }
                            else
                            {
                                currentTrack.Lyric = "";
                            }
                            if (tag.Year.IsAssigned)
                            {
                                int year;
                                if (Int32.TryParse(tag.Year.Value, out year))
                                {
                                    currentTrack.Year = year;
                                }
                            }
                        }
                        else
                        {
                            currentTrack.Title = unknownFrame;
                            currentTrack.AlbumTitle =unknownFrame;
                            currentTrack.ArtistTitle = unknownFrame;
                            currentTrack.Genre = unknownFrame;
                            currentTrack.Lyric = "";
                            currentTrack.Year = 0;
                        }
                                     
                        currentTrack.SongPath = musicFile;
                        currentTrack.TrackId = Guid.NewGuid();
                        tracksToInsert.Add(currentTrack);
                    }
                    else
                    {
                        currentTrack.Title =unknownFrame;
                        currentTrack.AlbumTitle = unknownFrame;
                        currentTrack.ArtistTitle =unknownFrame;
                        currentTrack.Genre = unknownFrame;
                        currentTrack.Lyric = "";
                        currentTrack.SongPath = musicFile;
                        currentTrack.TrackId= Guid.NewGuid();
                        currentTrack.Year = 0;
                        tracksToInsert.Add(currentTrack);
                    }
                }
            }
            this.userTracks.AddRange(tracksToInsert);
            this.InsertIntoDatabase(tracksToInsert);
        }
Example #2
0
        /// <summary>
        /// Metodo encargado de inicializar la biblioteca, carga los datos de las canciones desde la base de datos
        /// </summary>
        public void InitializeLibrary()
        {
            FileManager fileManager =new FileManager();
            fileManager.CreateUserDirectory();
            SessionManager sessionManager = SessionManager.Instance;
            TrackRepository trackRepo = new TrackRepository();
            UserTrackRepository userTrackRepo =new UserTrackRepository();
            List<Track> userStoredTracks= trackRepo.GetTraksByUserId(sessionManager.UserId);
            foreach (var userTrack in userStoredTracks)
            {
                TrackInfo trackInfo =new TrackInfo() {Title = userTrack.Title,TrackId = userTrack.TrackID,AlbumTitle = userTrack.Album.Title,
                                                      ArtistTitle = userTrack.Album.Artist.Title,SongPath = userTrack.Path,Year = userTrack.Album.ReleaseYear,
                                                      Lyric = userTrack.Lyrics,Genre = userTrack.Genre};
                trackInfo.isSynced = userTrackRepo.GetUserTrackByPK(sessionManager.UserId,trackInfo.TrackId).IsSync;
                this.userTracks.Add(trackInfo);
            }
            trackRepo.Dispose();
            userTrackRepo.Dispose();

        }