示例#1
0
        internal void Load(XElement xPublishInfo)
        {
            if (xPublishInfo == null)
            {
                throw new ArgumentNullException(nameof(xPublishInfo));
            }

            // Load book name
            BookTitle = null;
            XElement xBookName = xPublishInfo.Element(FileNameSpace + BookNameElementName);

            if (xBookName != null)
            {
                BookTitle = new TextFieldType();
                try
                {
                    BookTitle.Load(xBookName);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error reading publisher book name : {ex.Message}");
                }
            }

            // Load publisher
            Publisher = null;
            XElement xPublisher = xPublishInfo.Element(FileNameSpace + PublisherElementName);

            if (xPublisher != null)
            {
                Publisher = new TextFieldType();
                try
                {
                    Publisher.Load(xPublisher);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error reading publishers : {ex.Message}");
                }
            }

            // Load city
            City = null;
            XElement xCity = xPublishInfo.Element(FileNameSpace + CityElementName);

            if (xCity != null)
            {
                City = new TextFieldType();
                try
                {
                    City.Load(xCity);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error reading publishers' City: {ex.Message}");
                }
            }

            // Load year
            Year = null;
            XElement xYear = xPublishInfo.Element(FileNameSpace + YearElementName);

            if (xYear != null)
            {
                if (int.TryParse(xYear.Value, out var year))
                {
                    Year = year;
                }
            }

            // Load ISBN
            ISBN = null;
            XElement xISBN = xPublishInfo.Element(FileNameSpace + ISBNElementName);

            if (xISBN != null)
            {
                ISBN = new TextFieldType();
                try
                {
                    ISBN.Load(xISBN);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error reading publishers' ISBN: {ex.Message}");
                }
            }

            // Load sequence here
            ItemSequences.Clear();
            foreach (var xSequence in xPublishInfo.Elements(FileNameSpace + SequenceType.SequenceElementName))
            {
                var sec = new SequenceType();
                try
                {
                    sec.Load(xSequence);
                    ItemSequences.Add(sec);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error reading publisher sequence data: {ex.Message}");
                }
            }
        }
示例#2
0
        internal void Load(XElement xPublishInfo)
        {
            if (xPublishInfo == null)
            {
                throw new ArgumentNullException("xPublishInfo");
            }

            // Load book name
            BookTitle = null;
            XElement xBookName = xPublishInfo.Element(FileNameSpace + BookNameElementName);
            if ( xBookName != null)  
            {
                BookTitle = new TextFieldType();
                try
                {
                    BookTitle.Load(xBookName);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Error reading publisher book name : {0}", ex.Message));
                }
            }

            // Load publisher
            Publisher = null;
            XElement xPublisher = xPublishInfo.Element(FileNameSpace + PublisherElementName);
            if (xPublisher != null)
            {
                Publisher = new TextFieldType();
                try
                {
                    Publisher.Load(xPublisher);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Error reading publishers : {0}", ex.Message));
                }
            }

            // Load city 
            City = null;
            XElement xCity = xPublishInfo.Element(FileNameSpace + CityElementName);
            if (xCity != null)
            {
                City = new TextFieldType();
                try
                {
                    City.Load(xCity);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Error reading publishers' City: {0}", ex.Message));
                }
            }

            // Load year 
            Year = null;
            XElement xYear = xPublishInfo.Element(FileNameSpace + YearElementName);
            if ( (xYear != null))
            {
                int year;
                if ( int.TryParse( xYear.Value,out year) )
                {
                    Year = year;
                }

            }

            // Load ISBN
            ISBN = null;
            XElement xISBN = xPublishInfo.Element(FileNameSpace + ISBNElementName);
            if (xISBN != null) 
            {
                ISBN = new TextFieldType();
                try
                {
                    ISBN.Load(xISBN);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Error reading publishers' ISBN: {0}", ex.Message));
                }
            }

            // Load sequence here
            ItemSequences.Clear();
            IEnumerable<XElement> xSequences = xPublishInfo.Elements(FileNameSpace + SequenceType.SequenceElementName);
            foreach (var xSequence in xSequences)
            {
                var sec = new SequenceType();
                try
                {
                    sec.Load(xSequence);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Error reading publisher sequence data: {0}", ex.Message));
                    continue;
                }
            }

        }
