Пример #1
0
        public static async Task Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
        {
            var embedded = source.EmbeddedImages.Value;
            var loose    = source.LooseImages.Value;

            if (embedded && loose)
            {
                switch (MetaDataBehaviourConfiguration.GetImagesPreference(source.ImagesPreference.Value))
                {
                default:
                case ImagePreference.Embedded:
                    await WriteEmbedded(source, metaDataItem, file).ConfigureAwait(false);

                    break;

                case ImagePreference.Loose:
                    WriteLoose(source, metaDataItem, file);
                    break;
                }
            }
            else if (embedded)
            {
                await WriteEmbedded(source, metaDataItem, file).ConfigureAwait(false);
            }
            else if (loose)
            {
                WriteLoose(source, metaDataItem, file);
            }
        }
Пример #2
0
        private static void ReplaceImage(MetaDataItem metaDataItem, string fileName)
        {
            var type = GetArtworkType(metaDataItem.Name);

            global::System.IO.File.Copy(metaDataItem.Value, fileName, true);
            ArtworkProvider.Reset(fileName, type);
        }
Пример #3
0
 public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
 {
     if (file.TagTypes.HasFlag(TagTypes.Id3v2))
     {
         var tag    = GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
         var frames = tag.GetFrames <global::TagLib.Id3v2.PopularimeterFrame>();
         if (frames != null && frames.Any())
         {
             foreach (var frame in frames)
             {
                 WritePopularimeterFrame(source, metaDataItem, file, frame);
             }
         }
         else
         {
             var frame = new global::TagLib.Id3v2.PopularimeterFrame(string.Empty);
             WritePopularimeterFrame(source, metaDataItem, file, frame);
             tag.AddFrame(frame);
         }
     }
     else
     {
         WriteCustomTag(metaDataItem.Name, metaDataItem.Value, file);
     }
 }
Пример #4
0
 public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
 {
     if (file.TagTypes.HasFlag(TagTypes.Id3v2) && (new[] { CommonStatistics.Rating, CommonStatistics.PlayCount }).Contains(metaDataItem.Name, StringComparer.OrdinalIgnoreCase))
     {
         var tag    = TagManager.GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
         var frames = tag.GetFrames <global::TagLib.Id3v2.PopularimeterFrame>();
         if (frames != null && frames.Any())
         {
             foreach (var frame in frames)
             {
                 WritePopularimeterFrame(frame, metaDataItem);
             }
         }
         else
         {
             var frame = new global::TagLib.Id3v2.PopularimeterFrame(string.Empty);
             WritePopularimeterFrame(frame, metaDataItem);
             tag.AddFrame(frame);
         }
     }
     else if (string.Equals(metaDataItem.Name, CommonStatistics.Rating, StringComparison.OrdinalIgnoreCase))
     {
         TagManager.WriteCustomTag(metaDataItem.Name, Convert.ToString(GetRatingMask(metaDataItem.Value)), file);
     }
     else
     {
         TagManager.WriteCustomTag(metaDataItem.Name, metaDataItem.Value, file);
     }
 }
        protected override async Task OnRun()
        {
            var position = 0;

            using (var task = new SingletonReentrantTask(this, ComponentSlots.Database, SingletonReentrantTask.PRIORITY_LOW, async cancellationToken =>
            {
                var metaDataSource = this.MetaDataSourceFactory.Create();
                foreach (var libraryItem in this.LibraryItems)
                {
                    this.Description = Path.GetFileName(libraryItem.FileName);
                    this.Position = position;

                    if (!File.Exists(libraryItem.FileName))
                    {
                        Logger.Write(this, LogLevel.Debug, "File \"{0}\" no longer exists: Cannot refresh.", libraryItem.FileName);
                        continue;
                    }

                    var metaDatas = await metaDataSource.GetMetaData(libraryItem.FileName).ConfigureAwait(false);
                    MetaDataItem.Update(metaDatas, libraryItem.MetaDatas, null);

                    await this.WriteLibraryMetaData(libraryItem).ConfigureAwait(false);

                    libraryItem.Status = LibraryItemStatus.Import;
                    await LibraryTaskBase.UpdateLibraryItem(this.Database, libraryItem).ConfigureAwait(false);

                    position++;
                }
            }))
            {
                await task.Run().ConfigureAwait(false);
            }
        }
