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


C# Song.SetSources方法代码示例

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


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

示例1: PreProcessSongBeamerProperties

        /// <summary>
        /// Helper function to process the imported properties before the actual song content is loaded.
        /// </summary>
        /// <param name="song">The imported song.</param>
        /// <param name="properties">A dictionary with properties.</param>
        /// <param name="langcount">Will be assigned the number of languages as indicated by the 'langcount' property.</param>
        private static void PreProcessSongBeamerProperties(Song song, Dictionary<string, string> properties, out int langcount)
        {
            /* We ignore the following properties:
                properties["editor"] // name of editing program 	#Editor=SongBeamer 4.04c
                properties["keywords"] // search keywords 	#Keywords=Shout to the north and the south Men of faith rise up and sing
                properties["quickfind"] // quick find string like STTN for “Shout to the North” 	#QuickFind=STTN
                properties["churchsongid"] // internal ID 	#ChurchSongID=376
                properties["comments"] // same as Comment?
                properties["version"] // format version? 99.9% it’s 3 otherwise 2 	#Version=3
             */

            /* We currently also ignore any formatting/display properties:
                properties["backgroundimage"] // Path to background relative to image folder. Observed file types: JPEG, PNG, BMP, WMV, AVI 	#BackgroundImage=ThreeCrossesOnAHill.jpg
                properties["font"] // font for lyrics 	#Font=Arial
                properties["fontlang2"] // font for other lyrics 	#FontLang2=Arial
                properties["fontsize"] // font size for lyrics 	#FontSize=35
                properties["textalign"] // text alignment 	#TextAlign=Left
                properties["titlealign"] // title alignment 	#TitleAlign=Center
             */

            /* We could (should) add support for the following properties in the future:
                properties["author"] // name of the lyrics author 	#Author=Sarah Full Adams (1805-1848)
                properties["melody"] // name of composer 	#Melody=Lowell Mason (1792-1872)
                properties["translation"] // name of translation author 	#Translation=Deutsch: Daniel Jacob
                properties["natcopyright"] // national copyright information 	#NatCopyright=Hänssler Verlag
                properties["rights"] // additional rights (e.g. for translated lyrics) 	#Rights=D, A, CH, FL, und L Projektion J Musikverlag, Asslar
                properties["addcopyrightinfo"] // additional copyright information 	#AddCopyrightInfo=1977
                properties["bible"] // bible passage the text is based on 	#Bible=Ps. 144,1-2
                properties["key"] // mus. key of the song 	#Key=F#m
                properties["tempo"]
                properties["titlelang[2...n]"] // song title in other language 	#TitleLang2=Näher mein Gott zu Dir
                properties["otitle"] // original title 	#OTitle=Nearer my God to Thee
                */

            int ccli; // CCLI number 	#CCLI=858299
            if (properties.ContainsKey("ccli") && int.TryParse(properties["ccli"], out ccli))
                song.CcliNumber = ccli;

            if (properties.ContainsKey("title")) // song title 	#Title=Nearer My God To Thee
                song.Title = properties["title"];

            if (properties.ContainsKey("(c)")) // copyright information 	#(c)=1999 Hillsong Music, Australia / Kingsway’s Thankyou Music
                song.Copyright = properties["(c)"];

            if (properties.ContainsKey("categories")) // categories the song is about 	#Categories=grace, worship
                song.Category = properties["categories"];

            if (properties.ContainsKey("comment")) // arbitrary comment 	#Comment=correct slide 4!!!
                song.Comment = properties["comment"];

            if (properties.ContainsKey("songbook")) // also written: SongBook 	#Songbook=Come to Worship 1+2 / 136, In Love With Jesus 2 / 86
                song.SetSources(properties["songbook"].Split(','));

            if (properties.ContainsKey("langcount")) // number of translations in song file 	#LangCount=1
                langcount = int.Parse(properties["langcount"]);
            else
                langcount = 1;

            if (properties.ContainsKey("lang")) // language of the song 	#Lang=E
                song.Language = properties["lang"]; // TODO: what format is this in?

            // TODO: is there a "lang2" property for the language of the first translation? -> Put it in song.TranslationLanguage
        }
