Exemplo n.º 1
0
        public List <TrackViewModel> ListFilesInDirectory(string SourceDirectory)
        {
            List <TrackViewModel> tvm = new List <TrackViewModel>();

            foreach (string file in Directory.EnumerateFiles(SourceDirectory, "*.*", SearchOption.AllDirectories)
                     .Where(s => s.ToLower().EndsWith(".mp3") ||
                            s.ToLower().EndsWith(".wma") ||
                            s.ToLower().EndsWith(".wav")))
            {
                if (!(file == null))
                {
                    var            _filePath = file;
                    var            _fileName = Path.GetFileNameWithoutExtension(_filePath);
                    var            repoAlbum = new RepositoryAlbum(_uow);
                    TrackViewModel Track     = new TrackViewModel
                    {
                        TrackName = _fileName,
                        AlbumId   = null,
                        ArtistId  = null,
                        TrackURL  = _filePath
                    };

                    tvm.Add(Track);
                }
            }
            return(tvm);
        }
Exemplo n.º 2
0
        private AlbumViewModel AddAlbum(string Album)
        {
            AlbumViewModel ThisAlbum;
            var            repoAlbum = new RepositoryAlbum(_uow);

            ThisAlbum = repoAlbum.GetFilteredAlbums(Album).FirstOrDefault();
            if (ThisAlbum == null)
            {
                ThisAlbum = new AlbumViewModel
                {
                    AlbumName = Album
                };
                repoAlbum.AddAlbum(ThisAlbum);
                ThisAlbum = repoAlbum.GetFilteredAlbums(Album).FirstOrDefault();
            }
            return(ThisAlbum);
        }
Exemplo n.º 3
0
        public void SearchFilesInDirectory(string SourceDirectory)
        {
            foreach (string file in Directory.EnumerateFiles(SourceDirectory, "*.*", SearchOption.AllDirectories)
                     .Where(s => s.ToLower().EndsWith(".mp3") ||
                            s.ToLower().EndsWith(".wma") ||
                            s.ToLower().EndsWith(".wav")))
            {
                if (!(file == null))
                {
                    var _filePath = file;
                    var _fileName = Path.GetFileNameWithoutExtension(_filePath);
                    if (_fileName.Length > 100)
                    {
                        _fileName = string.Concat(_fileName.Remove(96), "...");
                    }

                    var            repoAlbum = new RepositoryAlbum(_uow);
                    TrackViewModel Track     = new TrackViewModel
                    {
                        TrackName = _fileName,
                        AlbumId   = null,
                        ArtistId  = null,
                        TrackURL  = _filePath
                    };

                    if (this.SearchTrackByName(_fileName).Count == 0)
                    {
                        repo.Add(Track.ToData());
                        try
                        {
                            repo.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
        }