Beispiel #1
0
        public void ToDelta_SectionHeader()
        {
            XElement usxElem = Usx("PHM",
                                   Chapter("1"),
                                   Para("p",
                                        Verse("1"),
                                        Verse("2")),
                                   Para("s"),
                                   Para("p",
                                        Verse("3")));

            DeltaUsxMapper mapper   = CreateMapper();
            Delta          newDelta = mapper.ToDelta("12345", usxElem);

            var expected = Delta.New()
                           .InsertChapter("1")
                           .InsertVerse("1")
                           .InsertBlank("verse_1_1")
                           .InsertVerse("2")
                           .InsertBlank("verse_1_2")
                           .InsertPara("p")
                           .InsertBlank("s_1")
                           .InsertPara("s")
                           .InsertVerse("3")
                           .InsertBlank("verse_1_3")
                           .InsertPara("p")
                           .Insert("\n");

            Assert.IsTrue(newDelta.DeepEquals(expected));
        }
Beispiel #2
0
        private async Task SyncBookAsync(User user, ParatextProject paratextProject, string fileName,
                                         string bookId, Document <Delta> doc)
        {
            await doc.FetchAsync();

            XElement bookTextElem = await LoadBookTextAsync(fileName);

            XElement oldUsxElem = bookTextElem.Element("usx");

            if (oldUsxElem == null)
            {
                throw new InvalidOperationException("Invalid USX data, missing 'usx' element.");
            }
            XElement bookElem = oldUsxElem.Element("book");

            if (bookElem == null)
            {
                throw new InvalidOperationException("Invalid USX data, missing 'book' element.");
            }
            XElement newUsxElem = _deltaUsxMapper.ToUsx((string)oldUsxElem.Attribute("version"),
                                                        (string)bookElem.Attribute("code"), (string)bookElem, doc.Data);

            var revision = (string)bookTextElem.Attribute("revision");

            string bookText;

            if (XNode.DeepEquals(oldUsxElem, newUsxElem))
            {
                bookText = await _paratextService.GetBookTextAsync(user, paratextProject.Id, bookId);
            }
            else
            {
                bookText = await _paratextService.UpdateBookTextAsync(user, paratextProject.Id, bookId, revision,
                                                                      newUsxElem.ToString());
            }

            bookTextElem = XElement.Parse(bookText);

            Delta delta     = _deltaUsxMapper.ToDelta(paratextProject.Id, bookTextElem.Element("usx"));
            Delta diffDelta = doc.Data.Diff(delta);
            await doc.SubmitOpAsync(diffDelta);

            await SaveBookTextAsync(bookTextElem, fileName);
        }
Beispiel #3
0
        public void ToDelta_Note()
        {
            XElement usxElem = Usx("PHM",
                                   Chapter("1"),
                                   Para("p",
                                        Verse("1"),
                                        "This is a verse with a footnote",
                                        Note("f", "+",
                                             Char("fr", "1.1: "),
                                             Char("ft", "Refers to "),
                                             Char("fq", "a footnote"),
                                             ". ",
                                             Char("xt", "John 1:1"),
                                             " and ",
                                             Char("xt", "Mark 1:1"),
                                             "."),
                                        ", so that we can test it."));

            DeltaUsxMapper mapper   = CreateMapper();
            Delta          newDelta = mapper.ToDelta("12345", usxElem);

            var expected = Delta.New()
                           .InsertChapter("1")
                           .InsertVerse("1")
                           .InsertText("This is a verse with a footnote", "verse_1_1")
                           .InsertNote(0, Delta.New()
                                       .InsertChar("1.1: ", "fr")
                                       .InsertChar("Refers to ", "ft")
                                       .InsertChar("a footnote", "fq")
                                       .Insert(". ")
                                       .InsertChar("John 1:1", "xt")
                                       .Insert(" and ")
                                       .InsertChar("Mark 1:1", "xt")
                                       .Insert("."), "f", "+", "verse_1_1")
                           .InsertText(", so that we can test it.", "verse_1_1")
                           .InsertPara("p")
                           .Insert("\n");

            Assert.IsTrue(newDelta.DeepEquals(expected));
        }