示例#3
0
        public void Load(XElement xTitleInfo)
        {
            if (xTitleInfo == null)
            {
                throw new ArgumentNullException("xTitleInfo");
            }

            // Load genres
            _genres.Clear();
            IEnumerable <XElement> xGenres = xTitleInfo.Elements(FileNameSpace + GenreElementName);

            foreach (XElement xGenre in xGenres)
            {
                if ((xGenre != null))
                {
                    var genre = new TitleGenreType {
                        Genre = xGenre.Value
                    };
                    XAttribute xMatch = xGenre.Attribute("match");
                    if (xMatch != null && !string.IsNullOrEmpty(xMatch.Value))
                    {
                        int percentage;
                        if (int.TryParse(xMatch.Value, out percentage))
                        {
                            genre.Match = percentage;
                        }
                    }
                    _genres.Add(genre);
                }
            }

            // Load authors
            _bookAuthors.Clear();
            IEnumerable <XElement> xAuthors = xTitleInfo.Elements(FileNameSpace + AuthorType.AuthorElementName);

            foreach (XElement xAuthor in xAuthors)
            {
                var author = new AuthorItem {
                    Namespace = FileNameSpace
                };
                try
                {
                    author.Load(xAuthor);
                    _bookAuthors.Add(author);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading author: {0}", ex.Message));
                    continue;
                }
            }


            // Load Title
            BookTitle = null;
            XElement xBookTitle = xTitleInfo.Element(FileNameSpace + BookTitleElementName);

            if (xBookTitle != null)
            {
                BookTitle = new TextFieldType();
                try
                {
                    BookTitle.Load(xBookTitle);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading book title: {0}", ex.Message));
                }
            }

            // Load Annotation
            Annotation = null;
            XElement xAnnotation = xTitleInfo.Element(FileNameSpace + AnnotationElementName);

            if (xAnnotation != null)
            {
                Annotation = new AnnotationItem();
                try
                {
                    Annotation.Load(xAnnotation);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading annotation: {0}", ex.Message));
                }
            }


            // Load keywords
            Keywords = null;
            XElement xKeywords = xTitleInfo.Element(FileNameSpace + KeywordsElementName);

            if (xKeywords != null)
            {
                Keywords = new TextFieldType();
                try
                {
                    Keywords.Load(xKeywords);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading keywords: {0}", ex.Message));
                }
            }

            // Load Book date
            BookDate = null;
            XElement xBookDate = xTitleInfo.Element(FileNameSpace + DateItem.Fb2DateElementName);

            if (xBookDate != null)
            {
                BookDate = new DateItem();
                try
                {
                    BookDate.Load(xBookDate);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading book date: {0}", ex.Message));
                }
            }

            Cover = null;
            // we should load coverpage images here but no use for them as for now
            XElement xCoverPage = xTitleInfo.Element(FileNameSpace + CoverPageElementName);

            if (xCoverPage != null)
            {
                Cover = new CoverPage {
                    Namespace = FileNameSpace
                };
                try
                {
                    Cover.Load(xCoverPage);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading cover: {0}", ex.Message));
                }
            }

            // Load Language
            Language = null;
            XElement xLanguage = xTitleInfo.Element(FileNameSpace + LanguageElementName);

            if ((xLanguage != null))
            {
                Language = xLanguage.Value;
            }
            else
            {
                Debug.WriteLine("Language not specified in title section");
            }

            // Load source language
            SrcLanguage = null;
            XElement xSrcLanguage = xTitleInfo.Element(FileNameSpace + SourceLanguageElementName);

            if ((xSrcLanguage != null))
            {
                SrcLanguage = xSrcLanguage.Value;
            }

            // Load translators
            _translators.Clear();
            IEnumerable <XElement> xTranslators = xTitleInfo.Elements(FileNameSpace + AuthorType.TranslatorElementName);

            foreach (XElement xTranslator in xTranslators)
            {
                var translator = new TranslatorItem {
                    Namespace = FileNameSpace
                };
                try
                {
                    translator.Load(xTranslator);
                    _translators.Add(translator);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading translator: {0}", ex.Message));
                    continue;
                }
            }

            // Load sequences
            ItemSequences.Clear();
            IEnumerable <XElement> xSequences = xTitleInfo.Elements(FileNameSpace + SequenceType.SequenceElementName);

            foreach (var xSequence in xSequences)
            {
                var sec = new SequenceType {
                    Namespace = FileNameSpace
                };
                try
                {
                    sec.Load(xSequence);
                    ItemSequences.Add(sec);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error reading sequence data: {0}", ex.Message));
                    continue;
                }
            }
        }