public void Load(XElement xTitleInfo) { if (xTitleInfo == null) { throw new ArgumentNullException("xTitleInfo"); } // Load genres genres.Clear(); IEnumerable <XElement> xGenres = xTitleInfo.Elements(fileNameSpace + GenreElementName); if (xGenres != null) { foreach (XElement xGenre in xGenres) { if ((xGenre != null) && (xGenre.Value != null)) { TitleGenreType genre = new TitleGenreType(); genre.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); if (xAuthors != null) { foreach (XElement xAuthor in xAuthors) { AuthorItem 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) && (xLanguage.Value != 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) && (xSrcLanguage.Value != null)) { SrcLanguage = xSrcLanguage.Value; } // Load translators translators.Clear(); IEnumerable <XElement> xTranslators = xTitleInfo.Elements(fileNameSpace + AuthorType.TranslatorElementName); if (xTranslators != null) { foreach (XElement xTranslator in xTranslators) { TranslatorItem 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 sequences.Clear(); IEnumerable <XElement> xSequences = xTitleInfo.Elements(fileNameSpace + SequenceType.SequenceElementName); foreach (var xSequence in xSequences) { SequenceType sec = new SequenceType() { Namespace = fileNameSpace }; try { sec.Load(xSequence); if (!string.IsNullOrEmpty(sec.Name)) { sequences.Add(sec); } } catch (Exception ex) { Debug.WriteLine(string.Format("Error reading sequence data: {0}", ex.Message)); //Debug.WriteLine(string.Format("Error reading sequence data: {0}",ex.Message)); continue; } } }
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.Fail(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.Fail(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.Fail(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.Fail(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.Fail(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.Fail(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.Write("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.Fail(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.Fail(string.Format("Error reading sequence data: {0}",ex.Message)); continue; } } }