示例#1
0
        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");
            }
        }
示例#2
0
        private void UploadItemsToTableOfContents(DocumentElementRenderDto element, SdtContentBlock sdtContentBlock,
                                                  int depth, string index)
        {
            AddTableOfContentsElement(sdtContentBlock, depth, index + ". " + element.Name);

            string dopIndex = "0";

            if (element.InnerElements is {})
示例#3
0
        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 {})
示例#4
0
        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]);
                }
            }
        }