Пример #1
0
        private void AnalyzeMainPart(DqMainPart dqMainPart, DqDocument dqDocument)
        {
            foreach (var dqParagraph in dqMainPart.Paragraphs)
            {
                AnalyzeMainPartParagraph(dqParagraph, dqDocument);
            }

            foreach (var chapter in dqMainPart.Children)
            {
                var dqParagraph = chapter.Start;
                if (!dqParagraph.Text.StartsWith("{PageBreak}") && !dqDocument.Paragraphs[dqParagraph.Index - 1].Text.EndsWith("{PageBreak}"))
                {
                    dqParagraph.Meta.Errors.Add(new DqError("Перед разделом отсутсвует разрыв страницы."));
                }
            }
        }
Пример #2
0
        public DqStructure PrimaryParse(DqDocument document)
        {
            var partTypeByTitle = TitlesByPartType
                                  .SelectMany(kv => kv.Value.Select(v => (kv.Key, v)))
                                  .ToDictionary(kv => kv.v, kv => kv.Key);

            var partStart = 0;

            var dqParts = new List <DqPart>();

            while (true)
            {
                var nextPartStart = TryFindByTitle(document, partTypeByTitle.Keys, partStart);
                if (nextPartStart == null)
                {
                    break;
                }

                var start = document.Paragraphs[nextPartStart.Value];
                dqParts.Add(new DqPart
                {
                    Type  = partTypeByTitle[start.GetPureText().ToLower()],
                    Start = start,
                });

                partStart = nextPartStart.Value;
            }

            for (var i = 0; i < dqParts.Count - 1; ++i)
            {
                var dqPart = dqParts[i];
                dqPart.Paragraphs.AddRange(document.Paragraphs.GetRange(dqPart.Start.Index, dqParts[i + 1].Start.Index - dqPart.Start.Index));
            }

            if (!dqParts.Any())
            {
                var mainPart = new DqMainPart();
                mainPart.Paragraphs.AddRange(document.Paragraphs);
                mainPart.Start = document.Paragraphs.First();
                return(new DqStructure {
                    MainPart = mainPart
                });
            }

            var lastPart = dqParts.Last();

            lastPart.Paragraphs.AddRange(document.Paragraphs.GetRange(lastPart.Start.Index, document.Paragraphs.Count - lastPart.Start.Index));

            var report = new DqStructure();

            report.Title = CopyContent(new DqPart
            {
                Type  = PartType.Title,
                Start = document.Paragraphs.First()
            }, document, 0, dqParts.First().Start.Index);

            foreach (var dqPart in dqParts)
            {
                switch (dqPart.Type)
                {
                case PartType.Abstract:
                    report.Abstracts.Add(dqPart);
                    break;

                case PartType.Toc:
                    report.Toc = dqPart;
                    break;

                case PartType.Introduction:
                    report.Introduction = dqPart;
                    break;

                case PartType.Conclusion:
                    report.Conclusion = dqPart;
                    break;

                case PartType.Bibliography:
                    report.Bibliography = dqPart;
                    break;

                case PartType.Annex:
                    report.Appendixes = dqPart;
                    break;
                }
            }

            return(report);
        }