开发者ID:Boddlnagg,项目名称:WordsLive,代码行数:69,代码来源:SongBeamerSongReader.cs

示例2: Read

        public void Read(Song song, Stream stream)
        {
            if (song == null)
                throw new ArgumentNullException("song");

            if (stream == null)
                throw new ArgumentNullException("stream");

            var doc = XDocument.Load(stream);

            if (doc.Root.Name != ns + "song")
            {
                throw new SongFormatException("File is not a valid OpenLyrics song.");
            }

            //var openLyricsVersion = new Version(doc.Root.Attribute("version").Value);
            //bool versionPre08 = openLyricsVersion < new Version(0, 8);

            var prop = doc.Root.Element(ns + "properties");

            song.Title = prop.Element(ns + "titles").Elements(ns + "title").First().Value;
            var authors = prop.Elements(ns + "authors");
            song.Copyright = authors.Any() ? String.Join(", ", authors.Single().Elements(ns + "author").Select(e => e.Value)) : String.Empty;
            if (prop.Elements(ns + "publisher").Any())
            {
                var publisher = "Publisher: " + prop.Element(ns + "publisher").Value;
                song.Copyright = String.IsNullOrEmpty(song.Copyright) ? publisher : song.Copyright + "\n" + publisher;
            }

            if (prop.Elements(ns + "copyright").Any())
            {
                var copyright = prop.Element(ns + "copyright").Value;
                if (!copyright.StartsWith("©") && !copyright.StartsWith("(c)"))
                    copyright = "© " + copyright;

                song.Copyright = String.IsNullOrEmpty(song.Copyright) ? copyright : song.Copyright + "\n" + copyright;
            }

            song.CcliNumber = prop.Elements(ns + "ccliNo").Any() ? int.Parse(prop.Element(ns + "ccliNo").Value) : (int?)null;
            song.Category = prop.Elements(ns + "themes").Any() ? String.Join("; ", prop.Element(ns + "themes").Elements(ns + "theme").Select(e => e.Value)) : String.Empty;
            song.Comment = prop.Elements(ns + "comments").Any() ? String.Join("\n", prop.Element(ns + "comments").Elements(ns + "comment").Select(e => e.Value)) : String.Empty;

            if (prop.Elements(ns + "songbooks").Any())
            {
                int number;
                song.SetSources(prop.Element(ns + "songbooks").Elements(ns + "songbook").Select(e => new SongSource(song) {
                    Songbook = e.Attribute("name").Value,
                    Number = e.Attributes("entry").Any() ? (int.TryParse(e.Attribute("entry").Value, out number) ? number : (int?)null) : null
                }));
            }

            var mappings = new Dictionary<string, string>();

            foreach (var verse in doc.Root.Element(ns + "lyrics").Elements(ns + "verse"))
            {
                string originalName = verse.Attribute("name").Value;
                // add language key to part name (we don't know which one is the translation
                // and we can not automatically deal with more than 2 languages)
                string name = originalName + (verse.Attributes("lang").Any() ? " (" + verse.Attribute("lang").Value + ")" : String.Empty);

                if (!mappings.ContainsKey(originalName))
                {
                    // keep a mapping from original name to name with appended language to be used for the verse order
                    mappings.Add(originalName, name);
                }

                var slides = verse.Elements(ns + "lines").Select(lines =>
                {
                    StringBuilder str = new StringBuilder();
                    ParseLines(lines, str);
                    return new SongSlide(song) { Text = str.ToString() };
                });

                song.AddPart(new SongPart(song, name, slides));
            }

            if (prop.Elements(ns + "verseOrder").Any())
            {
                song.SetOrder(prop.Element(ns + "verseOrder").Value.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(n => mappings[n]));
            }
            else
            {
                // if we have no verseOrder element, use all verses from the mappings dictionary
                // (so multiple translations will appear only once)
                song.SetOrder(mappings.Values);
            }
        }
开发者ID:Boddlnagg,项目名称:WordsLive,代码行数:87,代码来源:OpenLyricsSongReader.cs

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