public async Task <byte[]> Render(ObjectId documentID, RenderSettings renderSettings) { try { var document = await documentService.GetDocumentByID(documentID).ConfigureAwait(false); var documentStructure = await documentStructureService.GetDocumentStructureAsync(documentID) .ConfigureAwait(false); if (document is null || documentStructure is null) { throw new ArgumentException("Not all information collected for this document ID"); } DocumentElementRenderDto dto = new DocumentElementRenderDto(documentStructure.Items[0]); GetRenderElements(documentStructure.Items[0], dto); return(await new WordRenderer(renderSettings, document, dto.InnerElements).Render() .ConfigureAwait(false)); } catch (Exception ex) when(ex.GetType() != typeof(ArgumentException)) { exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration); throw new DatabaseException("Error occurred while rendering WORD document"); } }
private void UploadItemsToTableOfContents(DocumentElementRenderDto element, SdtContentBlock sdtContentBlock, int depth, string index) { AddTableOfContentsElement(sdtContentBlock, depth, index + ". " + element.Name); string dopIndex = "0"; if (element.InnerElements is {})
private void AddCommandsToList(DocumentElementRenderDto element, int depth, string index) { if (depth == 0) { CommandsContainer.Add(new ItemHeaderCommand(WordDocument, index + ". " + element.Name, renderData)); } else { CommandsContainer.Add(new ParagraphHeaderCommand(WordDocument, index + " " + element.Name, depth, renderData)); } if (element.InnerElements is {})
private void GetRenderElements(Item item, DocumentElementRenderDto parentElement) { if (item.ItemStatus.ItemType == ItemType.Content) { var documentElements = item.ElementsIds.Select(id => documentElementService.GetCurrentDocumentElement(id).GetAwaiter().GetResult()); parentElement.Elements.AddRange(documentElements); } else if (item.ItemStatus.ItemType == ItemType.Item) { parentElement.InnerElements.AddRange(item.Items.Select(it => new DocumentElementRenderDto(it))); for (int i = 0; i < item.Items.Count; ++i) { GetRenderElements(item.Items[i], parentElement.InnerElements[i]); } } }