Esempio n. 1
0
        /// <summary>
        /// Outputs a primary heading for the template type followed by each of the templates within
        /// the template type (defined by the templates parameter).
        /// </summary>
        /// <param name="typeName">The template type's name</param>
        /// <param name="detailsText">The details text describing the template type.</param>
        /// <param name="templates">The templates contained within the template type for this ig.</param>
        private void AddTemplateTypeSection(string typeName, string detailsText, List <Template> templates)
        {
            var notRetiredTemplates = templates.Where(y => y.Status != this.retiredStatus);

            if (notRetiredTemplates.Count() > 0)
            {
                // Add a Entry Level Templates heading
                Paragraph entryLevelHeading = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TemplateTypeHeadingStyle
                }),
                    new Run(
                        new Text(typeName)));
                this.document.MainDocumentPart.Document.Body.AppendChild(entryLevelHeading);

                if (!string.IsNullOrEmpty(detailsText))
                {
                    OpenXmlElement element = detailsText.MarkdownToOpenXml(this._tdb, this.document.MainDocumentPart);
                    OpenXmlHelper.Append(element, this.document.MainDocumentPart.Document.Body);
                }

                if (typeName.ToLower() == "document-level templates")
                {
                    RequiredAndOptionalSectionsTableGenerator.Append(this._tdb, this.tables, this.hyperlinkTracker, this.templates);
                }

                foreach (Template cTemplate in notRetiredTemplates)
                {
                    this.AddTemplate(cTemplate);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Outputs a primary heading for the template type followed by each of the templates within
        /// the template type (defined by the templates parameter).
        /// </summary>
        /// <param name="typeName">The template type's name</param>
        /// <param name="detailsText">The details text describing the template type.</param>
        /// <param name="templates">The templates contained within the template type for this ig.</param>
        private void AddTemplateTypeSection(IGSettingsManager.IGTemplateType templateType, List <Template> templates)
        {
            var notRetiredTemplates = templates.Where(y => y.Status != this.retiredStatus);

            if (notRetiredTemplates.Count() > 0)
            {
                // Add a Entry Level Templates heading
                Paragraph entryLevelHeading = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TemplateTypeHeadingStyle
                }),
                    new Run(
                        new Text(templateType.Name)));
                this.document.MainDocumentPart.Document.Body.AppendChild(entryLevelHeading);

                if (!string.IsNullOrEmpty(templateType.DetailsText))
                {
                    OpenXmlElement element = templateType.DetailsText.MarkdownToOpenXml(this._tdb, this.document.MainDocumentPart);
                    OpenXmlHelper.Append(element, this.document.MainDocumentPart.Document.Body);
                }

                // Generate the required and optional sections document table overview if the export settings indicate
                // it should be generated AND provide both a document and section template type id
                bool generateRandOSectionsTable =
                    this.exportSettings.GenerateRequiredAndOptionalSectionsTable &&
                    this.exportSettings.DocumentTemplateTypeId != null &&
                    this.exportSettings.SectionTemplateTypeId != null &&
                    this.exportSettings.DocumentTemplateTypeId == templateType.TemplateTypeId;

                if (generateRandOSectionsTable)
                {
                    RequiredAndOptionalSectionsTableGenerator.Append(
                        this._tdb,
                        this.tables,
                        this.hyperlinkTracker,
                        this.templates,
                        this.exportSettings.DocumentTemplateTypeId.Value,
                        this.exportSettings.SectionTemplateTypeId.Value);
                }

                foreach (Template cTemplate in notRetiredTemplates)
                {
                    this.AddTemplate(cTemplate);
                }
            }
        }
