static void ImportFromSearchXml(List<ChapterEntry> chapters, XDocument xml, int id)
        {
            //if (chapters.Count == 0) throw new Exception("Cannot import names to an empty chapter list.");

              var movie = xml.Descendants("movie").Where(m => (int)m.Element("tagChimpID") == id).FirstOrDefault();
              var names = movie.Descendants("chapterNumber").Select(c => new { Number = int.Parse(c.Value), Title = c.ElementsAfterSelf("chapterTitle").First().Value });
              //var names = from c in movie.Descendants("chapter")
              //            select new
              //            {
              //              Number = (int)c.Element("chapterNumber"),
              //              Title = (string)c.Element("chapterTitle")
              //            };
              names = names.OrderBy(n => n.Number).Distinct();
              if (chapters.Count > 0)
              {
            for (int i = 0; i < chapters.Count; i++)
            {
              string name = names.Where(n => n.Number == i + 1).Select(n => n.Title).FirstOrDefault();
              if (!string.IsNullOrEmpty(name))
            chapters[i] = new ChapterEntry() { Name = name, Time = chapters[i].Time };
            }
              }
              else
              {
            chapters.AddRange(names.Select(n => new ChapterEntry() { Name = n.Title }));
              }
        }
Пример #2
0
        private ChapterEntry GetChapterEntry()
        {
            if (!_chapterEntryWasSearched)
            {
                _chapterEntryWasSearched = true;

                if (VerseEntries.Any())
                {
                    _chapterEntry = new ChapterEntry();

                    VersePointer chapterVp = null;
                    foreach (var verseEntry in VerseEntries)
                    {
                        if (chapterVp != null &&
                            (verseEntry.VersePointer.BookIndex != chapterVp.BookIndex || verseEntry.VersePointer.Chapter != chapterVp.Chapter))
                        {
                            _chapterEntry.Invalid = true;
                            break;
                        }

                        if (chapterVp == null)
                        {
                            chapterVp = verseEntry.VersePointer;
                        }

                        if (verseEntry.StartIndex == 0)
                        {
                            _chapterEntry.AtStartOfParagraph = true;
                        }

                        if (verseEntry.VersePointer.MultiVerseType <= MultiVerse.OneChapter)
                        {
                            if (verseEntry.EntryType == VerseEntryType.BookChapter || verseEntry.EntryType == VerseEntryType.BookChapterVerse)
                            {
                                _chapterEntry.CorrectType = true;
                            }
                        }
                        else
                        {
                            _chapterEntry.Invalid = true;
                            break;
                        }
                    }

                    if (chapterVp != null && !_chapterEntry.Invalid)
                    {
                        _chapterEntry.ChapterPointer = chapterVp.ToChapterPointer();
                    }
                }
            }

            return(_chapterEntry);
        }
        private ChapterEntry GetChapterEntry()
        {
            if (!_chapterEntryWasSearched)
            {
                _chapterEntryWasSearched = true;

                _chapterEntry = new ChapterEntry();
                foreach (var entry in ParseResult.GetSimpleHierarchicalParagraphResults().Select(pr => pr.ChapterEntry))
                {
                    if (entry?.Invalid == true)
                    {
                        _chapterEntry.AtStartOfParagraph = entry.AtStartOfParagraph;
                        _chapterEntry.Invalid            = true;
                        break;
                    }

                    if (entry?.ChapterPointer == null ||
                        (_chapterEntry.ChapterPointer != null && entry.ChapterPointer?.Equals(_chapterEntry.ChapterPointer) == false))
                    {
                        _chapterEntry = ChapterEntry.Terminator;
                        break;
                    }

                    if (_chapterEntry.ChapterPointer == null)
                    {
                        _chapterEntry.ChapterPointer = entry.ChapterPointer;
                    }

                    if (entry.Found)
                    {
                        _chapterEntry.CorrectType = true;
                        if (entry.AtStartOfParagraph)
                        {
                            _chapterEntry.AtStartOfParagraph = true;
                        }
                    }
                }
            }

            return(_chapterEntry);
        }
        private ChapterEntry GetCalculatedChapterEntry()
        {
            ChapterEntry result = null;

            if (ElementType == ElementType.TableCell)
            {
                var hierarchyInfo = (TableHierarchyInfo)ParentHierarchy.ParentHierarchy.HierarchyInfo;
                if (hierarchyInfo.CurrentRow > 0)
                {
                    result = hierarchyInfo.FirstRowParseContexts.TryGetAt(hierarchyInfo.CurrentColumn)?.ChapterEntry;
                }

                if (!(result?.Found).GetValueOrDefault() && !(result?.AtStartOfParagraph).GetValueOrDefault() && hierarchyInfo.CurrentColumn > 0)
                {
                    result = hierarchyInfo.FirstColumnParseContexts.TryGetAt(hierarchyInfo.CurrentRow)?.ChapterEntry;
                }
            }
            else if (ElementType.CanBeLinear() || PreviousSibling?.ElementType.CanBeLinear() == true)
            {
                result = GetPreviousSiblingChapterEntry();
            }

            return(result);
        }
 public void SetTitleVerse(ChapterEntry titleChapter)
 {
     TitleChapter = titleChapter;
 }