コード例 #1
0
 static internal MetadataDto Read(string filePath)
 {
     lock (_lock)
     {
         var file = new FileInfo(filePath);
         if (file.Exists)
         {
             var result = new MetadataDto(filePath);
             using (var stream = file.OpenRead())
             {
                 var document = new XmlDocument();
                 document.Load(stream);
                 foreach (XmlNode node in document.SelectSingleNode("/AudioMetadata/SourceFile/IDTags").ChildNodes)
                 {
                     var name = node.Attributes["name"].Value;
                     if (Map.ContainsKey(name))
                     {
                         Map[name].Invoke(result, node.InnerText);
                     }
                 }
             }
             return(result);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #2
0
        static internal void Write(MetadataDto dto)
        {
            lock (_lock)
            {
                using (var stream = new FileStream(dto.Id, FileMode.Create, FileAccess.Write, FileShare.None))
                    using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
                    {
                        writer.Formatting  = Formatting.Indented;
                        writer.Indentation = 1;
                        writer.IndentChar  = '\t';

                        writer.WriteStartDocument();
                        writer.WriteStartElement("AudioMetadata");
                        writer.WriteStartElement("SourceFile");
                        writer.WriteStartElement("IDTags");

                        writer.WriteMandatoryElement(dto.Artist, ARTIST);
                        writer.WriteMandatoryElement(dto.Title, TITLE);
                        writer.WriteMandatoryElement(dto.Album, ALBUM);
                        writer.WriteMandatoryElement(dto.Track, TRACK);
                        writer.WriteMandatoryElement(dto.Year, YEAR);
                        writer.WriteMandatoryElement(dto.Genre, GENRE);

                        writer.WriteOptionalElement(dto.AccurateRipDiscId, ACCURATERIPDISCID);
                        writer.WriteOptionalElement(dto.AlbumArtist, ALBUM_ARTIST);
                        writer.WriteOptionalElement(dto.Compilation.HasValue && dto.Compilation.Value == 0 ? null : dto.Compilation, COMPILATION);
                        writer.WriteOptionalElement(dto.Disc, DISC);

                        writer.WriteEndDocument();
                    }
            }
        }
コード例 #3
0
        internal static void Write(MetadataDto dto)
        {
            lock (_lock)
            {
                using (var stream = new FileStream(dto.Id, FileMode.Create, FileAccess.Write, FileShare.None))
                using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.Indentation = 1;
                    writer.IndentChar = '\t';

                    writer.WriteStartDocument();
                    writer.WriteStartElement("AudioMetadata");
                    writer.WriteStartElement("SourceFile");
                    writer.WriteStartElement("IDTags");

                    writer.WriteMandatoryElement(dto.Artist, ARTIST);
                    writer.WriteMandatoryElement(dto.Title, TITLE);
                    writer.WriteMandatoryElement(dto.Album, ALBUM);
                    writer.WriteMandatoryElement(dto.Track, TRACK);
                    writer.WriteMandatoryElement(dto.Year, YEAR);
                    writer.WriteMandatoryElement(dto.Genre, GENRE);

                    writer.WriteOptionalElement(dto.AccurateRipDiscId, ACCURATERIPDISCID);
                    writer.WriteOptionalElement(dto.AlbumArtist, ALBUM_ARTIST);
                    writer.WriteOptionalElement(dto.Compilation.HasValue && dto.Compilation.Value == 0 ? null : dto.Compilation, COMPILATION);
                    writer.WriteOptionalElement(dto.Disc, DISC);

                    writer.WriteEndDocument();
                }
            }
        }
コード例 #4
0
 internal static MetadataDto Read(string filePath)
 {
     lock (_lock)
     {
         var file = new FileInfo(filePath);
         if (file.Exists)
         {
             var result = new MetadataDto(filePath);
             using (var stream = file.OpenRead())
             {
                 var document = new XmlDocument();
                 document.Load(stream);
                 foreach (XmlNode node in document.SelectSingleNode("/AudioMetadata/SourceFile/IDTags").ChildNodes)
                 {
                     var name = node.Attributes["name"].Value;
                     if (Map.ContainsKey(name))
                     {
                         Map[name].Invoke(result, node.InnerText);
                     }
                 }
             }
             return result;
         }
         else
         {
             return null;
         }
     }
 }
コード例 #5
0
 internal static IEnumerable<MetadataDto> MaterializeFor(IEnumerable<string> filePaths)
 {
     filePaths = filePaths.ToList();
     if (filePaths.Any())
     {
         var tracksPerDisc = ParseTracksPerDisc(filePaths).ToList();
         var discCount = tracksPerDisc.Max(x => x.Item1);
         foreach (var filePath in filePaths)
         {
             MetadataDto dto= null;
             try
             {
                 dto = MetadataStore.Read(filePath);
             }
             catch
             {
             }
             if (dto == null)
             {
                 var discAndTrack = ParseDiscAndTrack(filePath);
                 dto = new MetadataDto(filePath)
                 {
                     Track = String.Format("{0}/{1}", discAndTrack.Item2, tracksPerDisc.Single(x => x.Item1 == discAndTrack.Item1).Item2),
                     Disc = String.Format("{0}/{1}", discAndTrack.Item1, discCount),
                 };
             }
             IdentityMap.Put(dto);
             yield return dto;
         }
     }
 }
コード例 #6
0
 static internal IEnumerable <MetadataDto> MaterializeFor(IEnumerable <string> filePaths)
 {
     filePaths = filePaths.ToList();
     if (filePaths.Any())
     {
         var tracksPerDisc = ParseTracksPerDisc(filePaths).ToList();
         var discCount     = tracksPerDisc.Max(x => x.Item1);
         foreach (var filePath in filePaths)
         {
             MetadataDto dto = null;
             try
             {
                 dto = MetadataStore.Read(filePath);
             }
             catch
             {
             }
             if (dto == null)
             {
                 var discAndTrack = ParseDiscAndTrack(filePath);
                 dto = new MetadataDto(filePath)
                 {
                     Track = String.Format("{0}/{1}", discAndTrack.Item2, tracksPerDisc.Single(x => x.Item1 == discAndTrack.Item1).Item2),
                     Disc  = String.Format("{0}/{1}", discAndTrack.Item1, discCount),
                 };
             }
             IdentityMap.Put(dto);
             yield return(dto);
         }
     }
 }
コード例 #7
0
 static public void Save(MetadataDto dto)
 {
     MetadataStore.Write(dto);
 }
コード例 #8
0
 public static void Put(MetadataDto dto)
 {
     _metadataDtoMap[dto.Id] = dto;
 }
コード例 #9
0
 public static void Put(MetadataDto dto)
 {
     _metadataDtoMap[dto.Id] = dto;
 }