Пример #6
0
        public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
        {
            var tag   = file.Tag;
            var value = default(double);

            if (string.IsNullOrEmpty(metaDataItem.Value))
            {
                value = double.NaN;
            }
            else if (!double.TryParse(metaDataItem.Value, out value))
            {
                value = double.NaN;
            }
            if (string.Equals(metaDataItem.Name, CommonMetaData.ReplayGainAlbumGain, StringComparison.OrdinalIgnoreCase))
            {
                tag.ReplayGainAlbumGain = value;
            }
            else if (string.Equals(metaDataItem.Name, CommonMetaData.ReplayGainAlbumPeak, StringComparison.OrdinalIgnoreCase))
            {
                tag.ReplayGainAlbumPeak = value;
            }
            else if (string.Equals(metaDataItem.Name, CommonMetaData.ReplayGainTrackGain, StringComparison.OrdinalIgnoreCase))
            {
                tag.ReplayGainTrackGain = value;
            }
            else if (string.Equals(metaDataItem.Name, CommonMetaData.ReplayGainTrackPeak, StringComparison.OrdinalIgnoreCase))
            {
                tag.ReplayGainTrackPeak = value;
            }
        }
Пример #7
0
        private static void RemoveImage(MetaDataItem metaDataItem, string fileName)
        {
            var type = GetArtworkType(metaDataItem.Name);

            global::System.IO.File.Delete(fileName);
            ArtworkProvider.Reset(fileName, type);
        }
Пример #8
0
        public async Task Lookup(LyricsProvider provider, PlaylistItem playlistItem)
        {
            Logger.Write(this, LogLevel.Debug, "Looking up lyrics for file \"{0}\"..", playlistItem.FileName);
            var result = await provider.Lookup(playlistItem).ConfigureAwait(false);

            if (!result.Success)
            {
                Logger.Write(this, LogLevel.Warn, "Failed to look up lyrics for file \"{0}\".", playlistItem.FileName);
                return;
            }
            Logger.Write(this, LogLevel.Debug, "Looking up lyrics for file \"{0}\": OK, updating meta data.", playlistItem.FileName);
            lock (playlistItem.MetaDatas)
            {
                var metaDataItem = playlistItem.MetaDatas.FirstOrDefault(
                    element => string.Equals(element.Name, CommonMetaData.Lyrics, StringComparison.OrdinalIgnoreCase)
                    );
                if (metaDataItem == null)
                {
                    metaDataItem = new MetaDataItem(CommonMetaData.Lyrics, MetaDataItemType.Tag);
                    lock (playlistItem.MetaDatas)
                    {
                        playlistItem.MetaDatas.Add(metaDataItem);
                    }
                }
                metaDataItem.Value = result.Lyrics;
            }
            await this.MetaDataManager.Save(
                new[] { playlistItem },
                true,
                false,
                CommonMetaData.Lyrics
                ).ConfigureAwait(false);
        }
Пример #9
0
        private void SetTag(MetaDataItem metaDataItem, File file, Tag tag)
        {
            switch (metaDataItem.Name)
            {
            case CommonMetaData.Album:
                tag.Album = metaDataItem.Value;
                break;

            case CommonMetaData.Artist:
                tag.AlbumArtists = new[] { metaDataItem.Value };
                break;

            case CommonMetaData.Composer:
                tag.Composers = new[] { metaDataItem.Value };
                break;

            case CommonMetaData.Conductor:
                tag.Conductor = metaDataItem.Value;
                break;

            case CommonMetaData.Disc:
                tag.Disc = Convert.ToUInt32(metaDataItem.Value);
                break;

            case CommonMetaData.DiscCount:
                tag.DiscCount = Convert.ToUInt32(metaDataItem.Value);
                break;

            case CommonMetaData.Genre:
                tag.Genres = new[] { metaDataItem.Value };
                break;

            case CommonMetaData.Performer:
                tag.Performers = new[] { metaDataItem.Value };
                break;

            case CommonMetaData.PlayCount:
            case CommonMetaData.Rating:
                PopularimeterManager.Write(this, metaDataItem, file);
                break;

            case CommonMetaData.Title:
                tag.Title = metaDataItem.Value;
                break;

            case CommonMetaData.Track:
                tag.Track = Convert.ToUInt32(metaDataItem.Value);
                break;

            case CommonMetaData.TrackCount:
                tag.TrackCount = Convert.ToUInt32(metaDataItem.Value);
                break;

            case CommonMetaData.Year:
                tag.Year = Convert.ToUInt32(metaDataItem.Value);
                break;
            }
        }
