/// <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));
        }
Beispiel #2
0
        /// <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));
        }