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


C# Song.AddBackground方法代码示例

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


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

示例1: Read

        /// <summary>
        /// Reads the song data from a stream.
        /// </summary>
        /// <param name="song">The song.</param>
        /// <param name="stream">The stream.</param>
        public void Read(Song song, Stream stream)
        {
            XDocument doc = XDocument.Load(stream);
            XElement root = doc.Element("ppl");
            song.Title = root.Element("general").Element("title").Value;

            var formatting = root.Element("formatting");

            var video = root.Element("formatting").Element("background").Attribute("video");
            if (video != null)
            {
                song.AddBackground(new SongBackground(video.Value, true), true);
            }
            else
            {
                foreach (var bg in root.Element("formatting").Element("background").Elements("file"))
                {
                    song.AddBackground(ReadBackground(bg.Value), true);
                }
            }

            song.Formatting = new SongFormatting
            {
                MainText = ReadTextFormatting(formatting.Element("font").Element("maintext")),
                TranslationText = ReadTextFormatting(formatting.Element("font").Element("translationtext")),
                SourceText = ReadTextFormatting(formatting.Element("font").Element("sourcetext")),
                CopyrightText = ReadTextFormatting(formatting.Element("font").Element("copyrighttext")),
                TextLineSpacing = int.Parse(formatting.Element("linespacing").Element("main").Value),
                TranslationLineSpacing = int.Parse(formatting.Element("linespacing").Element("translation").Value),
                SourceBorderRight = int.Parse(formatting.Element("borders").Element("sourceright").Value),
                SourceBorderTop = int.Parse(formatting.Element("borders").Element("sourcetop").Value),
                CopyrightBorderBottom = int.Parse(formatting.Element("borders").Element("copyrightbottom").Value),
                HorizontalOrientation = (HorizontalTextOrientation)Enum.Parse(typeof(HorizontalTextOrientation), formatting.Element("textorientation").Element("horizontal").Value, true),
                VerticalOrientation = (VerticalTextOrientation)Enum.Parse(typeof(VerticalTextOrientation), formatting.Element("textorientation").Element("vertical").Value, true),
                BorderBottom = int.Parse(formatting.Element("borders").Element("mainbottom").Value),
                BorderTop = int.Parse(formatting.Element("borders").Element("maintop").Value),
                BorderLeft = int.Parse(formatting.Element("borders").Element("mainleft").Value),
                BorderRight = int.Parse(formatting.Element("borders").Element("mainright").Value),
                IsOutlineEnabled = bool.Parse(formatting.Element("font").Element("outline").Element("enabled").Value),
                OutlineColor = ParseColor(formatting.Element("font").Element("outline").Element("color").Value),
                IsShadowEnabled = bool.Parse(formatting.Element("font").Element("shadow").Element("enabled").Value),
                ShadowColor = ParseColor(formatting.Element("font").Element("shadow").Element("color").Value),
                ShadowDirection = int.Parse(formatting.Element("font").Element("shadow").Element("direction").Value),
                TranslationPosition = formatting.Element("textorientation").Element("transpos") != null ?
                    (TranslationPosition)Enum.Parse(typeof(TranslationPosition), formatting.Element("textorientation").Element("transpos").Value, true) : TranslationPosition.Inline,
                CopyrightDisplayPosition = (MetadataDisplayPosition)Enum.Parse(typeof(MetadataDisplayPosition), root.Element("information").Element("copyright").Element("position").Value, true),
                SourceDisplayPosition = (MetadataDisplayPosition)Enum.Parse(typeof(MetadataDisplayPosition), root.Element("information").Element("source").Element("position").Value, true)
            };

            var general = root.Element("general");

            if (general.Element("category") != null)
                song.Category = general.Element("category").Value;

            if (general.Element("language") != null)
                song.Language = general.Element("language").Value;

            if (general.Element("translationlanguage") != null)
                song.TranslationLanguage = general.Element("translationlanguage").Value;

            if (general.Element("comment") != null)
                song.Comment = general.Element("comment").Value;
            else
                song.Comment = String.Empty;

            int ccli;
            if (general.Element("ccli") != null && int.TryParse(general.Element("ccli").Value, out ccli))
                song.CcliNumber = ccli;
            else
                song.CcliNumber = null;

            foreach (var part in root.Element("songtext").Elements("part"))
            {
                song.AddPart(new SongPart(song,
                                part.Attribute("caption").Value,
                                from slide in part.Elements("slide")
                                select new SongSlide(song)
                                {
                                    Text = String.Join("\n", slide.Elements("line").Select(line => line.Value).ToArray())/*.Trim()*/,
                                    Translation = String.Join("\n", slide.Elements("translation").Select(line => line.Value).ToArray())/*.Trim()*/,
                                    BackgroundIndex = slide.Attribute("backgroundnr") != null ? int.Parse(slide.Attribute("backgroundnr").Value) : 0,
                                    Size = slide.Attribute("mainsize") != null ? int.Parse(slide.Attribute("mainsize").Value) : song.Formatting.MainText.Size
                                }
                            ));
            }

            song.SetOrder(from item in root.Element("order").Elements("item") select item.Value);

            song.Copyright = String.Join("\n", root.Element("information").Element("copyright").Element("text").Elements("line").Select(line => line.Value).ToArray());

            song.SetSources(root.Element("information").Element("source").Element("text").Elements("line").Select(line => line.Value));
        }
开发者ID:Boddlnagg,项目名称:WordsLive,代码行数:97,代码来源:PowerpraiseSongReader.cs


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