Пример #10
0
 public static MetaDataItem Clone(MetaDataItem metaDataItem)
 {
     return(new MetaDataItem()
     {
         Name = metaDataItem.Name,
         Type = metaDataItem.Type,
         Value = metaDataItem.Value
     });
 }
Пример #11
0
 private async Task AddImage(MetaDataItem metaDataItem, Tag tag, IList <IPicture> pictures)
 {
     /* Unmerged change from project 'FoxTunes.MetaData.TagLib(net461)'
      * Before:
      *          pictures.Add(await this.CreateImage(metaDataItem, tag));
      * After:
      *          pictures.Add(await this.CreateImage(metaDataItem, tag).ConfigureAwait(false));
      */
     pictures.Add(await this.CreateImage(metaDataItem, tag).ConfigureAwait(false));
 }
Пример #12
0
        private static void AddImage(MetaDataItem metaDataItem, File file)
        {
            var type = GetArtworkType(metaDataItem.Name);
            //TODO: Assuming that the file name has the correct extension and not .bin
            var extension = global::System.IO.Path.GetExtension(metaDataItem.Value);
            var fileName  = ArtworkProvider.GetFileName(file.Name, extension, type);

            global::System.IO.File.Copy(metaDataItem.Value, fileName, true);
            ArtworkProvider.Reset(file.Name, type);
        }
Пример #13
0
        public async Task Edit()
        {
            var outputStream = this.PlaybackManager.CurrentStream;

            if (outputStream == null)
            {
                return;
            }
            var playlistItem = outputStream.PlaylistItem;
            var metaDataItem = default(MetaDataItem);

            lock (playlistItem.MetaDatas)
            {
                metaDataItem = playlistItem.MetaDatas.FirstOrDefault(
                    element => string.Equals(element.Name, CommonMetaData.Lyrics, StringComparison.OrdinalIgnoreCase)
                    );
            }
            var fileName = Path.GetTempFileName();

            Logger.Write(this, LogLevel.Debug, "Editing lyrics for file \"{0}\": \"{1}\"", playlistItem.FileName, fileName);
            if (metaDataItem != null)
            {
                File.WriteAllText(fileName, metaDataItem.Value);
            }
            else
            {
                File.WriteAllText(fileName, string.Empty);
            }
            var args = string.Format("\"{0}\"", fileName);

            Logger.Write(this, LogLevel.Debug, "Using editor: \"{0}\"", this.Editor.Value);
            var process = Process.Start(this.Editor.Value, args);
            await process.WaitForExitAsync().ConfigureAwait(false);

            if (process.ExitCode != 0)
            {
                Logger.Write(this, LogLevel.Warn, "Process does not indicate success: Code = {0}", process.ExitCode);
                return;
            }
            if (metaDataItem == null)
            {
                metaDataItem = new MetaDataItem(CommonMetaData.Lyrics, MetaDataItemType.Tag);
                lock (playlistItem.MetaDatas)
                {
                    playlistItem.MetaDatas.Add(metaDataItem);
                }
            }
            metaDataItem.Value = File.ReadAllText(fileName);
            await this.MetaDataManager.Save(
                new[] { playlistItem },
                true,
                false,
                CommonMetaData.Lyrics
                ).ConfigureAwait(false);
        }
Пример #14
0
        private async Task <IPicture> CreateImage(MetaDataItem metaDataItem, Tag tag)
        {
            var type    = GetArtworkType(metaDataItem.Name);
            var picture = new Picture(metaDataItem.Value)
            {
                Type     = GetPictureType(type),
                MimeType = MimeMapping.Instance.GetMimeType(metaDataItem.Value)
            };

            metaDataItem.Value = await this.ImportImage(tag, picture, type, true).ConfigureAwait(false);

            return(picture);
        }
