本文整理汇总了C#中Song.SetOrder方法的典型用法代码示例。如果您正苦于以下问题:C# Song.SetOrder方法的具体用法?C# Song.SetOrder怎么用?C# Song.SetOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Song
的用法示例。
在下文中一共展示了Song.SetOrder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: PostProcessSongBeamerProperties
/// <summary>
/// Helper function to process the imported properties after the actual song content is loaded.
/// </summary>
/// <param name="song">The imported song.</param>
/// <param name="properties">A dictionary with properties.</param>
private static void PostProcessSongBeamerProperties(Song song, Dictionary<string, string> properties)
{
if (properties.ContainsKey("verseorder"))
{
song.SetOrder(properties["verseorder"].Split(','), ignoreMissing: true);
}
else
{
// if no verseorder is specified, add each part once in order
foreach (SongPart part in song.Parts)
{
song.AddPartToOrder(part);
}
}
}
示例3: Read
//.........这里部分代码省略.........
for (int l = 0; l < lines.Length; l++)
{
var line = lines[l];
if (line.StartsWith("[")) // next part (or group of parts)
{
if (partKey != null)
FinishPart(song, partKey, partLineGroups, currentLineGroup);
var i = line.IndexOf("]");
if (i < 0)
throw new SongFormatException("File is not a valid OpenSong song: Invalid part declaration.");
partKey = line.Substring(1, i - 1).Trim();
partLineGroups = new List<LineGroup>();
currentLineGroup = null;
}
else // not the start of a new part
{
if (line.Trim() == String.Empty || line[0] == ';' || line.StartsWith("---"))
{
// ignore empty line, comments, '---' breaks (whatever they mean)
continue;
}
if (partKey == null) // no part has been started -> create an anonymous one
{
partKey = "Unnamed";
partLineGroups = new List<LineGroup>();
}
if (line[0] == '.')
{
// chord line -> always start new line group and set chords property
if (currentLineGroup != null)
partLineGroups.Add(currentLineGroup);
currentLineGroup = new LineGroup { Chords = line.Substring(1) };
}
else if (line[0] == ' ')
{
// lyrics line -> set lyrics to current LineGroup
if (currentLineGroup == null || currentLineGroup.Lines.Count == 0)
{
if (currentLineGroup == null)
{
currentLineGroup = new LineGroup();
}
currentLineGroup.Lines.Add(new Line { Text = line.Substring(1) });
partLineGroups.Add(currentLineGroup);
currentLineGroup = null;
}
else
{
throw new SongFormatException("File is not a valid OpenSong song: Expected verse number.");
}
}
else if (char.IsDigit(line[0]))
{
int vnum = int.Parse(line[0].ToString());
if (currentLineGroup == null)
{
currentLineGroup = new LineGroup();
}
else if (currentLineGroup.Lines.Count > 0 && vnum <= currentLineGroup.Lines.Last().Number)
{
partLineGroups.Add(currentLineGroup);
currentLineGroup = new LineGroup();
}
currentLineGroup.Lines.Add(new Line { Text = line.Substring(1), Number = vnum });
}
else
{
throw new SongFormatException("File is not a valid OpenSong song: Expected one of ' ', '.', ';' , '[0-9]'");
}
}
}
if (partKey != null)
FinishPart(song, partKey, partLineGroups, currentLineGroup);
// parse order
if (root.Elements("presentation").Any() && root.Elements("presentation").Single().Value.Trim() != String.Empty)
{
var val = root.Elements("presentation").Single().Value.Trim();
var split = wordRegex.Matches(val).Cast<Match>();
song.SetOrder(split.Select(m => GetPartName(m.Value)), ignoreMissing: true);
}
else
{
// if no order is specified, add each part once in order
foreach (SongPart part in song.Parts)
{
song.AddPartToOrder(part);
}
}
}
示例4: 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));
}