public void Map(string text, Song s) { s.Parts.Clear(); s.PartSequence.Clear(); var lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None); SongPart p = null; SongSlide sl = null; foreach (var l in lines) { var line = l; string caption = null; if (sl == null) { var match = Regex.Match(line, "^(.+): ", RegexOptions.IgnoreCase); if (match.Success) { caption = match.Groups[1].Value; line = line.Substring(match.Groups[0].Value.Length); } } if (p == null || caption != null) { p = new SongPart { Caption = caption }; s.Parts.Add(p); s.PartSequence.Add(p); } if (sl == null) { sl = new SongSlide(); p.Slides.Add(sl); } if (line.StartsWith("--")) { sl = null; continue; } sl.Lines.Add(line); } foreach (var part in s.Parts) { foreach (var slide in part.Slides) { RemoveEmptyLineAtEnd(slide.Lines); } } }
/// <summary> /// Clones this slide /// </summary> /// <returns>A duplicate of this slide</returns> public object Clone() { var res = new SongSlide { Text = Text, TranslationText = TranslationText, PartName = PartName, TextSize = TextSize, Background = Background }; return(res); }
private static Song GetSong() { var s = new Song { Title = "Näher, mein Gott, zu Dir" }; var p = new SongPart { Caption = "Teil 1" }; s.Parts.Add(p); s.PartSequence.Add(p); var sl = new SongSlide(); sl.Lines.Add("Näher, mein Gott, zu Dir,"); sl.Lines.Add("sei meine Bitt'!"); sl.Lines.Add("Näher, o Herr, zu Dir"); sl.Lines.Add("mit jedem Schritt."); p.Slides.Add(sl); sl = new SongSlide(); sl.Lines.Add("Nur an dem Herzen Dein"); sl.Lines.Add("kann ich geborgen sein;"); sl.Lines.Add("deshalb die Bitte mein:"); sl.Lines.Add("Näher zu Dir!"); p.Slides.Add(sl); p = new SongPart { Caption = "Teil 2" }; s.Parts.Add(p); s.PartSequence.Add(p); sl = new SongSlide(); sl.Lines.Add("Näher, mein Gott, zu Dir!"); sl.Lines.Add("Ein jeder Tag"); sl.Lines.Add("soll es neu zeigen mir,"); sl.Lines.Add("was er vermag:"); p.Slides.Add(sl); sl = new SongSlide(); sl.Lines.Add("Wie seiner Gnade Macht,"); sl.Lines.Add("Erlösung hat gebracht,"); sl.Lines.Add("in uns're Sündennacht."); sl.Lines.Add("Näher zu Dir!"); p.Slides.Add(sl); p = new SongPart { Caption = "Teil 3" }; s.Parts.Add(p); s.PartSequence.Add(p); sl = new SongSlide(); sl.Lines.Add("Näher, mein Gott, zu Dir!"); sl.Lines.Add("Dich bet' ich an."); sl.Lines.Add("Wie vieles hast an mir,"); sl.Lines.Add("Du doch getan!"); p.Slides.Add(sl); sl = new SongSlide(); sl.Lines.Add("Von Banden frei und los,"); sl.Lines.Add("ruh' ich in Deinem Schoss."); sl.Lines.Add("Ja, Deine Gnad' ist gross!"); sl.Lines.Add("Näher zu Dir!"); p.Slides.Add(sl); return(s); }
protected bool Equals(SongSlide other) { return(Equals(TranslationText, other.TranslationText) && Equals(Text, other.Text) && Equals(Background, other.Background) && TextSize.Equals(other.TextSize) && string.Equals(PartName, other.PartName)); }
public void TestGetHashCode2() { Song s1 = new Song { Title = "Song 1" }; var s2 = new Song { Title = "Song 1" }; Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode()); SongPart p1 = new SongPart { Caption = "Verse 1" }; s1.Parts.Add(p1); SongPart p2 = new SongPart { Caption = "Verse 1" }; s2.Parts.Add(p2); Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode()); SongSlide sl1 = new SongSlide { Text = "abc def\nghi" }; p1.Slides.Add(sl1); SongSlide sl2 = new SongSlide { Text = "abc def\nghi" }; p2.Slides.Add(sl2); Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode()); SongSlide sl1B = new SongSlide { Text = "abc def\nghij" }; p1.Slides.Add(sl1B); Assert.AreNotEqual(s1.GetHashCode(), s2.GetHashCode()); p1.Slides.RemoveAt(0); Assert.AreNotEqual(s1.GetHashCode(), s2.GetHashCode()); sl1B.Text = "abc def\nghi"; Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode()); }