Пример #15
0
        protected virtual MetaDataItem[] GetMetaData(CueSheet cueSheet, CueSheetTrack cueSheetTrack, IEnumerable <MetaDataItem> fileMetaData)
        {
            var metaDataItems = new Dictionary <string, MetaDataItem>(StringComparer.OrdinalIgnoreCase);

            if (fileMetaData != null)
            {
                foreach (var metaDataItem in fileMetaData)
                {
                    metaDataItems[metaDataItem.Name] = metaDataItem;
                }
            }
            foreach (var tag in cueSheet.Tags)
            {
                var name = default(string);
                if (!FILE_NAMES.TryGetValue(tag.Name, out name))
                {
                    if (!CommonMetaData.Lookup.TryGetValue(tag.Name, out name))
                    {
                        name = tag.Name;
                    }
                }
                metaDataItems[name] = new MetaDataItem(name, MetaDataItemType.Tag)
                {
                    Value = tag.Value
                };
            }
            foreach (var tag in cueSheetTrack.Tags)
            {
                var name = default(string);
                if (!TRACK_NAMES.TryGetValue(tag.Name, out name))
                {
                    if (!CommonMetaData.Lookup.TryGetValue(tag.Name, out name))
                    {
                        name = tag.Name;
                    }
                }
                metaDataItems[name] = new MetaDataItem(name, MetaDataItemType.Tag)
                {
                    Value = tag.Value
                };
            }
            metaDataItems[CommonMetaData.Track] = new MetaDataItem(CommonMetaData.Track, MetaDataItemType.Tag)
            {
                Value = cueSheetTrack.Number
            };
            //TODO: We could create the CommonProperties.Duration for all but the last track in each file.
            //TODO: Without understanding the file format we can't determine the length of the last track.
            //TODO: Just don't provide any duration for now.
            metaDataItems.Remove(CommonProperties.Duration);
            return(metaDataItems.Values.ToArray());
        }
Пример #16
0
        public static IEnumerable <string> UpdatePlaylistCache(IPlaylistCache playlistCache, IEnumerable <LibraryItem> libraryItems, IEnumerable <string> names)
        {
            var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var libraryItem in libraryItems)
            {
                var playlistItems = default(PlaylistItem[]);
                if (playlistCache.TryGetItemsByLibraryId(libraryItem.Id, out playlistItems))
                {
                    result.AddRange(MetaDataItem.Update(libraryItem, playlistItems, names));
                }
            }
            return(result);
        }
Пример #17
0
        private static async Task <IPicture> CreateImage(MetaDataItem metaDataItem, File file)
        {
            var type    = GetArtworkType(metaDataItem.Name);
            var picture = new Picture(metaDataItem.Value)
            {
                Type = GetPictureType(type),
                //TODO: Assuming that the file name has the correct extension and not .bin
                MimeType = MimeMapping.Instance.GetMimeType(metaDataItem.Value)
            };

            metaDataItem.Value = await ImportImage(file, picture, type, true).ConfigureAwait(false);

            return(picture);
        }
        protected virtual void UpdateLastPlayed(IDictionary <string, MetaDataItem> metaDatas)
        {
            var metaDataItem = default(MetaDataItem);

            if (!metaDatas.TryGetValue(CommonStatistics.LastPlayed, out metaDataItem))
            {
                metaDataItem = new MetaDataItem(CommonStatistics.LastPlayed, MetaDataItemType.Tag);
                this.PlaylistItem.MetaDatas.Add(metaDataItem);
            }
            //TODO: I can't work out what the standard is for this value.
            //TODO: I've seen DateTime.ToFileTime() but that seems a little too windows-ish.
            //TODO: Using yyyy/MM/dd HH:mm:ss for now.
            metaDataItem.Value = DateTimeHelper.ToString(DateTime.UtcNow);
        }
Пример #19
0
 protected virtual void AddMetaData(OnDemandMetaDataRequest request, OnDemandMetaDataValue value)
 {
     lock (value.FileData.MetaDatas)
     {
         var metaDataItem = value.FileData.MetaDatas.FirstOrDefault(
             element => string.Equals(element.Name, request.Name, StringComparison.OrdinalIgnoreCase) && element.Type == request.Type
             );
         if (metaDataItem == null)
         {
             metaDataItem = new MetaDataItem(request.Name, request.Type);
             value.FileData.MetaDatas.Add(metaDataItem);
         }
         metaDataItem.Value = value.Value;
     }
 }