Esempio n. 3
0
        public Paragraph AddToDocParagraph(MainDocumentPart mainPart, HyperlinkTracker hyperlinkTracker, OpenXmlElement parent, int level, int id, string headingStyle)
        {
            // Add the heading
            if (this.IsHeading && !string.IsNullOrEmpty(this.Context))
            {
                string headingTitle = this.Context;

                if (!string.IsNullOrEmpty(this.Category))
                {
                    headingTitle += " for " + this.Category;
                }

                Paragraph pHeading = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = headingStyle
                }),
                    DocHelper.CreateRun(headingTitle));
                parent.Append(pHeading);

                if (!string.IsNullOrEmpty(this.HeadingDescription))
                {
                    OpenXmlElement parsedHeadingDescription = this.HeadingDescription.MarkdownToOpenXml(this.tdb, mainPart);

                    if (parsedHeadingDescription != null)
                    {
                        foreach (OpenXmlElement cParsedChild in parsedHeadingDescription.ChildElements)
                        {
                            OpenXmlElement cClonedParsedChild = cParsedChild.CloneNode(true);
                            this.ApplyStyleToElement(cClonedParsedChild);
                            parent.Append(cClonedParsedChild);
                        }
                    }
                }
            }

            // Add the description above the constraint definition
            if (!string.IsNullOrEmpty(this.Description))
            {
                OpenXmlElement parsedDescription = this.Description.MarkdownToOpenXml(this.tdb, mainPart);

                if (parsedDescription != null)
                {
                    foreach (OpenXmlElement cParsedChild in parsedDescription.ChildElements)
                    {
                        OpenXmlElement cClonedParsedChild = cParsedChild.CloneNode(true);
                        this.ApplyStyleToElement(cClonedParsedChild);
                        parent.Append(cClonedParsedChild);
                    }
                }
            }

            // Add the constraint definition
            Paragraph para = new Paragraph(
                new ParagraphProperties(
                    new NumberingProperties(
                        new NumberingLevelReference()
            {
                Val = level
            },
                        new NumberingId()
            {
                Val = id
            })));

            foreach (ConstraintPart cPart in this.parts)
            {
                switch (cPart.PartType)
                {
                case ConstraintPart.PartTypes.Keyword:
                    para.Append(
                        DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.ConformanceVerbStyle));
                    break;

                case ConstraintPart.PartTypes.Context:
                    para.Append(
                        DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.ConstraintContextStyle));
                    break;

                case ConstraintPart.PartTypes.Template:
                    para.Append(
                        DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.TemplateOidStyle));
                    break;

                case ConstraintPart.PartTypes.Vocabulary:
                    para.Append(
                        DocHelper.CreateRun(cPart.Text, style: Properties.Settings.Default.VocabularyConstraintStyle));
                    break;

                case ConstraintPart.PartTypes.Link:
                    hyperlinkTracker.AddHyperlink(para, cPart.Text, cPart.LinkDestination, Properties.Settings.Default.LinkStyle);
                    break;

                case ConstraintPart.PartTypes.Constraint:
                    var newRun = DocHelper.CreateRun(cPart.Text);

                    if (cPart.IsAnchor)
                    {
                        hyperlinkTracker.AddAnchorAround(para, "C_" + this.Number, newRun);
                    }
                    else
                    {
                        para.Append(newRun);
                    }

                    break;

                case ConstraintPart.PartTypes.PrimitiveText:
                    var element = cPart.Text.MarkdownToOpenXml(this.tdb, mainPart, styleKeywords: true);
                    OpenXmlHelper.Append(element, para);
                    break;

                default:
                    para.Append(
                        DocHelper.CreateRun(cPart.Text));
                    break;
                }
            }

            // Add the label after a line break on the run to the paragraph
            if (!string.IsNullOrEmpty(this.Label))
            {
                string additionalLabel = string.Format("Note: {0}", this.Label);
                para.AppendChild(
                    new Run(
                        new Break()));
                para.AppendChild(
                    DocHelper.CreateRun(additionalLabel));
            }

            parent.Append(para);

            return(para);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a single template to the implementation guide document.
        /// </summary>
        /// <param name="template">The template to add to the document</param>
        private void AddTemplate(Template template)
        {
            Log.For(this).Trace("BEGIN: Adding template '{0}'.", template.Oid);

            List <TemplateConstraint> templateConstraints = (from tc in this._tdb.TemplateConstraints
                                                             where tc.TemplateId == template.Id
                                                             select tc).ToList();
            List <TemplateConstraint> rootConstraints = templateConstraints
                                                        .Where(y => y.ParentConstraintId == null)
                                                        .OrderBy(y => y.Order)
                                                        .ToList();
            GreenTemplate greenTemplate      = template.GreenTemplates.FirstOrDefault();
            string        bookmarkId         = template.Bookmark;
            string        templateIdentifier = string.Format("identifier: {0}", template.Oid);

            if (!string.IsNullOrEmpty(template.PrimaryContext))
            {
                templateIdentifier = string.Format("{0} (identifier: {1})", template.PrimaryContext, template.Oid);
            }

            this.templateCount++;

            string headingLevel = Properties.Settings.Default.TemplateHeaderStyle;

            if (exportSettings.AlphaHierarchicalOrder && template.ImpliedTemplateId != null && this.templates.Exists(y => y.Id == template.ImpliedTemplateId))
            {
                headingLevel = Properties.Settings.Default.TemplateHeaderSecondLevelStyle;
            }

            StringBuilder lTitleBuilder = new StringBuilder(string.Format("{0}", template.Name.Substring(1)));

            bool lDirectlyOwnedTemplate = template.OwningImplementationGuideId == this.implementationGuide.Id;
            bool lStatusMatches         = template.StatusId == template.OwningImplementationGuide.PublishStatusId;

            string lTemplateTitle = lTitleBuilder.ToString();

            // Output the title of the template
            Paragraph pHeading = new Paragraph(
                new ParagraphProperties(
                    new ParagraphStyleId()
            {
                Val = headingLevel
            }));

            this.hyperlinkTracker.AddAnchorAround(pHeading, bookmarkId,
                                                  new Run(
                                                      new Text(template.Name.Substring(0, 1))),
                                                  new Run(
                                                      new Text(lTemplateTitle)));

            if (!string.IsNullOrEmpty(template.Notes) && this.exportSettings.IncludeNotes)
            {
                this.commentManager.AddCommentRange(pHeading, template.Notes);
            }

            this.document.MainDocumentPart.Document.Body.AppendChild(pHeading);

            // Output the "bracket data" for the template
            string detailsText = string.Format("identifier: {0} ({1})", template.Oid, template.IsOpen == true ? "open" : "closed");

            if (!string.IsNullOrEmpty(template.PrimaryContext))
            {
                detailsText = string.Format("[{0}: identifier {1} ({2})]",
                                            template.PrimaryContext,
                                            template.Oid,
                                            template.IsOpen == true ? "open" : "closed");
            }

            Paragraph pDetails = new Paragraph(
                new ParagraphProperties(
                    new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TemplateLocationStyle
            }),
                DocHelper.CreateRun(detailsText));

            this.document.MainDocumentPart.Document.Body.AppendChild(pDetails);

            //Output IG publish/draft info with "bracket data" format
            if (exportSettings.IncludeTemplateStatus)
            {
                string status = template.Status != null ? template.Status.Status : "Draft";
                string igText = string.Format("{0} as part of {1}", status, template.OwningImplementationGuide.GetDisplayName());

                Paragraph igDetails = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TemplateLocationStyle
                }),
                    DocHelper.CreateRun(igText));
                this.document.MainDocumentPart.Document.Body.AppendChild(igDetails);
            }

            // If we were told to generate context tables for the template...
            if (exportSettings.GenerateTemplateContextTable)
            {
                TemplateContextTable.AddTable(this._tdb, this.templateRelationships, this.tables, this.document.MainDocumentPart.Document.Body, template, this.templates, this.hyperlinkTracker);
            }

            // Output the template's descriptionz
            if (!string.IsNullOrEmpty(template.Description))
            {
                OpenXmlElement element = template.Description.MarkdownToOpenXml(this._tdb, this.document.MainDocumentPart);
                OpenXmlHelper.Append(element, this.document.MainDocumentPart.Document.Body);
            }

            // If we were told to generate tables for the template...
            if (exportSettings.GenerateTemplateConstraintTable)
            {
                this.constraintTableGenerator.AddTemplateConstraintTable(this.schema, template, this.document.MainDocumentPart.Document.Body, templateIdentifier);
            }

            if (templateConstraints.Count(y => y.IsHeading) > 0)
            {
                Paragraph propertiesHeading = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.PropertiesHeadingStyle
                }),
                    DocHelper.CreateRun("Properties"));
                this.document.MainDocumentPart.Document.Body.AppendChild(propertiesHeading);
            }

            // Output the implied template conformance line
            if (template.ImpliedTemplate != null)
            {
                OpenXmlElement templateReference = !this.templates.Contains(template.ImpliedTemplate) ?
                                                   (OpenXmlElement)DocHelper.CreateRun(template.ImpliedTemplate.Name) :
                                                   (OpenXmlElement)this.hyperlinkTracker.CreateHyperlink(template.ImpliedTemplate.Name, template.ImpliedTemplate.Bookmark, Properties.Settings.Default.LinkStyle);

                Paragraph impliedConstraint = new Paragraph(
                    new ParagraphProperties(
                        new NumberingProperties(
                            new NumberingLevelReference()
                {
                    Val = 0
                },
                            new NumberingId()
                {
                    Val = GenerationConstants.BASE_TEMPLATE_INDEX + (int)template.Id
                })),
                    DocHelper.CreateRun("Conforms to "),
                    templateReference,
                    DocHelper.CreateRun(" template "),
                    DocHelper.CreateRun("(identifier: " + template.ImpliedTemplate.Oid + ")", style: Properties.Settings.Default.TemplateOidStyle),
                    DocHelper.CreateRun("."));
                this.document.MainDocumentPart.Document.Body.Append(impliedConstraint);
            }

            bool lCreateValueSetTables = exportSettings.DefaultValueSetMaxMembers > 0;

            IConstraintGenerator constraintGenerator = ConstraintGenerationFactory.NewConstraintGenerator(
                this.igSettings,
                this.document.MainDocumentPart,
                this.commentManager,
                this.figures,
                exportSettings.IncludeXmlSamples,
                _tdb,
                rootConstraints,
                templateConstraints,
                template,
                this.templates,
                Properties.Settings.Default.ConstraintHeadingStyle,
                exportSettings.SelectedCategories,
                this.hyperlinkTracker);

            constraintGenerator.GenerateConstraints(lCreateValueSetTables, this.exportSettings.IncludeNotes);

            // Add value-set tables
            if (lCreateValueSetTables)
            {
                var constraintValueSets = (from c in templateConstraints
                                           where c.ValueSet != null
                                           select new { ValueSet = c.ValueSet, ValueSetDate = c.ValueSetDate })
                                          .Distinct();

                foreach (var cConstraintValueSet in constraintValueSets)
                {
                    DateTime?bindingDate = cConstraintValueSet.ValueSetDate != null ? cConstraintValueSet.ValueSetDate : this.implementationGuide.PublishDate;

                    if (bindingDate == null)
                    {
                        bindingDate = DateTime.Now;
                    }

                    this.valueSetsExport.AddValueSet(cConstraintValueSet.ValueSet, bindingDate.Value);
                }
            }

            if (exportSettings.IncludeXmlSamples)
            {
                foreach (var lSample in template.TemplateSamples.OrderBy(y => y.Id))
                {
                    this.figures.AddSample(lSample.Name, lSample.XmlSample);
                }
            }

            Log.For(this).Trace("END: Adding template '{0}' with {1} constraints.", template.Oid, templateConstraints.Count);
        }