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(); } } }