Пример #20
0
        public static IEnumerable <string> UpdatePlaylistCache(IPlaylistCache playlistCache, IEnumerable <PlaylistItem> playlistItems, IEnumerable <string> names)
        {
            var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var playlistItem in playlistItems)
            {
                var cachedPlaylistItem = default(PlaylistItem);
                if (playlistCache.TryGetItemById(playlistItem.Id, out cachedPlaylistItem))
                {
                    if (!object.ReferenceEquals(playlistItem, cachedPlaylistItem))
                    {
                        result.AddRange(MetaDataItem.Update(playlistItem, cachedPlaylistItem, names));
                    }
                }
            }
            return(result);
        }
Пример #21
0
        public static IEnumerable <string> UpdateLibraryCache(ILibraryCache libraryCache, IEnumerable <LibraryItem> libraryItems, IEnumerable <string> names)
        {
            var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var libraryItem in libraryItems)
            {
                var cachedLibraryItem = default(LibraryItem);
                if (libraryCache.TryGetItem(libraryItem.Id, out cachedLibraryItem))
                {
                    if (!object.ReferenceEquals(libraryItem, cachedLibraryItem))
                    {
                        result.AddRange(MetaDataItem.Update(libraryItem, cachedLibraryItem, names));
                    }
                }
            }
            return(result);
        }
Пример #22
0
        public static IEnumerable <string> UpdateLibraryCache(ILibraryCache libraryCache, IEnumerable <PlaylistItem> playlistItems, IEnumerable <string> names)
        {
            var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var playlistItem in playlistItems)
            {
                if (!playlistItem.LibraryItem_Id.HasValue)
                {
                    continue;
                }
                var libraryItem = default(LibraryItem);
                if (libraryCache.TryGetItem(playlistItem.LibraryItem_Id.Value, out libraryItem))
                {
                    result.AddRange(MetaDataItem.Update(playlistItem, libraryItem, names));
                }
            }
            return(result);
        }
Пример #23
0
        public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
        {
            if (string.Equals(metaDataItem.Name, CommonMetaData.IsCompilation, StringComparison.OrdinalIgnoreCase))
            {
                var isCompilation = string.Equals(metaDataItem.Value, bool.TrueString, StringComparison.OrdinalIgnoreCase);

                if (TagManager.HasTag(file, TagTypes.Id3v2))
                {
                    var tag = TagManager.GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
                    if (tag != null)
                    {
                        tag.IsCompilation = isCompilation;
                    }
                }
                else if (TagManager.HasTag(file, TagTypes.Apple))
                {
                    var tag = TagManager.GetTag <global::TagLib.Mpeg4.AppleTag>(file, TagTypes.Apple);
                    if (tag != null)
                    {
                        tag.IsCompilation = isCompilation;
                    }
                }
                else if (TagManager.HasTag(file, TagTypes.Xiph))
                {
                    var tag = TagManager.GetTag <global::TagLib.Ogg.XiphComment>(file, TagTypes.Xiph);
                    if (tag != null)
                    {
                        tag.IsCompilation = isCompilation;
                    }
                }

                if (source.MusicBrainz.Value)
                {
                    if (isCompilation)
                    {
                        file.Tag.MusicBrainzReleaseType = MusicBrainzReleaseType.Compilation;
                    }
                    else if (string.Equals(file.Tag.MusicBrainzReleaseType, MusicBrainzReleaseType.Compilation, StringComparison.OrdinalIgnoreCase))
                    {
                        //TODO: MusicBrainzReleaseType could be anything...
                    }
                }
            }
        }
Пример #24
0
        protected override async Task OnRun()
        {
            foreach (var playlistItem in this.PlaylistItems)
            {
                var metaDataItem = playlistItem.MetaDatas.FirstOrDefault(
                    _metaDataItem => string.Equals(_metaDataItem.Name, CommonMetaData.Rating, StringComparison.OrdinalIgnoreCase)
                    );
                if (metaDataItem == null)
                {
                    metaDataItem = new MetaDataItem(CommonMetaData.Rating, MetaDataItemType.Tag);
                    playlistItem.MetaDatas.Add(metaDataItem);
                }
                metaDataItem.Value = Convert.ToString(this.Rating);
            }
            //Send a soft playlist update so the list refreshes, this makes the task seem more responsive.
            await this.SignalEmitter.Send(new Signal(this, CommonSignals.PlaylistUpdated, CommonSignalFlags.SOFT)).ConfigureAwait(false);

            await this.MetaDataManager.Save(this.PlaylistItems, CommonMetaData.Rating).ConfigureAwait(false);
        }
