Beispiel #1
0
 public WMP3FileInfo(WFileInfo source)
 {
     Path = source.Path;
     Filename = source.Filename;
     Bytes = source.Bytes;
     EditDate = source.EditDate;
 }
Beispiel #2
0
        /// <summary>
        /// This method reads the files of a directory and add the informations in a list of WFileInfo-Objectes
        /// </summary>
        /// <param name="path">
        /// The path to start reading
        /// </param>
        /// <param name="recursive">
        /// If this parameter is true, the subdirectories are read, too
        /// </param>
        /// <returns>
        /// A list of WFileInfo-Objectes.The wrappers contains all releveant informations of the files in the directory 
        /// </returns>
        /// 
        private List<WFileInfo> readDirectory(String path, bool? recursive)
        {
            if (String.IsNullOrWhiteSpace(path))
                return new List<WFileInfo>();
            if (!path.EndsWith("\\"))
                path += "\\";
            List<WFileInfo> retValue = new List<WFileInfo>();
            var filenames = Directory.EnumerateFiles(path, "*.mp3").ToArray();
            if (filenames.Length > 0)
            {
                var rangePartitioner = Partitioner.Create(0, filenames.Length);
                Parallel.ForEach(rangePartitioner, (range, loopstate) =>
                {
                    for (int i = range.Item1; i < range.Item2; i++)
                    {
                        string filename = filenames[i];
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Read Directory: " + path + filename);
                        }
                        string normalizedFilename = NormalizeFilename(filename);
                        WFileInfo newElement = new WFileInfo { Path = path, Filename = normalizedFilename };

                        FileInfo fileInfo = new FileInfo(filename);
                        newElement.Bytes = Int64.Parse(fileInfo.Length.ToString());
                        newElement.EditDate = fileInfo.LastWriteTime;
                        lock (fileAddLock)
                        {
                            retValue.Add(newElement);
                        }
                    }
                });
            }
            if (recursive.GetValueOrDefault(false))
            {
                var directories = Directory.EnumerateDirectories(path);
                foreach (var directory in directories)
                {
                    retValue.AddRange(readDirectory(directory, recursive));
                }
            }
            return retValue;

        }
Beispiel #3
0
        /// <summary>
        /// Reads the ID3-Tag Information and merges it with the physical file info
        /// </summary>
        /// <param name="fileInfo">
        /// The physical file info
        /// </param>
        /// <returns>
        /// A wrapper which includes the physical file info and theD3-Tag informations
        /// </returns>
        public WMP3FileInfo readFile(WFileInfo fileInfo)
        {
            if (fileInfo==null)
                throw new ArgumentNullException("fileInfo");
            string fullFilename = fileInfo.Path + fileInfo.Filename;
            TagLib.File file = null;
            try
            {
                file = TagLib.File.Create(new TagLibFileAbstraction(fullFilename));
            }
            catch (TagLib.UnsupportedFormatException)
            {                
                new System.IO.IOException("UNSUPPORTED FILE: " + fullFilename);
            }

            //Fill the return value
            WMP3FileInfo retValue = new WMP3FileInfo(fileInfo);
            foreach(var codec in file.Properties.Codecs)
            {
                TagLib.IAudioCodec acodec = codec as TagLib.IAudioCodec;
                if (acodec != null && (acodec.MediaTypes & TagLib.MediaTypes.Audio) != TagLib.MediaTypes.None)
                {
                    retValue.BitRate = acodec.AudioBitrate;
                    retValue.Songlength = acodec.Duration != null ? convertTime(Convert.ToInt32(acodec.Duration.TotalSeconds)) :  convertTime(0);
                    retValue.DurationInSeconds = acodec.Duration != null ? Convert.ToInt32(acodec.Duration.TotalSeconds) : 0;
                    retValue.Channels = acodec.AudioChannels;
                    retValue.SampleRate = acodec.AudioSampleRate;
                }
            }

            retValue.Genre = (file.Tag.Genres != null && file.Tag.Genres.Length > 0) ? file.Tag.Genres[0] : string.Empty;
            retValue.PublicationYear = (int)file.Tag.Year;
            retValue.Album = NormaliseName(file.Tag.Album);
            retValue.Interpret = NormaliseName(file.Tag.FirstPerformer);
            retValue.Title = file.Tag.Title;
            retValue.Track = (int)file.Tag.Track;
            return retValue;
        }
Beispiel #4
0
        /// <summary>
        /// Diese Methode filtert die Elemente aus, die in die Datenbank nicht vorhanden sind
        /// </summary>
        /// <param name="fileInfos">
        /// Eine Liste von Dateien, die  überprüft werden müssen
        /// </param>
        /// <returns></returns>
        public IEnumerable<WFileInfo> ExtractDatabaseFromList(IEnumerable<WFileInfo> fileInfos)
        {
            List<WFileInfo> returnValues = new List<WFileInfo>();
            if (fileInfos == null)
            {
                log.Warn("ExtractDatabaseFromList: fileInfos == null");
                return returnValues;
            }

            using (var context = new MP3ManagerContext())
            {
                var titles = context.Titles;
                var pathFilename = from title in titles
                                   select new { Filename = title.Filename, Path = title.Path };
                var pathFilenameList = pathFilename.ToList();
                foreach (var fi in fileInfos)
                {
                    log.DebugFormat("ExtractDatabaseFromList: Überprüfe Datei path={0}, filename={1}", fi.Path, fi.Filename);
                    bool doInsert = true;
                    foreach (var listElement in pathFilenameList)
                    {
                        if (listElement.Filename == fi.Filename && listElement.Path == fi.Path)
                        {
                            doInsert = false;
                            break;
                        }
                    }
                    if (doInsert)
                    {
                        log.DebugFormat("ExtractDatabaseFromList: Füge Datei in Datenbank hinzu path={0}, filename={1}", fi.Path, fi.Filename);
                        WFileInfo newInfo = new WFileInfo { Filename = fi.Filename, Path = fi.Path, Bytes = fi.Bytes, EditDate = fi.EditDate };
                        returnValues.Add(newInfo);
                    }
                }
            }
            return returnValues;
        }
Beispiel #5
0
 /// <summary>
 /// This method checks if a file is inserted in the database. The check isn't case-sensitive.
 /// </summary>
 /// <param name="fileInfo">
 /// A searchcriteria to  extract the informations of the file location
 /// </param>
 /// <returns></returns>
 public bool ExistFileInDatabase(WFileInfo fileInfo)
 {
     return ExistFileInDatabase(fileInfo.Path, fileInfo.Filename);
 }