/// <summary>
        ///     Parses song part oder
        /// </summary>
        /// <param name="xelem"></param>
        /// <param name="sng"></param>
        /// <returns></returns>
        private List <PowerPraiseSong.Part> ParseOrder(XmlElement xelem, PowerPraiseSong sng)
        {
            var list = new List <PowerPraiseSong.Part>();

            if (xelem != null && xelem.ChildNodes.Count > 0)
            {
                foreach (XmlElement elem in xelem)
                {
                    if (elem.Name == "item")
                    {
                        if (!string.IsNullOrEmpty(elem.InnerText))
                        {
                            var val = elem.InnerText.Trim();
                            foreach (var part in sng.Parts)
                            {
                                if (part.Caption == val)
                                {
                                    list.Add(part);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                list.AddRange(sng.Parts);
            }
            return(list);
        }
Esempio n. 2
0
 protected bool Equals(PowerPraiseSong other)
 {
     return(string.Equals(Title, other.Title) && string.Equals(Category, other.Category) &&
            string.Equals(Language, other.Language) && Equals(Parts, other.Parts) && Equals(Order, other.Order) &&
            Equals(CopyrightText, other.CopyrightText) && string.Equals(SourceText, other.SourceText) &&
            Formatting.Equals(other.Formatting));
 }
        public void SaveTest()
        {
            ISongFileWriter <PowerPraiseSong> target = new PowerPraiseSongFileWriter();
            string referenceFilename = "Resources/powerpraise/Näher, mein Gott zu Dir.ppl";
            string filename          = "Resources/powerpraise/Näher, mein Gott zu Dir - neu.ppl";

            PowerPraiseSong sng = PowerPraiseTestUtil.GetExpectedPowerPraiseSong();

            target.Save(filename, sng);

            try {
                FileUtils.FileEquals(filename, referenceFilename, true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
        public static PowerPraiseSong GetExpectedPowerPraiseSong()
        {
            PowerPraiseSong ppl = new PowerPraiseSong
            {
                Title    = "Näher, mein Gott, zu Dir",
                Language = "Deutsch",
                Category = "Anbetung"
            };

            // General

            // Songtext
            PowerPraiseSong.Part part = new PowerPraiseSong.Part
            {
                Caption = "Teil 1"
            };

            PowerPraiseSong.Slide slide = new PowerPraiseSong.Slide
            {
                MainSize   = 42,
                Background = new ImageBackground("Blumen\\Blume 3.jpg")
            };
            slide.Lines.Add("Näher, mein Gott, zu Dir,");
            slide.Lines.Add("sei meine Bitt'!");
            slide.Lines.Add("Näher, o Herr, zu Dir");
            slide.Lines.Add("mit jedem Schritt.");
            part.Slides.Add(slide);

            slide = new PowerPraiseSong.Slide
            {
                MainSize   = 44,
                Background = new ImageBackground("Blumen\\Blume 3.jpg")
            };
            slide.Lines.Add("Nur an dem Herzen Dein");
            slide.Lines.Add("kann ich geborgen sein;");
            slide.Lines.Add("deshalb die Bitte mein:");
            slide.Lines.Add("Näher zu Dir!");
            part.Slides.Add(slide);
            ppl.Parts.Add(part);

            part = new PowerPraiseSong.Part
            {
                Caption = "Teil 2"
            };

            slide = new PowerPraiseSong.Slide
            {
                MainSize   = 42,
                Background = new ImageBackground("Blumen\\Blume 3.jpg")
            };
            slide.Lines.Add("Näher, mein Gott, zu Dir!");
            slide.Lines.Add("Ein jeder Tag");
            slide.Lines.Add("soll es neu zeigen mir,");
            slide.Lines.Add("was er vermag:");
            part.Slides.Add(slide);

            slide = new PowerPraiseSong.Slide
            {
                MainSize   = 42,
                Background = new ImageBackground("Blumen\\Blume 3.jpg")
            };
            slide.Lines.Add("Wie seiner Gnade Macht,");
            slide.Lines.Add("Erlösung hat gebracht,");
            slide.Lines.Add("in uns're Sündennacht.");
            slide.Lines.Add("Näher zu Dir!");
            part.Slides.Add(slide);
            ppl.Parts.Add(part);

            part = new PowerPraiseSong.Part
            {
                Caption = "Teil 3"
            };

            slide = new PowerPraiseSong.Slide
            {
                MainSize   = 42,
                Background = new ImageBackground("Blumen\\Blume 3.jpg")
            };
            slide.Lines.Add("Näher, mein Gott, zu Dir!");
            slide.Lines.Add("Dich bet' ich an.");
            slide.Lines.Add("Wie vieles hast an mir,");
            slide.Lines.Add("Du doch getan!");
            part.Slides.Add(slide);

            slide = new PowerPraiseSong.Slide
            {
                MainSize   = 42,
                Background = new ImageBackground("Blumen\\Blume 3.jpg")
            };
            slide.Lines.Add("Von Banden frei und los,");
            slide.Lines.Add("ruh' ich in Deinem Schoss.");
            slide.Lines.Add("Ja, Deine Gnad' ist gross!");
            slide.Lines.Add("Näher zu Dir!");
            part.Slides.Add(slide);
            ppl.Parts.Add(part);

            // Order
            ppl.Order.Add(ppl.Parts[0]);
            ppl.Order.Add(ppl.Parts[1]);
            ppl.Order.Add(ppl.Parts[2]);

            // Copyright
            ppl.CopyrightText.Add("Text und Musik: Lowell Mason, 1792-1872");
            ppl.Formatting.CopyrightTextPosition = AdditionalInformationPosition.LastSlide;

            // Source
            ppl.SourceText = "grünes Buch 339";
            ppl.Formatting.SourceTextPosition = AdditionalInformationPosition.FirstSlide;

            // Formatting
            ppl.Formatting.MainText = new PowerPraiseSongFormatting.FontFormatting
            {
                Font           = new Font("Times New Roman", 44, FontStyle.Bold | FontStyle.Italic),
                Color          = Color.White,
                OutlineWidth   = 30,
                ShadowDistance = 15
            };
            ppl.Formatting.TranslationText = new PowerPraiseSongFormatting.FontFormatting
            {
                Font           = new Font("Times New Roman", 20, FontStyle.Regular),
                Color          = Color.White,
                OutlineWidth   = 30,
                ShadowDistance = 20
            };
            ppl.Formatting.CopyrightText = new PowerPraiseSongFormatting.FontFormatting
            {
                Font           = new Font("Times New Roman", 14, FontStyle.Regular),
                Color          = Color.White,
                OutlineWidth   = 30,
                ShadowDistance = 20
            };
            ppl.Formatting.SourceText = new PowerPraiseSongFormatting.FontFormatting
            {
                Font           = new Font("Times New Roman", 30, FontStyle.Regular),
                Color          = Color.White,
                OutlineWidth   = 30,
                ShadowDistance = 20
            };
            ppl.Formatting.Outline = new PowerPraiseSongFormatting.OutlineFormatting
            {
                Color   = Color.Black,
                Enabled = false
            };
            ppl.Formatting.Shadow = new PowerPraiseSongFormatting.ShadowFormatting
            {
                Color     = Color.Black,
                Direction = 125,
                Enabled   = true
            };

            // Line spacing
            ppl.Formatting.MainLineSpacing        = 30;
            ppl.Formatting.TranslationLineSpacing = 20;

            // Text orientation
            ppl.Formatting.TextOrientation     = new TextOrientation(VerticalOrientation.Middle, HorizontalOrientation.Left);
            ppl.Formatting.TranslationPosition = TranslationPosition.Inline;

            // Borders
            ppl.Formatting.Borders = new PowerPraiseSongFormatting.TextBorders
            {
                TextLeft        = 50,
                TextTop         = 40,
                TextRight       = 60,
                TextBottom      = 70,
                CopyrightBottom = 30,
                SourceTop       = 20,
                SourceRight     = 40
            };

            return(ppl);
        }
        protected void Parse(string filename, PowerPraiseSong sng)
        {
            // Init xml
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);
            var xmlRoot = xmlDoc.DocumentElement;

            if (xmlRoot == null || xmlRoot.Name != XmlRootNodeName ||
                xmlRoot.GetAttribute("version") != SupportedFileFormatVersion || xmlRoot["general"] == null ||
                xmlRoot["general"]["title"] == null)
            {
                throw new InvalidSongSourceFileException("Song header missing");
            }

            // Title
            sng.Title = xmlRoot["general"]["title"].InnerText;

            // Category
            sng.Category = ParseString(xmlRoot["general"]["category"], PowerPraiseConstants.NoCategory);

            // Language
            sng.Language = ParseString(xmlRoot["general"]["language"], PowerPraiseConstants.Language);

            // Parse additional fields (hook)
            ParseAdditionalFields(xmlRoot, sng);

            // Background images
            if (xmlRoot["formatting"] != null && xmlRoot["formatting"]["background"] != null)
            {
                _backgrounds = ParseBackgroundImages(xmlRoot["formatting"]["background"]);
            }
            else
            {
                _backgrounds = new List <IBackground>();
            }

            //
            // Song text and part order
            //

            if (xmlRoot["songtext"] == null)
            {
                throw new InvalidSongSourceFileException("Song parts missing");
            }

            // Song text
            foreach (XmlElement elem in xmlRoot["songtext"])
            {
                if (elem.Name == "part")
                {
                    sng.Parts.Add(ParseSongPart(elem, PowerPraiseConstants.SlideMainTextSize));
                }
            }

            // Order
            sng.Order.AddRange(ParseOrder(xmlRoot["order"], sng));

            //
            // Information
            //

            var copyrightTextPosition = PowerPraiseConstants.Format.CopyrightTextPosition;
            var sourceTextEnabled     = PowerPraiseConstants.Format.SourceTextPosition;

            if (xmlRoot["information"] != null)
            {
                // Copyright text
                var copyrightElem = xmlRoot["information"]["copyright"];
                if (copyrightElem != null)
                {
                    // Position
                    copyrightTextPosition = ParseAdditionalInformationPosition(copyrightElem["position"],
                                                                               PowerPraiseConstants.Format.CopyrightTextPosition);

                    // Text
                    sng.CopyrightText.AddRange(ParseCopyRightText(copyrightElem["text"]));
                }

                // Source text
                var sourceElem = xmlRoot["information"]["source"];
                if (sourceElem != null)
                {
                    // Enabled
                    sourceTextEnabled = ParseAdditionalInformationPosition(sourceElem["position"],
                                                                           PowerPraiseConstants.Format.SourceTextPosition);

                    // Text
                    sng.SourceText = ParseSourceText(sourceElem["text"]);
                }
            }

            //
            // Formatting
            //

            var formatting = xmlRoot["formatting"];

            if (formatting == null)
            {
                throw new InvalidSongSourceFileException("Formatting definition missing");
            }

            var fontElem            = formatting["font"];
            var lineSpacingElem     = formatting["linespacing"];
            var textOrientationElem = formatting["textorientation"];
            var borderElem          = formatting["borders"];

            if (fontElem == null || lineSpacingElem == null || textOrientationElem == null || borderElem == null)
            {
                throw new InvalidSongSourceFileException("Formatting definition incomplete");
            }

            sng.Formatting = new PowerPraiseSongFormatting
            {
                // Font formatting
                MainText        = ParseTextFormatting(fontElem["maintext"], PowerPraiseConstants.Format.MainText),
                TranslationText =
                    ParseTextFormatting(fontElem["translationtext"], PowerPraiseConstants.Format.TranslationText),
                CopyrightText =
                    ParseTextFormatting(fontElem["copyrighttext"], PowerPraiseConstants.Format.CopyrightText),
                SourceText = ParseTextFormatting(fontElem["sourcetext"], PowerPraiseConstants.Format.SourceText),

                // Font outline
                Outline = ParseFontOutline(fontElem["outline"], PowerPraiseConstants.Format.Outline),

                // Font shadow
                Shadow = ParseFontShadow(fontElem["shadow"], PowerPraiseConstants.Format.Shadow),

                // Line spacing
                MainLineSpacing =
                    ParseNaturalNumber(lineSpacingElem["main"], PowerPraiseConstants.Format.MainLineSpacing),
                TranslationLineSpacing =
                    ParseNaturalNumber(lineSpacingElem["translation"],
                                       PowerPraiseConstants.Format.TranslationLineSpacing),

                // Text orientation
                TextOrientation = ParseOrientation(textOrientationElem, PowerPraiseConstants.Format.TextOrientation),

                // Translation position
                TranslationPosition =
                    ParseTranslationPosition(textOrientationElem, PowerPraiseConstants.Format.TranslationPosition),

                // Copyright and source
                CopyrightTextPosition = copyrightTextPosition,
                SourceTextPosition    = sourceTextEnabled,

                // Borders
                Borders = ParseBorders(borderElem)
            };
        }
 /// <summary>
 ///     Parses additional fields (hook)
 /// </summary>
 /// <param name="xmlRoot"></param>
 /// <param name="sng"></param>
 protected abstract void ParseAdditionalFields(XmlElement xmlRoot, PowerPraiseSong sng);
        public void MapTest()
        {
            PowerPraiseSongFileMapper mapper = new PowerPraiseSongFileMapper();

            PowerPraiseSong source   = PowerPraiseTestUtil.GetExpectedPowerPraiseSong();
            Song            expected = PowerPraiseTestUtil.GetExpectedSong();
            Song            actual   = mapper.Map(source);

            Assert.AreEqual(expected.Guid, actual.Guid, "Wrong GUID");
            Assert.AreEqual(expected.ModifiedTimestamp, actual.ModifiedTimestamp, "Wrong modified timestamp");
            Assert.AreEqual(expected.CreatedIn, actual.CreatedIn, "Wrong created in");
            Assert.AreEqual(expected.ModifiedIn, actual.ModifiedIn, "Wrong modified in");
            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.Language, actual.Language, "Wrong language");
            Assert.AreEqual(expected.CcliIdentifier, actual.CcliIdentifier, "Wrong CcliID");
            Assert.AreEqual(expected.Copyright, actual.Copyright, "Wrong copyright");
            Assert.AreEqual(expected.Formatting.CopyrightPosition, actual.Formatting.CopyrightPosition, "Wrong copyright position");
            Assert.AreEqual(expected.Formatting.SourcePosition, actual.Formatting.SourcePosition, "Wrong source position");
            Assert.AreEqual(expected.ReleaseYear, actual.ReleaseYear, "Wrong release year");
            CollectionAssert.AreEqual(expected.Authors, actual.Authors, "Wrong author");
            Assert.AreEqual(expected.RightsManagement, actual.RightsManagement, "Wrong rights Management");
            Assert.AreEqual(expected.Publisher, actual.Publisher, "Wrong publisher");
            Assert.AreEqual(expected.Version, actual.Version, "Wrong version");
            Assert.AreEqual(expected.Key, actual.Key, "Wrong key");
            Assert.AreEqual(expected.Transposition, actual.Transposition, "Wrong transposition");
            Assert.AreEqual(expected.Tempo, actual.Tempo, "Wrong tempo");
            Assert.AreEqual(expected.Variant, actual.Variant, "Wrong variant");
            Assert.AreEqual(expected.Themes[0], actual.Themes[0], "Wrong theme");
            Assert.AreEqual(expected.Comment, actual.Comment, "Wrong comment");
            Assert.AreEqual(expected.SongBooks[0].Name, actual.SongBooks[0].Name, "Wrong songbook");

            Assert.AreEqual(expected.Parts.Count, actual.Parts.Count, "Parts incomplete");
            for (int i = 0; i < expected.Parts.Count; i++)
            {
                Assert.AreEqual(expected.Parts[i].Caption, actual.Parts[i].Caption, "Wrong verse name in verse " + i);
                Assert.AreEqual(expected.Parts[i].Slides.Count, actual.Parts[i].Slides.Count, "Slides incomplete in verse " + i);
                for (int j = 0; j < expected.Parts[i].Slides.Count; j++)
                {
                    Assert.AreEqual(expected.Parts[i].Slides[j].Background, actual.Parts[i].Slides[j].Background, "Slide background incomplete in verse " + i + " slide " + j);
                    CollectionAssert.AreEqual(expected.Parts[i].Slides[j].Lines, actual.Parts[i].Slides[j].Lines, "Slide lines incomplete in verse " + i + " slide " + j);
                    CollectionAssert.AreEqual(expected.Parts[i].Slides[j].Translation, actual.Parts[i].Slides[j].Translation, "Slide translation lines incomplete in verse " + i + " slide " + j);
                }
            }
            CollectionAssert.AreEqual(expected.PartSequence, actual.PartSequence, "Wrong part sequence");

            Assert.AreEqual(expected.QualityIssues, actual.QualityIssues, "Wrong QA issues");

            Assert.AreEqual(expected.Formatting.MainText.Font, actual.Formatting.MainText.Font);
            Assert.AreEqual(expected.Formatting.MainText.Color, actual.Formatting.MainText.Color);
            Assert.AreEqual(expected.Formatting.MainText.Outline.Color, actual.Formatting.MainText.Outline.Color);
            Assert.AreEqual(expected.Formatting.MainText.Outline.Width, actual.Formatting.MainText.Outline.Width);
            Assert.AreEqual(expected.Formatting.MainText.Shadow.Color, actual.Formatting.MainText.Shadow.Color);
            Assert.AreEqual(expected.Formatting.MainText.Shadow.Direction, actual.Formatting.MainText.Shadow.Direction);
            Assert.AreEqual(expected.Formatting.MainText.Shadow.Distance, actual.Formatting.MainText.Shadow.Distance);
            Assert.AreEqual(expected.Formatting.MainLineSpacing, actual.Formatting.MainLineSpacing);

            Assert.AreEqual(expected.Formatting.TranslationText.Font, actual.Formatting.TranslationText.Font);
            Assert.AreEqual(expected.Formatting.TranslationText.Color, actual.Formatting.TranslationText.Color);
            Assert.AreEqual(expected.Formatting.TranslationText.Outline.Color, actual.Formatting.TranslationText.Outline.Color);
            Assert.AreEqual(expected.Formatting.TranslationText.Outline.Width, actual.Formatting.TranslationText.Outline.Width);
            Assert.AreEqual(expected.Formatting.TranslationText.Shadow.Color, actual.Formatting.TranslationText.Shadow.Color);
            Assert.AreEqual(expected.Formatting.TranslationText.Shadow.Direction, actual.Formatting.TranslationText.Shadow.Direction);
            Assert.AreEqual(expected.Formatting.TranslationText.Shadow.Distance, actual.Formatting.TranslationText.Shadow.Distance);
            Assert.AreEqual(expected.Formatting.TranslationLineSpacing, actual.Formatting.TranslationLineSpacing);

            Assert.AreEqual(expected.Formatting.CopyrightText.Font, actual.Formatting.CopyrightText.Font);
            Assert.AreEqual(expected.Formatting.CopyrightText.Color, actual.Formatting.CopyrightText.Color);
            Assert.AreEqual(expected.Formatting.CopyrightText.Outline.Color, actual.Formatting.CopyrightText.Outline.Color);
            Assert.AreEqual(expected.Formatting.CopyrightText.Outline.Width, actual.Formatting.CopyrightText.Outline.Width);
            Assert.AreEqual(expected.Formatting.CopyrightText.Shadow.Color, actual.Formatting.CopyrightText.Shadow.Color);
            Assert.AreEqual(expected.Formatting.CopyrightText.Shadow.Direction, actual.Formatting.CopyrightText.Shadow.Direction);
            Assert.AreEqual(expected.Formatting.CopyrightText.Shadow.Distance, actual.Formatting.CopyrightText.Shadow.Distance);

            Assert.AreEqual(expected.Formatting.SourceText.Font, actual.Formatting.SourceText.Font);
            Assert.AreEqual(expected.Formatting.SourceText.Color, actual.Formatting.SourceText.Color);
            Assert.AreEqual(expected.Formatting.SourceText.Outline.Color, actual.Formatting.SourceText.Outline.Color);
            Assert.AreEqual(expected.Formatting.SourceText.Outline.Width, actual.Formatting.SourceText.Outline.Width);
            Assert.AreEqual(expected.Formatting.SourceText.Shadow.Color, actual.Formatting.SourceText.Shadow.Color);
            Assert.AreEqual(expected.Formatting.SourceText.Shadow.Direction, actual.Formatting.SourceText.Shadow.Direction);
            Assert.AreEqual(expected.Formatting.SourceText.Shadow.Distance, actual.Formatting.SourceText.Shadow.Distance);

            Assert.AreEqual(expected.Formatting.TextOrientation, actual.Formatting.TextOrientation);
            Assert.AreEqual(expected.Formatting.TextOutlineEnabled, actual.Formatting.TextOutlineEnabled);
            Assert.AreEqual(expected.Formatting.TextShadowEnabled, actual.Formatting.TextShadowEnabled);

            Assert.AreEqual(expected.Formatting.TextBorders.TextLeft, actual.Formatting.TextBorders.TextLeft);
            Assert.AreEqual(expected.Formatting.TextBorders.TextTop, actual.Formatting.TextBorders.TextTop);
            Assert.AreEqual(expected.Formatting.TextBorders.TextRight, actual.Formatting.TextBorders.TextRight);
            Assert.AreEqual(expected.Formatting.TextBorders.TextBottom, actual.Formatting.TextBorders.TextBottom);
            Assert.AreEqual(expected.Formatting.TextBorders.CopyrightBottom, actual.Formatting.TextBorders.CopyrightBottom);
            Assert.AreEqual(expected.Formatting.TextBorders.SourceRight, actual.Formatting.TextBorders.SourceRight);
            Assert.AreEqual(expected.Formatting.TextBorders.SourceTop, actual.Formatting.TextBorders.SourceTop);

            Assert.IsTrue(SongSearchUtil.GetSearchableSongText(actual).Contains("näher mein gott zu dir"));
            Assert.IsTrue(SongSearchUtil.GetSearchableSongText(actual).Contains("geborgen"));
        }
        public void MapSongPowerPraiseSongTest()
        {
            PowerPraiseSongFileMapper mapper = new PowerPraiseSongFileMapper();

            Song            source   = PowerPraiseTestUtil.GetExpectedSong();
            PowerPraiseSong expected = PowerPraiseTestUtil.GetExpectedPowerPraiseSong();
            PowerPraiseSong actual   = new PowerPraiseSong();

            mapper.Map(source, actual);

            // General
            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.Language, actual.Language, "Wrong language");
            Assert.AreEqual(expected.Category, actual.Category, "Wrong category");

            // Parts
            Assert.AreEqual(expected.Parts.Count, actual.Parts.Count, "Parts incomplete");
            for (int i = 0; i < expected.Parts.Count; i++)
            {
                Assert.AreEqual(expected.Parts[i].Caption, actual.Parts[i].Caption, "Wrong verse name in verse " + i);
                Assert.AreEqual(expected.Parts[i].Slides.Count, actual.Parts[i].Slides.Count, "Slides incomplete in verse " + i);
                for (int j = 0; j < expected.Parts[i].Slides.Count; j++)
                {
                    Assert.AreEqual(expected.Parts[i].Slides[j].Background, actual.Parts[i].Slides[j].Background);
                    Assert.AreEqual(expected.Parts[i].Slides[j].MainSize, actual.Parts[i].Slides[j].MainSize);
                    CollectionAssert.AreEqual(expected.Parts[i].Slides[j].Lines, actual.Parts[i].Slides[j].Lines, "Slide lines incomplete in verse " + i + " slide " + j);
                    CollectionAssert.AreEqual(expected.Parts[i].Slides[j].Translation, actual.Parts[i].Slides[j].Translation, "Slide translation incomplete in verse " + i + " slide " + j);
                }
            }

            // Order
            Assert.AreEqual(expected.Order.Count, actual.Order.Count, "Order incomplete");
            for (int i = 0; i < expected.Order.Count; i++)
            {
                Assert.AreEqual(expected.Order[i].Caption, actual.Order[i].Caption, "Wrong verse name in verse " + i);
            }

            // Copyright
            CollectionAssert.AreEqual(expected.CopyrightText, actual.CopyrightText, "Wrong copyright");
            Assert.AreEqual(expected.Formatting.CopyrightTextPosition, actual.Formatting.CopyrightTextPosition, "Wrong copyright text position");

            // Source
            Assert.AreEqual(expected.SourceText, actual.SourceText, "Wrong source text");
            Assert.AreEqual(expected.Formatting.SourceTextPosition, actual.Formatting.SourceTextPosition, "Wrong source text position");

            // Formatting
            Assert.AreEqual(expected.Formatting.MainText.Font, actual.Formatting.MainText.Font);
            Assert.AreEqual(expected.Formatting.MainText.Color, actual.Formatting.MainText.Color);
            Assert.AreEqual(expected.Formatting.MainText.OutlineWidth, actual.Formatting.MainText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.MainText.ShadowDistance, actual.Formatting.MainText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.TranslationText.Font, actual.Formatting.TranslationText.Font);
            Assert.AreEqual(expected.Formatting.TranslationText.Color, actual.Formatting.TranslationText.Color);
            Assert.AreEqual(expected.Formatting.TranslationText.OutlineWidth, actual.Formatting.TranslationText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.TranslationText.ShadowDistance, actual.Formatting.TranslationText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.CopyrightText.Font, actual.Formatting.CopyrightText.Font);
            Assert.AreEqual(expected.Formatting.CopyrightText.Color, actual.Formatting.CopyrightText.Color);
            Assert.AreEqual(expected.Formatting.CopyrightText.OutlineWidth, actual.Formatting.CopyrightText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.CopyrightText.ShadowDistance, actual.Formatting.CopyrightText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.SourceText.Font, actual.Formatting.SourceText.Font);
            Assert.AreEqual(expected.Formatting.SourceText.Color, actual.Formatting.SourceText.Color);
            Assert.AreEqual(expected.Formatting.SourceText.OutlineWidth, actual.Formatting.SourceText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.SourceText.ShadowDistance, actual.Formatting.SourceText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.Outline.Color, actual.Formatting.Outline.Color);
            Assert.AreEqual(expected.Formatting.Outline.Enabled, actual.Formatting.Outline.Enabled);

            Assert.AreEqual(expected.Formatting.Shadow.Color, actual.Formatting.Shadow.Color);
            Assert.AreEqual(expected.Formatting.Shadow.Direction, actual.Formatting.Shadow.Direction);
            Assert.AreEqual(expected.Formatting.Shadow.Enabled, actual.Formatting.Shadow.Enabled);

            // Linespacing
            Assert.AreEqual(expected.Formatting.MainLineSpacing, actual.Formatting.MainLineSpacing);
            Assert.AreEqual(expected.Formatting.TranslationLineSpacing, actual.Formatting.TranslationLineSpacing);

            // Text orientation
            Assert.AreEqual(expected.Formatting.TextOrientation, actual.Formatting.TextOrientation);
            Assert.AreEqual(expected.Formatting.TranslationPosition, actual.Formatting.TranslationPosition);

            // Borders
            Assert.AreEqual(expected.Formatting.Borders.TextLeft, actual.Formatting.Borders.TextLeft);
            Assert.AreEqual(expected.Formatting.Borders.TextTop, actual.Formatting.Borders.TextTop);
            Assert.AreEqual(expected.Formatting.Borders.TextRight, actual.Formatting.Borders.TextRight);
            Assert.AreEqual(expected.Formatting.Borders.TextBottom, actual.Formatting.Borders.TextBottom);
            Assert.AreEqual(expected.Formatting.Borders.CopyrightBottom, actual.Formatting.Borders.CopyrightBottom);
            Assert.AreEqual(expected.Formatting.Borders.SourceTop, actual.Formatting.Borders.SourceTop);
            Assert.AreEqual(expected.Formatting.Borders.SourceRight, actual.Formatting.Borders.SourceRight);
        }
Esempio n. 9
0
        public void LoadTest()
        {
            ISongFileReader <PowerPraiseSong> target = new PowerPraiseSongFileReader();
            const string filename = "Resources/powerpraise/Näher, mein Gott zu Dir.ppl";

            PowerPraiseSong expected = PowerPraiseTestUtil.GetExpectedPowerPraiseSong();

            PowerPraiseSong actual = target.Load(filename);

            // General
            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.Title, actual.GetTitle(), "Wrong song title");
            Assert.AreEqual(expected.Language, actual.Language, "Wrong language");
            Assert.AreEqual(expected.Category, actual.Category, "Wrong category");

            // Parts
            Assert.AreEqual(expected.Parts.Count, actual.Parts.Count, "Parts incomplete");
            for (int i = 0; i < expected.Parts.Count; i++)
            {
                Assert.AreEqual(expected.Parts[i].Caption, actual.Parts[i].Caption, "Wrong verse name in verse " + i);
                Assert.AreEqual(expected.Parts[i].Slides.Count, actual.Parts[i].Slides.Count, "Slides incomplete in verse " + i);
                for (int j = 0; j < expected.Parts[i].Slides.Count; j++)
                {
                    Assert.AreEqual(expected.Parts[i].Slides[j].Background, actual.Parts[i].Slides[j].Background);
                    Assert.AreEqual(expected.Parts[i].Slides[j].MainSize, actual.Parts[i].Slides[j].MainSize);
                    CollectionAssert.AreEqual(expected.Parts[i].Slides[j].Lines, actual.Parts[i].Slides[j].Lines, "Slide lines incomplete in verse " + i + " slide " + j);
                    CollectionAssert.AreEqual(expected.Parts[i].Slides[j].Translation, actual.Parts[i].Slides[j].Translation, "Slide translation incomplete in verse " + i + " slide " + j);
                }
            }

            // Order
            Assert.AreEqual(expected.Order.Count, actual.Order.Count, "Order incomplete");
            for (int i = 0; i < expected.Order.Count; i++)
            {
                Assert.AreEqual(expected.Order[i].Caption, actual.Order[i].Caption, "Wrong verse name in verse " + i);
            }

            // Copyright
            CollectionAssert.AreEqual(expected.CopyrightText, actual.CopyrightText, "Wrong copyright");
            Assert.AreEqual(expected.Formatting.CopyrightTextPosition, actual.Formatting.CopyrightTextPosition, "Wrong copyright text position");

            // Source
            Assert.AreEqual(expected.SourceText, actual.SourceText, "Wrong source text");
            Assert.AreEqual(expected.Formatting.SourceTextPosition, actual.Formatting.SourceTextPosition, "Wrong source text position");

            // Formatting
            Assert.AreEqual(expected.Formatting.MainText.Font, actual.Formatting.MainText.Font);
            Assert.AreEqual(expected.Formatting.MainText.Color.ToArgb(), actual.Formatting.MainText.Color.ToArgb());
            Assert.AreEqual(expected.Formatting.MainText.OutlineWidth, actual.Formatting.MainText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.MainText.ShadowDistance, actual.Formatting.MainText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.TranslationText.Font, actual.Formatting.TranslationText.Font);
            Assert.AreEqual(expected.Formatting.TranslationText.Color.ToArgb(), actual.Formatting.TranslationText.Color.ToArgb());
            Assert.AreEqual(expected.Formatting.TranslationText.OutlineWidth, actual.Formatting.TranslationText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.TranslationText.ShadowDistance, actual.Formatting.TranslationText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.CopyrightText.Font, actual.Formatting.CopyrightText.Font);
            Assert.AreEqual(expected.Formatting.CopyrightText.Color.ToArgb(), actual.Formatting.CopyrightText.Color.ToArgb());
            Assert.AreEqual(expected.Formatting.CopyrightText.OutlineWidth, actual.Formatting.CopyrightText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.CopyrightText.ShadowDistance, actual.Formatting.CopyrightText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.SourceText.Font, actual.Formatting.SourceText.Font);
            Assert.AreEqual(expected.Formatting.SourceText.Color.ToArgb(), actual.Formatting.SourceText.Color.ToArgb());
            Assert.AreEqual(expected.Formatting.SourceText.OutlineWidth, actual.Formatting.SourceText.OutlineWidth);
            Assert.AreEqual(expected.Formatting.SourceText.ShadowDistance, actual.Formatting.SourceText.ShadowDistance);

            Assert.AreEqual(expected.Formatting.Outline.Color.ToArgb(), actual.Formatting.Outline.Color.ToArgb());
            Assert.AreEqual(expected.Formatting.Outline.Enabled, actual.Formatting.Outline.Enabled);

            Assert.AreEqual(expected.Formatting.Shadow.Color.ToArgb(), actual.Formatting.Shadow.Color.ToArgb());
            Assert.AreEqual(expected.Formatting.Shadow.Direction, actual.Formatting.Shadow.Direction);
            Assert.AreEqual(expected.Formatting.Shadow.Enabled, actual.Formatting.Shadow.Enabled);

            // Linespacing
            Assert.AreEqual(expected.Formatting.MainLineSpacing, actual.Formatting.MainLineSpacing);
            Assert.AreEqual(expected.Formatting.TranslationLineSpacing, actual.Formatting.TranslationLineSpacing);

            // Text orientation
            Assert.AreEqual(expected.Formatting.TextOrientation, actual.Formatting.TextOrientation);
            Assert.AreEqual(expected.Formatting.TranslationPosition, actual.Formatting.TranslationPosition);

            // Borders
            Assert.AreEqual(expected.Formatting.Borders.TextLeft, actual.Formatting.Borders.TextLeft);
            Assert.AreEqual(expected.Formatting.Borders.TextTop, actual.Formatting.Borders.TextTop);
            Assert.AreEqual(expected.Formatting.Borders.TextRight, actual.Formatting.Borders.TextRight);
            Assert.AreEqual(expected.Formatting.Borders.TextBottom, actual.Formatting.Borders.TextBottom);
            Assert.AreEqual(expected.Formatting.Borders.CopyrightBottom, actual.Formatting.Borders.CopyrightBottom);
            Assert.AreEqual(expected.Formatting.Borders.SourceTop, actual.Formatting.Borders.SourceTop);
            Assert.AreEqual(expected.Formatting.Borders.SourceRight, actual.Formatting.Borders.SourceRight);
        }
Esempio n. 10
0
        public void Write(string filename, PowerPraiseSong sng)
        {
            var xml     = new XmlWriterHelper(XmlRootNodeName, SupportedFileFormatVersion);
            var xmlRoot = xml.Root;
            var xmlDoc  = xml.Doc;

            xmlRoot.AppendChild(xmlDoc.CreateElement("general"));

            // Title
            xmlRoot["general"].AppendChild(xmlDoc.CreateElement("title"));
            xmlRoot["general"]["title"].InnerText = sng.Title;

            // Category
            xmlRoot["general"].AppendChild(xmlDoc.CreateElement("category"));
            xmlRoot["general"]["category"].InnerText = !string.IsNullOrEmpty(sng.Category)
                ? sng.Category
                : PowerPraiseConstants.NoCategory;

            // Language
            xmlRoot["general"].AppendChild(xmlDoc.CreateElement("language"));
            xmlRoot["general"]["language"].InnerText = !string.IsNullOrEmpty(sng.Language)
                ? sng.Language
                : PowerPraiseConstants.Language;

            // Write additional fields
            WriteAdditionalFields(xmlDoc, xmlRoot, sng);

            xmlRoot.AppendChild(xmlDoc.CreateElement("songtext"));

            // Dictionary of backgrouns
            var bgIndex     = 0;
            var backgrounds = new Dictionary <string, int>();

            // Song parts
            foreach (var prt in sng.Parts)
            {
                var tn = xmlDoc.CreateElement("part");

                // Caption
                tn.SetAttribute("caption", prt.Caption);

                foreach (var sld in prt.Slides)
                {
                    var tn2 = xmlDoc.CreateElement("slide");

                    // Slide-specific text size
                    var mainsize = sld.MainSize > 0 ? sld.MainSize : (int)sng.Formatting.MainText.Font.Size;
                    tn2.SetAttribute("mainsize", mainsize.ToString());

                    // Backgound number
                    var bg = PowerPraiseFileUtil.MapBackground(sld.Background) ??
                             PowerPraiseFileUtil.MapBackground(PowerPraiseConstants.DefaultBackground);
                    int backgroundNr;
                    if (!backgrounds.ContainsKey(bg))
                    {
                        backgroundNr = bgIndex;
                        backgrounds.Add(bg, bgIndex++);
                    }
                    else
                    {
                        backgroundNr = backgrounds[bg];
                    }
                    tn2.SetAttribute("backgroundnr", backgroundNr.ToString());

                    // Lyrics
                    foreach (var ln in sld.Lines)
                    {
                        var tn3 = xmlDoc.CreateElement("line");
                        tn3.InnerText = ln;
                        tn2.AppendChild(tn3);
                    }
                    foreach (var ln in sld.Translation)
                    {
                        var tn3 = xmlDoc.CreateElement("translation");
                        tn3.InnerText = ln;
                        tn2.AppendChild(tn3);
                    }
                    tn.AppendChild(tn2);
                }
                xmlRoot["songtext"].AppendChild(tn);
            }

            // Order
            xmlRoot.AppendChild(xmlDoc.CreateElement("order"));
            foreach (var prt in sng.Order)
            {
                var tn = xmlDoc.CreateElement("item");
                tn.InnerText = prt.Caption;
                xmlRoot["order"].AppendChild(tn);
            }

            xmlRoot.AppendChild(xmlDoc.CreateElement("information"));

            // Copyright
            xmlRoot["information"].AppendChild(xmlDoc.CreateElement("copyright"));

            // Copyright position
            xmlRoot["information"]["copyright"].AppendChild(xmlDoc.CreateElement("position"));
            xmlRoot["information"]["copyright"]["position"].InnerText =
                MapAdditionalInformationPosition(sng.Formatting.CopyrightTextPosition);

            // Copyright text
            xmlRoot["information"]["copyright"].AppendChild(xmlDoc.CreateElement("text"));
            if (sng.CopyrightText != null && !string.IsNullOrEmpty(string.Join("", sng.CopyrightText.ToArray())))
            {
                foreach (var l in sng.CopyrightText)
                {
                    var n = xmlRoot["information"]["copyright"]["text"].AppendChild(xmlDoc.CreateElement("line"));
                    n.InnerText = l;
                }
            }

            // Source
            xmlRoot["information"].AppendChild(xmlDoc.CreateElement("source"));

            // Source enabled
            xmlRoot["information"]["source"].AppendChild(xmlDoc.CreateElement("position"));
            xmlRoot["information"]["source"]["position"].InnerText =
                MapAdditionalInformationPosition(sng.Formatting.SourceTextPosition);

            // Source text
            xmlRoot["information"]["source"].AppendChild(xmlDoc.CreateElement("text"));
            if (!string.IsNullOrEmpty(sng.SourceText))
            {
                xmlRoot["information"]["source"]["text"].AppendChild(xmlDoc.CreateElement("line"));
                xmlRoot["information"]["source"]["text"]["line"].InnerText = sng.SourceText;
            }

            xmlRoot.AppendChild(xmlDoc.CreateElement("formatting"));
            xmlRoot["formatting"].AppendChild(xmlDoc.CreateElement("font"));

            // Font formatting
            ApplyFormatting(xmlDoc, xmlRoot["formatting"]["font"], "maintext", sng.Formatting.MainText);
            ApplyFormatting(xmlDoc, xmlRoot["formatting"]["font"], "translationtext", sng.Formatting.TranslationText);
            ApplyFormatting(xmlDoc, xmlRoot["formatting"]["font"], "copyrighttext", sng.Formatting.CopyrightText);
            ApplyFormatting(xmlDoc, xmlRoot["formatting"]["font"], "sourcetext", sng.Formatting.SourceText);

            // Outline
            xmlRoot["formatting"]["font"].AppendChild(xmlDoc.CreateElement("outline"));
            xmlRoot["formatting"]["font"]["outline"].AppendChild(xmlDoc.CreateElement("enabled"));
            xmlRoot["formatting"]["font"]["outline"]["enabled"].InnerText = sng.Formatting.Outline.Enabled
                ? "true"
                : "false";
            xmlRoot["formatting"]["font"]["outline"].AppendChild(xmlDoc.CreateElement("color"));
            xmlRoot["formatting"]["font"]["outline"]["color"].InnerText =
                PowerPraiseFileUtil.ConvertColor(sng.Formatting.Outline.Color).ToString();

            // Shadow
            xmlRoot["formatting"]["font"].AppendChild(xmlDoc.CreateElement("shadow"));
            xmlRoot["formatting"]["font"]["shadow"].AppendChild(xmlDoc.CreateElement("enabled"));
            xmlRoot["formatting"]["font"]["shadow"]["enabled"].InnerText = sng.Formatting.Shadow.Enabled
                ? "true"
                : "false";
            xmlRoot["formatting"]["font"]["shadow"].AppendChild(xmlDoc.CreateElement("color"));
            xmlRoot["formatting"]["font"]["shadow"]["color"].InnerText =
                PowerPraiseFileUtil.ConvertColor(sng.Formatting.Shadow.Color).ToString();
            xmlRoot["formatting"]["font"]["shadow"].AppendChild(xmlDoc.CreateElement("direction"));
            xmlRoot["formatting"]["font"]["shadow"]["direction"].InnerText =
                sng.Formatting.Shadow.Direction.ToString();

            // Backgrounds
            xmlRoot["formatting"].AppendChild(xmlDoc.CreateElement("background"));
            if (backgrounds.Count == 0)
            {
                backgrounds.Add(PowerPraiseFileUtil.MapBackground(PowerPraiseConstants.DefaultBackground), 0);
            }
            foreach (var bg in backgrounds.Keys)
            {
                var tn = xmlDoc.CreateElement("file");
                tn.InnerText = bg;
                xmlRoot["formatting"]["background"].AppendChild(tn);
            }

            // Linespacing
            xmlRoot["formatting"].AppendChild(xmlDoc.CreateElement("linespacing"));
            xmlRoot["formatting"]["linespacing"].AppendChild(xmlDoc.CreateElement("main"));
            xmlRoot["formatting"]["linespacing"].AppendChild(xmlDoc.CreateElement("translation"));
            xmlRoot["formatting"]["linespacing"]["main"].InnerText =
                (sng.Formatting.MainLineSpacing > 0
                    ? sng.Formatting.MainLineSpacing
                    : PowerPraiseConstants.Format.MainLineSpacing).ToString();
            xmlRoot["formatting"]["linespacing"]["translation"].InnerText =
                (sng.Formatting.MainLineSpacing > 0
                    ? sng.Formatting.TranslationLineSpacing
                    : PowerPraiseConstants.Format.TranslationLineSpacing)
                .ToString();

            // Orientation
            xmlRoot["formatting"].AppendChild(xmlDoc.CreateElement("textorientation"));

            xmlRoot["formatting"]["textorientation"].AppendChild(xmlDoc.CreateElement("horizontal"));
            switch (
                sng.Formatting.TextOrientation != null
                    ? sng.Formatting.TextOrientation.Horizontal
                    : HorizontalOrientation.Center)
            {
            case HorizontalOrientation.Left:
                xmlRoot["formatting"]["textorientation"]["horizontal"].InnerText = "left";
                break;

            case HorizontalOrientation.Center:
                xmlRoot["formatting"]["textorientation"]["horizontal"].InnerText = "center";
                break;

            case HorizontalOrientation.Right:
                xmlRoot["formatting"]["textorientation"]["horizontal"].InnerText = "right";
                break;
            }

            xmlRoot["formatting"]["textorientation"].AppendChild(xmlDoc.CreateElement("vertical"));
            switch (
                sng.Formatting.TextOrientation != null
                    ? sng.Formatting.TextOrientation.Vertical
                    : VerticalOrientation.Middle)
            {
            case VerticalOrientation.Top:
                xmlRoot["formatting"]["textorientation"]["vertical"].InnerText = "top";
                break;

            case VerticalOrientation.Middle:
                xmlRoot["formatting"]["textorientation"]["vertical"].InnerText = "center";
                break;

            case VerticalOrientation.Bottom:
                xmlRoot["formatting"]["textorientation"]["vertical"].InnerText = "bottom";
                break;
            }
            xmlRoot["formatting"]["textorientation"].AppendChild(xmlDoc.CreateElement("transpos"));
            xmlRoot["formatting"]["textorientation"]["transpos"].InnerText = "inline";

            // Borders
            xmlRoot["formatting"].AppendChild(xmlDoc.CreateElement("borders"));
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("mainleft"));
            xmlRoot["formatting"]["borders"]["mainleft"].InnerText = sng.Formatting.Borders.TextLeft.ToString();
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("maintop"));
            xmlRoot["formatting"]["borders"]["maintop"].InnerText = sng.Formatting.Borders.TextTop.ToString();
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("mainright"));
            xmlRoot["formatting"]["borders"]["mainright"].InnerText = sng.Formatting.Borders.TextRight.ToString();
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("mainbottom"));
            xmlRoot["formatting"]["borders"]["mainbottom"].InnerText = sng.Formatting.Borders.TextBottom.ToString();
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("copyrightbottom"));
            xmlRoot["formatting"]["borders"]["copyrightbottom"].InnerText =
                sng.Formatting.Borders.CopyrightBottom.ToString();
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("sourcetop"));
            xmlRoot["formatting"]["borders"]["sourcetop"].InnerText = sng.Formatting.Borders.SourceTop.ToString();
            xmlRoot["formatting"]["borders"].AppendChild(xmlDoc.CreateElement("sourceright"));
            xmlRoot["formatting"]["borders"]["sourceright"].InnerText = sng.Formatting.Borders.SourceRight.ToString();

            xml.Write(filename);
        }
Esempio n. 11
0
 /// <summary>
 ///     Parses additional fields (hook)
 /// </summary>
 /// <param name="xmlDoc"></param>
 /// <param name="xmlRoot"></param>
 /// <param name="sng"></param>
 protected abstract void WriteAdditionalFields(XmlDocument xmlDoc, XmlElement xmlRoot, PowerPraiseSong sng);