/// <summary>
 /// Aktualisiert den MP3-Tag der Datei
 /// </summary>
 /// <param name="item"></param>
 private void UpdateMP3Tag(WSearchItem item)
 {
     string filename = item.Title.Path + item.Title.Filename;
     if (!File.Exists(filename))
     {
         return;
     }
     MP3FileHandler mp3Handler = new MP3FileHandler();
     mp3Handler.ChangeMP3Tag(filename, modifyInterpret.Text, modifyAlbum.Text, modifyTitle.Text);
 }
Exemple #2
0
        /// <summary>
        /// This  method read the ID3-Tag of the file and insert the values in the database
        /// </summary>
        /// <param name="fileInfo">
        /// The informations of the file
        /// </param>
        public List<WSynchronizeError> InsertFilesInDatabase(IEnumerable<WFileInfo> fileInfos)
        {
            if (fileInfos == null)
            {
                throw new ArgumentException("fileInfo == null");
            }
            if (fileInfos.Count() == 0)
            {
                return new List<WSynchronizeError>();
            }
            List<WSynchronizeError> errors = new List<WSynchronizeError>();
            MP3FileHandler mp3Reader = new MP3FileHandler();
            List<WMP3FileInfo> mp3Infos = new List<WMP3FileInfo>();
            var mp3InfoReadertasks = new Queue<Task>();
            ThreadPool.SetMinThreads(50, 50);
            var fileInfosArray=fileInfos.ToArray();
            var rangeFileInfo=Partitioner.Create(0, fileInfosArray.Length,5);
            ParallelOptions options = new ParallelOptions();
            options.MaxDegreeOfParallelism = -1;
            Parallel.ForEach(rangeFileInfo, (range, loopstate) =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    WFileInfo fileInfoParameter = fileInfosArray[i];
                    try
                    {
                        log.DebugFormat("ReadMP3_Info: path={0}, filename={1}", fileInfoParameter.Path, fileInfoParameter.Filename);
                        WMP3FileInfo newInfo = mp3Reader.readFile(fileInfoParameter);
                        mp3Infos.Add(newInfo);
                    }
                    catch (Exception ex)
                    {
                        errors.Add(new WSynchronizeError() { Path = fileInfoParameter.Path, Filename = fileInfoParameter.Filename, Message = ex.Message });
                    }
                }
            });
            var dbInsertTasks = new Queue<Task>();
            foreach (WMP3FileInfo mp3Info in mp3Infos)
            {
                if (mp3Info == null)
                    continue;

                    Interpret interpretRow = insertInterpret(mp3Info); 
                    Album albumRow = InsertAlbum(mp3Info);
                    InsertTitle(mp3Info, interpretRow, albumRow);
                    FileInserted(this, mp3Info.Title);
            }
            
            return errors;
        }