示例#1
0
        /// <summary>
        /// Loads the file at the specified <paramref name="path"/> and then deserializes it into a <see cref="Version.ScriptureInfo"/> object.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns>
        /// Returns a <see cref="Version.ScriptureInfo"/> object.
        /// </returns>
        private static Version.ScriptureInfo LoadScriptureInfo(string path)
        {
            Version.ScriptureInfo si = null;

            Stream stream = null;

            try
            {
                stream = new FileStream(path, FileMode.Open);
                si     = Deserialize(stream);
            }
            catch (Exception)
            {
                // Exceptions result in null resource.
            }
            finally
            {
                if (stream != null)
                {
                    ((IDisposable)stream).Dispose();
                }
            }
            return(si);
        }
示例#2
0
        public static Version.ScriptureInfo Deserialize(Stream stream)
        {
            Version.ScriptureInfo result = new Version.ScriptureInfo();

            using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(stream))
            {
                while (r.Read())
                {
                    if (r.Name == "Resource")
                    {

                        result.Name = r.GetAttribute("name");
                        result.TranslationName = r.GetAttribute("tname");
                        result.TranslationAbbreviation = r.GetAttribute("tabbr");

                        while (r.Read())
                        {
                            if (r.Name == "Limits")
                            {
                                r.Read();
                                var limits = new List<ChapterLimits>();

                                while (r.ReadToNextSibling("L"))
                                {
                                    limits.Add(new ChapterLimits
                                    {
                                        BookNumber = int.Parse(r.GetAttribute("b")),
                                        ChapterNumber = int.Parse(r.GetAttribute("c")),
                                        StartVerseIndex = int.Parse(r.GetAttribute("s")),
                                        EndVerseIndex = int.Parse(r.GetAttribute("e")),
                                        EndVerseNumber = int.Parse(r.GetAttribute("v"))
                                    });
                                }
                                result.ChapterLimits = limits.ToArray();
                            }
                            else if (r.Name == "Books")
                            {
                                r.Read();

                                var books = new List<ScriptureBook>();

                                while (r.ReadToNextSibling("B"))
                                {

                                    string o = r.GetAttribute("o");

                                    var book = new ScriptureBook
                                    {
                                        Name = r.GetAttribute("n"),
                                        Number = int.Parse(r.GetAttribute("i")),
                                        ShortAbbr = r.GetAttribute("s"),
                                        LongAbbr = r.GetAttribute("l"),
                                        Ordinal = string.IsNullOrEmpty(o) ? -1 : int.Parse(o)
                                    };

                                    var abbrs = new List<string>();

                                    r.Read();

                                    while (r.ReadToNextSibling("A"))
                                    {
                                        abbrs.Add(r.ReadInnerXml());
                                    }
                                    book.Abbreviations = abbrs.ToArray();

                                    books.Add(book);
                                }
                                result.Books = books.ToArray();
                            }
                        }
                    }
                }
            }
            return result;
        }
示例#3
0
        public static Version.ScriptureInfo Deserialize(Stream stream)
        {
            Version.ScriptureInfo result = new Version.ScriptureInfo();

            using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(stream))
            {
                while (r.Read())
                {
                    if (r.Name == "Resource")
                    {
                        result.Name                    = r.GetAttribute("name");
                        result.TranslationName         = r.GetAttribute("tname");
                        result.TranslationAbbreviation = r.GetAttribute("tabbr");



                        while (r.Read())
                        {
                            if (r.Name == "Limits")
                            {
                                r.Read();
                                var limits = new List <ChapterLimits>();

                                while (r.ReadToNextSibling("L"))
                                {
                                    limits.Add(new ChapterLimits
                                    {
                                        BookNumber      = int.Parse(r.GetAttribute("b")),
                                        ChapterNumber   = int.Parse(r.GetAttribute("c")),
                                        StartVerseIndex = int.Parse(r.GetAttribute("s")),
                                        EndVerseIndex   = int.Parse(r.GetAttribute("e")),
                                        EndVerseNumber  = int.Parse(r.GetAttribute("v"))
                                    });
                                }
                                result.ChapterLimits = limits.ToArray();
                            }
                            else if (r.Name == "Books")
                            {
                                r.Read();

                                var books = new List <ScriptureBook>();

                                while (r.ReadToNextSibling("B"))
                                {
                                    string o = r.GetAttribute("o");

                                    var book = new ScriptureBook
                                    {
                                        Name      = r.GetAttribute("n"),
                                        Number    = int.Parse(r.GetAttribute("i")),
                                        ShortAbbr = r.GetAttribute("s"),
                                        LongAbbr  = r.GetAttribute("l"),
                                        Ordinal   = string.IsNullOrEmpty(o) ? -1 : int.Parse(o)
                                    };

                                    var abbrs = new List <string>();

                                    r.Read();

                                    while (r.ReadToNextSibling("A"))
                                    {
                                        abbrs.Add(r.ReadInnerXml());
                                    }
                                    book.Abbreviations = abbrs.ToArray();

                                    books.Add(book);
                                }
                                result.Books = books.ToArray();
                            }
                        }
                    }
                }
            }
            return(result);
        }