Пример #25
0
 protected override async Task OnRun()
 {
     foreach (var playlistItem in this.PlaylistItems)
     {
         lock (playlistItem.MetaDatas)
         {
             var metaDataItem = playlistItem.MetaDatas.FirstOrDefault(
                 _metaDataItem => string.Equals(_metaDataItem.Name, CommonStatistics.Rating, StringComparison.OrdinalIgnoreCase)
                 );
             if (metaDataItem == null)
             {
                 metaDataItem = new MetaDataItem(CommonStatistics.Rating, MetaDataItemType.Tag);
                 playlistItem.MetaDatas.Add(metaDataItem);
             }
             metaDataItem.Value = Convert.ToString(this.Rating);
         }
     }
     await this.MetaDataManager.Save(this.PlaylistItems, true, false, CommonStatistics.Rating).ConfigureAwait(false);
 }
Пример #26
0
 public static MetaDataItem GetOrAdd(this IFileData fileData, string name, MetaDataItemType type, string value = null)
 {
     foreach (var metaDataItem in fileData.MetaDatas)
     {
         if (string.Equals(metaDataItem.Name, name, StringComparison.OrdinalIgnoreCase) && metaDataItem.Type == type)
         {
             return(metaDataItem);
         }
     }
     {
         var metaDataItem = new MetaDataItem(name, type);
         if (value != null)
         {
             metaDataItem.Value = value;
         }
         fileData.MetaDatas.Add(metaDataItem);
         return(metaDataItem);
     }
 }
Пример #27
0
        private static IPicture CreateDocument(MetaDataItem metaDataItem, File file)
        {
            var parts = metaDataItem.Value.Split(new[] { ':' }, 2);

            if (parts.Length != 2)
            {
                Logger.Write(typeof(DocumentManager), LogLevel.Warn, "Failed to parse document: {0}", metaDataItem.Value);
                return(null);
            }
            var mimeType = parts[0];
            var data     = parts[1];
            var picture  = new Picture(Encoding.UTF8.GetBytes(data))
            {
                Type     = PictureType.NotAPicture,
                MimeType = mimeType
            };

            return(picture);
        }
        protected virtual void UpdatePlayCount(IDictionary <string, MetaDataItem> metaDatas)
        {
            var metaDataItem = default(MetaDataItem);

            if (!metaDatas.TryGetValue(CommonStatistics.PlayCount, out metaDataItem))
            {
                metaDataItem = new MetaDataItem(CommonStatistics.PlayCount, MetaDataItemType.Tag);
                this.PlaylistItem.MetaDatas.Add(metaDataItem);
            }
            var playCount = default(int);

            if (!string.IsNullOrEmpty(metaDataItem.Value) && int.TryParse(metaDataItem.Value, out playCount))
            {
                metaDataItem.Value = Convert.ToString(playCount + 1);
            }
            else
            {
                metaDataItem.Value = "1";
            }
        }
Пример #29
0
        private static void WriteLoose(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
        {
            var fileName = default(string);

            if (HasImage(metaDataItem.Name, file, out fileName))
            {
                if (!string.IsNullOrEmpty(metaDataItem.Value))
                {
                    ReplaceImage(metaDataItem, fileName);
                }
                else
                {
                    RemoveImage(metaDataItem, fileName);
                }
            }
            else if (!string.IsNullOrEmpty(metaDataItem.Value))
            {
                AddImage(metaDataItem, file);
            }
        }
Пример #30
0
        public string GetKey(MetaDataItem item)
        {
            var name = item.Name;

            switch (item.Type)
            {
            case MetaDataItemType.Document:
                var parts = name.Split(new[] { ':' }, 2);
                if (parts.Length != 2)
                {
                    //Expected document:Name.
                }
                else
                {
                    name = parts[1];
                }
                break;
            }
            return(name.ToLower());
        }