internal void Load(XElement xPoem) { if (xPoem == null) { throw new ArgumentNullException("xPoem"); } if (xPoem.Name.LocalName != Fb2PoemElementName) { throw new ArgumentException("Element of wrong type passed", "xPoem"); } Title = null; Date = null; epigraphs.Clear(); content.Clear(); authors.Clear(); IEnumerable<XElement> xElements = xPoem.Elements(); foreach (var xElement in xElements) { if (xElement.Name == (XName)(xPoem.Name.Namespace + StanzaItem.Fb2StanzaElementName)) { StanzaItem stanza = new StanzaItem(); try { stanza.Load(xElement); content.Add(stanza); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + SubTitleItem.Fb2SubtitleElementName)) { SubTitleItem subtitle = new SubTitleItem(); try { subtitle.Load(xElement); content.Add(subtitle); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TitleItem.Fb2TitleElementName) && Title == null) // only one title { Title = new TitleItem(); Title.Load(xElement); } else if (xElement.Name == (XName)(xPoem.Name.Namespace + EpigraphItem.Fb2EpigraphElementName)) { EpigraphItem epigraphItem = new EpigraphItem(); try { epigraphItem.Load(xElement); epigraphs.Add(epigraphItem); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TextAuthorItem.Fb2TextAuthorElementName)) { TextAuthorItem author = new TextAuthorItem(); try { author.Load(xElement); authors.Add(author); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + DateItem.Fb2DateElementName) && Date == null) // only one date { Date = new DateItem(); try { Date.Load(xElement); } catch (Exception) { continue; } } } XAttribute xID = xPoem.Attribute("id"); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } Lang = null; XAttribute xLang = xPoem.Attribute(XNamespace.Xml + "lang"); if ((xLang != null) && (xLang.Value != null)) { Lang = xLang.Value; } }
internal void Load(XElement xPoem) { if (xPoem == null) { throw new ArgumentNullException("xPoem"); } if (xPoem.Name.LocalName != Fb2PoemElementName) { throw new ArgumentException("Element of wrong type passed", "xPoem"); } Title = null; Date = null; epigraphs.Clear(); content.Clear(); authors.Clear(); IEnumerable <XElement> xElements = xPoem.Elements(); foreach (var xElement in xElements) { if (xElement.Name == (XName)(xPoem.Name.Namespace + StanzaItem.Fb2StanzaElementName)) { StanzaItem stanza = new StanzaItem(); try { stanza.Load(xElement); content.Add(stanza); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + SubTitleItem.Fb2SubtitleElementName)) { SubTitleItem subtitle = new SubTitleItem(); try { subtitle.Load(xElement); content.Add(subtitle); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TitleItem.Fb2TitleElementName) && Title == null) // only one title { Title = new TitleItem(); Title.Load(xElement); } else if (xElement.Name == (XName)(xPoem.Name.Namespace + EpigraphItem.Fb2EpigraphElementName)) { EpigraphItem epigraphItem = new EpigraphItem(); try { epigraphItem.Load(xElement); epigraphs.Add(epigraphItem); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TextAuthorItem.Fb2TextAuthorElementName)) { TextAuthorItem author = new TextAuthorItem(); try { author.Load(xElement); authors.Add(author); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + DateItem.Fb2DateElementName) && Date == null) // only one date { Date = new DateItem(); try { Date.Load(xElement); } catch (Exception) { continue; } } } XAttribute xID = xPoem.Attribute("id"); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } Lang = null; XAttribute xLang = xPoem.Attribute(XNamespace.Xml + "lang"); if ((xLang != null) && (xLang.Value != null)) { Lang = xLang.Value; } }
internal void Load(XElement xDocumentInfo) { if (xDocumentInfo == null) { throw new ArgumentNullException("xDocumentInfo"); } // Load document authors _documentAuthors.Clear(); IEnumerable <XElement> xAuthors = xDocumentInfo.Elements(_fileNameSpace + AuthorType.AuthorElementName); if (xAuthors != null) { foreach (XElement xAuthor in xAuthors) { AuthorItem author = new AuthorItem { Namespace = _fileNameSpace }; try { author.Load(xAuthor); _documentAuthors.Add(author); } catch (Exception ex) { Debug.Fail(string.Format("Error reading document authors : {0}", ex.Message)); continue; } } } // load Program used to create ProgramUsed2Create = null; XElement xProgramUsed = xDocumentInfo.Element(_fileNameSpace + ProgramUsedElementName); if (xProgramUsed != null) { ProgramUsed2Create = new TextFieldType(); try { ProgramUsed2Create.Load(xProgramUsed); } catch (Exception ex) { Debug.Fail(string.Format("Error reading program used to create : {0}", ex.Message)); } } // Load creation date DocumentDate = null; XElement xDate = xDocumentInfo.Element(_fileNameSpace + DateItem.Fb2DateElementName); if (xDate != null) { DocumentDate = new DateItem(); try { DocumentDate.Load(xDate); } catch (Exception ex) { Debug.Fail(string.Format("Error reading document date : {0}", ex.Message)); } } // Load Source URLs _sourceUrLs.Clear(); IEnumerable <XElement> xSrcURLs = xDocumentInfo.Elements(_fileNameSpace + SourceURLElementName); if (xSrcURLs != null) { foreach (XElement xSrcURL in xSrcURLs) { if ((xSrcURL != null) && (xSrcURL.Value != null)) { string srcURL = xSrcURL.Value; _sourceUrLs.Add(srcURL); } } } // Load SourceOCR SourceOCR = null; XElement xSrcOcr = xDocumentInfo.Element(_fileNameSpace + SourceOCRElementName); if (xSrcOcr != null) { SourceOCR = new TextFieldType(); try { SourceOCR.Load(xSrcOcr); } catch (Exception ex) { Debug.Fail(string.Format("Error reading source OCR : {0}", ex.Message)); } } // load document's ID ID = null; XElement xID = xDocumentInfo.Element(_fileNameSpace + IdElementName); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } // load document's version DocumentVersion = null; XElement xVersion = xDocumentInfo.Element(_fileNameSpace + VersionElementName); if ((xVersion != null) && (xVersion.Value != null)) { string version = xVersion.Value; try { var cult = new CultureInfo("", false); DocumentVersion = float.Parse(version, cult.NumberFormat); } catch (FormatException ex) { Debug.Fail(string.Format("Error reading document version : {0}", ex.Message)); } } // Load change history History = null; XElement xHistory = xDocumentInfo.Element(_fileNameSpace + HistoryElementName); if (xHistory != null) { History = new AnnotationType() { ElementName = HistoryElementName }; try { History.Load(xHistory); } catch (Exception ex) { Debug.Fail(string.Format("Error reading document history : {0}", ex.Message)); } } // Load copyright owners _documentPublishers.Clear(); IEnumerable <XElement> xPublishers = xDocumentInfo.Elements(_fileNameSpace + AuthorType.PublisherElementName); if (xPublishers != null) { foreach (XElement xPublisher in xPublishers) { PublisherItem publisher = new PublisherItem { Namespace = _fileNameSpace }; try { publisher.Load(xPublisher); _documentPublishers.Add(publisher); } catch (Exception ex) { Debug.Fail(string.Format("Error reading document publishers : {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); 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; } } }