Exemplo n.º 1
0
        public async Task <ImportResultDto> Upload()
        {
            var fileContent = await _fileUploadUtility.GetUploadFileContent(Request);

            var importResult = await _bookImporter.Import(fileContent);

            return(new ImportResultDto
            {
                ErrorsCount = importResult.ErrorMessages.Count,
                ErrorMessages = importResult.ErrorMessages.Take(20).ToList(), // send max 20 error messages
            });
        }
Exemplo n.º 2
0
        private bool FillInBookChildren(TreeNode bookNode)
        {
            IScrBook book    = bookNode.Tag as IScrBook;
            int      bookNum = (book == null) ? (int)bookNode.Tag : book.CanonicalNum;
            Form     owner   = FindForm();

            while (owner != null && !owner.Visible)
            {
                owner = owner.Owner;
            }
            if (owner == null)
            {
                owner = Form.ActiveForm ?? Application.OpenForms[0];
            }

            if (book == null || (m_associatedPtText != null && m_associatedPtText.BookPresent(book.CanonicalNum) &&
                                 !m_associatedPtText.IsCheckSumCurrent(book.CanonicalNum, book.ImportedCheckSum)))
            {
                // The book for this node is out-of-date with the Paratext book data
                IScrBook importedBook = m_bookImporter.Import(bookNum, owner, false);
                if (importedBook != null)
                {
                    bookNode.Tag = book = importedBook;
                }
                if (book == null)
                {
                    return(false);
                }
            }

            if (m_associatedPtText != null)
            {
                ScrText btProject = ParatextHelper.GetBtsForProject(m_associatedPtText).FirstOrDefault();
                if (btProject != null && !btProject.IsCheckSumCurrent(book.CanonicalNum,
                                                                      book.ImportedBtCheckSum.get_String(book.Cache.DefaultAnalWs).Text))
                {
                    // The BT for this book node is out-of-date with the Paratext BT data
                    m_bookImporter.Import(bookNum, owner, true);
                }
            }

            bookNode.Nodes.Clear();             // Gets rid of dummy.
            //IScrBook book = (IScrBook)bookNode.Tag;
            // Add Title node.
            if (book.TitleOA != null)
            {
                TreeNode titleNode =
                    new TreeNode(ResourceHelper.GetResourceString("kstidScriptureTitle"));
                titleNode.Name = book.TitleOA.ToString();
                titleNode.Tag  = book.TitleOA;
                bookNode.Nodes.Add(titleNode);
            }

            // Add Sections.
            foreach (IScrSection section in book.SectionsOS)
            {
                string chapterVerseBridge = m_scr.ChapterVerseBridgeAsString(section);
                if (section.HeadingOA != null)
                {
                    // Include the heading text if it's not empty.  See LT-8764.
                    int cTotal = 0;
                    foreach (IScrTxtPara para in section.HeadingOA.ParagraphsOS)
                    {
                        cTotal += para.Contents.Length;
                    }
                    if (cTotal > 0)
                    {
                        string   sFmt = ResourceHelper.GetResourceString("kstidSectionHeading");
                        TreeNode node = new TreeNode(String.Format(sFmt, chapterVerseBridge));
                        node.Name = String.Format(sFmt, section);
                        node.Tag  = section.HeadingOA;                        // expect an StText
                        bookNode.Nodes.Add(node);
                    }
                }
                TreeNode sectionNode = new TreeNode(chapterVerseBridge);
                sectionNode.Name = section.ToString();
                sectionNode.Tag  = section.ContentOA;                // expect an StText
                bookNode.Nodes.Add(sectionNode);
            }

            // Add Footnotes in reverse order, so we can insert them in the proper order.
            List <IScrFootnote> footnotes = new List <IScrFootnote>(book.FootnotesOS);

            footnotes.Reverse();
            foreach (IScrFootnote scrFootnote in footnotes)
            {
                // insert under the relevant section, if any (LTB-408)
                IScrSection containingSection;
                IStText     containingTitle = null;
                if (scrFootnote.TryGetContainingSection(out containingSection) ||
                    scrFootnote.TryGetContainingTitle(out containingTitle))
                {
                    string   nodeName     = m_scr.ContainingRefAsString(scrFootnote);
                    TreeNode footnoteNode = new TreeNode(nodeName);
                    footnoteNode.Tag  = scrFootnote;
                    footnoteNode.Name = "Footnote";

                    // see if we can lookup the node of this section.
                    int nodeIndex = bookNode.Nodes.IndexOfKey(
                        containingSection != null ? containingSection.ToString() : containingTitle.ToString());
                    //TreeNode[] sectionNodes = bookNode.Nodes.Find(hvoSection.ToString(), false);
                    //if (sectionNodes != null && sectionNodes.Length > 0)
                    if (nodeIndex >= 0)
                    {
                        bookNode.Nodes.Insert(nodeIndex + 1, footnoteNode);
                    }
                    else
                    {
                        bookNode.Nodes.Add(footnoteNode);                               // insert at end.
                    }
                }
            }
            return(true);
        }