当前位置: 首页>>代码示例>>C#>>正文


C# XmlReader.GetAttributeOrNull方法代码示例

本文整理汇总了C#中XmlReader.GetAttributeOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.GetAttributeOrNull方法的具体用法?C# XmlReader.GetAttributeOrNull怎么用?C# XmlReader.GetAttributeOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlReader的用法示例。


在下文中一共展示了XmlReader.GetAttributeOrNull方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadRelease

        protected Release ReadRelease(XmlReader reader)
        {
            reader.AssertElementStart(Keys.Release);

            Release release = new Release();
            release.JoinedAlbumArtists = reader.GetAttributeOrNull(Keys.JoinedAlbumArtists);
            release.Title = reader.GetAttributeOrNull(Keys.Title);
            release.ReleaseDate = ReleaseDate.Parse(reader.GetAttributeOrNull(Keys.ReleaseDate));
            release.OriginalReleaseDate = ReleaseDate.Parse(reader.GetAttributeOrNull(Keys.OriginalReleaseDate));
            release.CatalogNumber = reader.GetAttributeOrNull(Keys.CatalogNumber);
            release.Label = reader.GetAttributeOrNull(Keys.Label);
            release.Country = reader.GetAttributeOrNull(Keys.Country);
            release.FlagMessage = reader.GetAttributeOrNull(Keys.FlagMessage);
            release.IsFlagged = release.FlagMessage != null;
            release.Notes = reader.GetAttributeOrNull(Keys.Notes);
            release.WikipediaPageName = reader.GetAttributeOrNull(Keys.WikipediaPageName);

            release.DiscogsReleaseId = reader.GetAttributeInt32(Keys.DiscogsReleaseId, 0);
            release.DiscogsMasterId = reader.GetAttributeInt32(Keys.DiscogsMasterId, 0);
            release.Genre = reader.GetAttributeOrNull(Keys.Genre);
            release.Score = reader.GetAttributeInt32(Keys.Score, 0);
            release.DynamicRange = reader.GetAttributeDouble(Keys.DynamicRange, double.NaN);
            release.ReplayGainAlbumGain = reader.GetAttributeDouble(Keys.AlbumGain, double.NaN);
            release.ReplayGainAlbumPeak = reader.GetAttributeDouble(Keys.AlbumPeak, double.NaN);

            if (reader.GetAttributeOrNull(Keys.DateAdded) != null)
            {
                release.DateAdded = new DateTime(reader.GetAttributeInt64(Keys.DateAdded, 0));
            }
            if (reader.GetAttributeOrNull(Keys.DateAudioModified) != null)
            {
                release.DateAudioModified = new DateTime(reader.GetAttributeInt64(Keys.DateAudioModified, 0));
            }
            if (reader.GetAttributeOrNull(Keys.DateModified) != null)
            {
                release.DateModified = new DateTime(reader.GetAttributeInt64(Keys.DateModified, 0));
            }

            if (reader.IsEmptyElement)
            {
                throw new FormatException(InvalidXmlDatabase);
            }

            while (reader.Read())
            {
                if (reader.IsElementEnd(Keys.Release))
                {
                    break;
                }

                if (reader.IsElementStart(Keys.Artists))
                {
                    this.ReadArtists(reader, release);
                }
                else if (reader.IsElementStart(Keys.Tracks))
                {
                    this.ReadTracks(reader, release);
                }
                else if (reader.IsElementStart(Keys.Images))
                {
                    this.ReadImages(reader, release);
                }
                else if (reader.IsElementStart(Keys.AdditionalFiles))
                {
                    this.ReadAdditionalFiles(reader, release);
                }
            }

            return release;
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:70,代码来源:CollectionImporterBase.cs

示例2: ReadTrackArtists

        private void ReadTrackArtists(XmlReader reader, Track track)
        {
            reader.AssertElementStart(Keys.Artists);

            if (reader.IsEmptyElement)
            {
                throw new FormatException(InvalidXmlDatabase);
            }

            while (reader.Read())
            {
                if (reader.IsElementEnd(Keys.Artists))
                {
                    break;
                }

                reader.AssertElementStart(Keys.Artist);
                track.Artists.Add(new TrackArtist()
                {
                    Artist = this.collectionManager.GetOrCreateArtist(reader.GetAttributeOrNull(Keys.Name)),
                    JoinString = reader.GetAttributeOrNull(Keys.JoinString)
                });
            }
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:24,代码来源:CollectionImporterBase.cs

示例3: ReadImages

        private void ReadImages(XmlReader reader, Release release)
        {
            reader.AssertElementStart(Keys.Images);

            if (reader.IsEmptyElement)
            {
                return;
            }

            bool skipRead = false;
            while (skipRead || reader.Read())
            {
                skipRead = false;

                if (reader.IsElementEnd(Keys.Images))
                {
                    break;
                }

                reader.AssertElementStart(Keys.Image);
                Image image = new Image()
                {
                    Type = Utility.ParseEnum<ImageType>(reader.GetAttributeOrNull(Keys.Type)),
                    MimeType = reader.GetAttributeOrNull(Keys.MimeType),
                    Extension = reader.GetAttributeOrNull(Keys.Extension),
                    Description = reader.GetAttributeOrNull(Keys.Description),
                    IsMain = bool.Parse(reader.GetAttributeOrNull(Keys.IsMain))
                };
                release.Images.Add(image);

                release.UpdateDynamicProperties();

                this.collectionManager.ImageHandler.StoreImageFromXml(image, reader);

                skipRead = true;
            }
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:37,代码来源:CollectionImporterBase.cs

示例4: ReadTrack

        private Track ReadTrack(XmlReader reader)
        {
            reader.AssertElementStart(Keys.Track);

            Track track = new Track()
            {
                Disc = reader.GetAttributeInt32(Keys.Disc, 0),
                Position = reader.GetAttributeInt32(Keys.Position, 0),
                Title = reader.GetAttributeOrNull(Keys.Title),
                JoinedArtists = reader.GetAttributeOrNull(Keys.JoinedArtists),
                RelativeFilename = reader.GetAttributeOrNull(Keys.RelativeFilename),
                DynamicRange = reader.GetAttributeDouble(Keys.DynamicRange, double.NaN),
                ReplayGainTrackGain = reader.GetAttributeDouble(Keys.TrackGain, double.NaN),
                ReplayGainTrackPeak = reader.GetAttributeDouble(Keys.TrackPeak, double.NaN),
            };

            if (reader.IsEmptyElement)
            {
                return track;
            }

            while (reader.Read())
            {
                if (reader.IsElementEnd(Keys.Track))
                {
                    break;
                }

                if (reader.IsElementStart(Keys.Artists))
                {
                    this.ReadTrackArtists(reader, track);
                }
                else
                {
                    throw new FormatException(InvalidXmlDatabase);
                }
            }

            return track;
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:40,代码来源:CollectionImporterBase.cs

示例5: ReadAdditionalFiles

        private void ReadAdditionalFiles(XmlReader reader, Release release)
        {
            reader.AssertElementStart(Keys.AdditionalFiles);

            if (reader.IsEmptyElement)
            {
                return;
            }

            bool skipRead = false;
            while (skipRead || reader.Read())
            {
                skipRead = false;

                if (reader.IsElementEnd(Keys.AdditionalFiles))
                {
                    break;
                }

                reader.AssertElementStart(Keys.AdditionalFile);
                ReleaseAdditionalFile file = new ReleaseAdditionalFile()
                {
                    Type = Utility.ParseEnum<ReleaseAdditionalFileType>(reader.GetAttributeOrNull(Keys.Type)),
                    Description = reader.GetAttributeOrNull(Keys.Description),
                    OriginalFilename = reader.GetAttributeOrNull(Keys.OriginalFilename)
                };

                byte[] resultBuffer = new byte[0];
                int read;
                while ((read = reader.ReadElementContentAsBase64(this.readBuffer, 0, this.readBuffer.Length)) > 0)
                {
                    byte[] newResultBuffer = new byte[resultBuffer.Length + read];
                    Array.Copy(resultBuffer, newResultBuffer, resultBuffer.Length);
                    Array.Copy(this.readBuffer, 0, newResultBuffer, resultBuffer.Length, read);
                    resultBuffer = newResultBuffer;
                }
                file.File = resultBuffer;

                release.AdditionalFiles.Add(file);

                skipRead = true;
            }
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:43,代码来源:CollectionImporterBase.cs


注:本文中的XmlReader.GetAttributeOrNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。