예제 #1
0
        private void AddTemplateContainmentTableEntry(IObjectRepository tdb, Table table, Template template, int level)
        {
            int spacing = 0;

            if (level > 1)
            {
                for (int i = 1; i < level; i++)
                {
                    spacing += 144;
                }
            }

            TableRow newRow = new TableRow(
                new TableCell(
                    new Paragraph(
                        new ParagraphProperties(
                            new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TableContentStyle
            },
                            new Indentation()
            {
                Left = new StringValue(spacing.ToString())
            }),
                        DocHelper.CreateAnchorHyperlink(template.Name, template.Bookmark, Properties.Settings.Default.TableLinkStyle))),
                new TableCell(
                    new Paragraph(
                        new ParagraphProperties(
                            new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TableContentStyle
            }),
                        DocHelper.CreateRun(template.TemplateType.Name))),
                new TableCell(
                    new Paragraph(
                        new ParagraphProperties(
                            new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TableContentStyle
            }),
                        DocHelper.CreateRun(template.Oid))));

            table.Append(newRow);

            List <Template> childTemplates = (from tc in template.ChildConstraints
                                              join t in this.allTemplates on tc.ContainedTemplateId equals t.Id
                                              where t.Id != template.Id
                                              orderby t.Name
                                              select t)
                                             .Distinct()
                                             .ToList();

            if (childTemplates != null)
            {
                foreach (Template cTemplate in childTemplates)
                {
                    if (this.parentTemplates.Exists(y => y.Id == cTemplate.Id))
                    {
                        Log.For(this).Warn("Circular reference found when generating containment tables for '{0}' ({1})", cTemplate.Name, cTemplate.Oid);
                        continue;
                    }

                    parentTemplates.Add(cTemplate);

                    AddTemplateContainmentTableEntry(tdb, table, cTemplate, level + 1);

                    parentTemplates.Remove(cTemplate);
                }
            }
        }
예제 #2
0
        private OpenXmlElement Process(XmlReader xmlReader, OpenXmlElement current)
        {
            Paragraph cPara      = current as Paragraph;
            Run       cRun       = current as Run;
            Hyperlink cHyperlink = current as Hyperlink;
            Table     cTable     = current as Table;
            TableRow  cTableRow  = current as TableRow;
            TableCell cTableCell = current as TableCell;

            if (xmlReader.NodeType == XmlNodeType.Element)
            {
                // Do something for elements
                switch (xmlReader.Name)
                {
                case "p":
                    if (cPara != null)
                    {
                        break;
                    }

                    Paragraph newParagraph = new Paragraph(
                        new ParagraphProperties(
                            new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TemplateDescriptionStyle
                    }));
                    return(NewChild(current, newParagraph));

                case "b":
                    if (cPara != null)
                    {
                        Run newRun = new Run();
                        AddBoldToRun(newRun);
                        return(NewChild(current, newRun));
                    }
                    else if (cRun != null)
                    {
                        AddBoldToRun(cRun);
                        return(cRun);
                    }
                    break;

                case "i":
                    if (cPara != null)
                    {
                        Run newRun = new Run();
                        AddItalicsToRun(newRun);
                        return(NewChild(current, newRun));
                    }
                    else if (cRun != null)
                    {
                        AddItalicsToRun(cRun);
                        return(cRun);
                    }
                    break;

                case "a":
                    string    hrefAttr     = xmlReader.GetAttribute("href");
                    Hyperlink newHyperlink = new Hyperlink(
                        new ProofError()
                    {
                        Type = ProofingErrorValues.GrammarStart
                    });

                    if (!string.IsNullOrEmpty(hrefAttr))
                    {
                        Template foundTemplate = null;

                        if (hrefAttr.StartsWith("#") && hrefAttr.Length > 1)
                        {
                            foundTemplate = this.tdb.Templates.SingleOrDefault(y => y.Oid == hrefAttr.Substring(1));
                        }

                        if (foundTemplate != null)
                        {
                            newHyperlink.Anchor = foundTemplate.Bookmark;
                            newHyperlink.Append(
                                DocHelper.CreateRun(
                                    string.Format("{0} ({1})",
                                                  foundTemplate.Name,
                                                  foundTemplate.Oid)));
                        }
                        else
                        {
                            try
                            {
                                HyperlinkRelationship rel = mainPart.AddHyperlinkRelationship(new Uri(hrefAttr), true);
                                newHyperlink.History = true;
                                newHyperlink.Id      = rel.Id;
                            }
                            catch { }
                        }
                    }

                    if (cPara != null)
                    {
                        return(NewChild(current, newHyperlink));
                    }
                    break;

                case "ul":
                    this.currentListLevel++;
                    this.currentListStyle = "ListBullet";

                    if (current is Paragraph)
                    {
                        current = current.Parent;
                    }
                    break;

                case "ol":
                    this.currentListLevel++;
                    this.currentListStyle = "ListNumber";

                    if (current is Paragraph)
                    {
                        current = current.Parent;
                    }
                    break;

                case "li":
                    Paragraph bulletPara = new Paragraph(
                        new ParagraphProperties(
                            new ParagraphStyleId()
                    {
                        Val = this.currentListStyle
                    }));
                    return(NewChild(current, bulletPara));

                case "table":
                    Table newTable = new Table(
                        new TableProperties(),
                        new TableGrid());

                    return(NewChild(current, newTable));

                case "thead":
                    this.currentIsTableHeader = true;
                    break;

                case "tr":
                    if (cTable != null)
                    {
                        TableRow newTableRow = new TableRow();

                        if (this.currentIsTableHeader)
                        {
                            newTableRow.Append(
                                new TableRowProperties(
                                    new CantSplit(),
                                    new TableHeader()));
                        }

                        return(NewChild(current, newTableRow));
                    }
                    break;

                case "td":
                    if (cTableRow != null)
                    {
                        TableCell newCell = new TableCell();

                        if (this.currentIsTableHeader)
                        {
                            newCell.Append(
                                new TableCellProperties()
                            {
                                Shading = new Shading()
                                {
                                    Val   = new EnumValue <ShadingPatternValues>(ShadingPatternValues.Clear),
                                    Color = new StringValue("auto"),
                                    Fill  = new StringValue("E6E6E6")
                                }
                            });
                        }

                        // Cells' contents should be within a paragraph
                        Paragraph newPara = new Paragraph();
                        newCell.AppendChild(newPara);

                        current.Append(newCell);
                        return(newPara);
                    }
                    break;

                case "span":
                    if (cPara != null)
                    {
                        Run newRun = new Run();
                        return(NewChild(current, newRun));
                    }
                    break;

                case "root":
                case "tbody":
                    break;

                default:
                    throw new Exception("Unsupported wiki syntax");
                }
            }
            else if (xmlReader.NodeType == XmlNodeType.Text)
            {
                string text = xmlReader.Value
                              .Replace("&nbsp;", " ");

                if (current is Paragraph || current is TableCell)
                {
                    current.Append(DocHelper.CreateRun(text));
                }
                else if (cHyperlink != null)
                {
                    if (!(cHyperlink.LastChild is Run))
                    {
                        cHyperlink.Append(DocHelper.CreateRun(text));
                    }
                }
                else if (cRun != null)
                {
                    cRun.Append(new Text(text));
                }
            }
            else if (xmlReader.NodeType == XmlNodeType.EndElement)
            {
                if (xmlReader.Name == "thead")
                {
                    this.currentIsTableHeader = false;
                    return(current);
                }
                else if (xmlReader.Name == "tbody")
                {
                    return(current);
                }
                else if (xmlReader.Name == "td")
                {
                    // Expect that we are in a paragraph within a table cell, and when TD ends, we need to return two levels higher
                    if (cPara != null && cPara.Parent is TableCell)
                    {
                        return(current.Parent.Parent);
                    }
                }
                else if (xmlReader.Name == "a")
                {
                    // Make sure all runs within a hyperlink have the correct style
                    foreach (var cChildRun in current.ChildElements.OfType <Run>())
                    {
                        cChildRun.RunProperties.RunStyle = new RunStyle()
                        {
                            Val = Properties.Settings.Default.LinkStyle
                        };
                    }
                }
                else if (xmlReader.Name == "ul")
                {
                    this.currentListLevel--;
                }

                if (current.Parent == null)
                {
                    return(current);
                }

                return(current.Parent);
            }

            return(current);
        }
예제 #3
0
        /// <summary>
        /// Adds a table for the template in question which lists all constraints in separate rows.
        /// </summary>
        public void AddTemplateConstraintTable(Template template, Body documentBody, string templateXpath)
        {
            var constraintCategories  = template.ChildConstraints.Where(y => !string.IsNullOrEmpty(y.Category)).Select(y => y.Category).Distinct();
            var includeCategoryHeader = false;

            if (!this.HasSelectedCategories && constraintCategories.Count() > 0)
            {
                includeCategoryHeader = true;
            }
            else if (this.HasSelectedCategories && this.selectedCategories.Count > 1)
            {
                includeCategoryHeader = true;
            }

            var rootConstraints = template.ChildConstraints.Where(y => y.ParentConstraintId == null);
            List <HeaderDescriptor> lHeaders = new List <HeaderDescriptor>();

            if (includeCategoryHeader)
            {
                lHeaders.Add(new HeaderDescriptor()
                {
                    HeaderName = CATEGORY, AutoResize = true, AutoWrap = false, ColumnWidth = "720"
                });
            }

            lHeaders.Add(new HeaderDescriptor()
            {
                HeaderName = XPATH, AutoResize = true, AutoWrap = false, ColumnWidth = "3445"
            });
            lHeaders.Add(new HeaderDescriptor()
            {
                HeaderName = CARD, AutoResize = false, CellWidth = .5, ColumnWidth = "720"
            });
            lHeaders.Add(new HeaderDescriptor()
            {
                HeaderName = VERB, AutoResize = false, CellWidth = .8, ColumnWidth = "1152"
            });
            lHeaders.Add(new HeaderDescriptor()
            {
                HeaderName = DATA_TYPE, AutoResize = false, CellWidth = .6, ColumnWidth = "864"
            });
            lHeaders.Add(new HeaderDescriptor()
            {
                HeaderName = CONF, AutoResize = false, CellWidth = .6, ColumnWidth = "864"
            });
            lHeaders.Add(new HeaderDescriptor()
            {
                HeaderName = FIXED_VALUE, AutoResize = false, CellWidth = .6, ColumnWidth = "3171"
            });

            Table t = this.tables.AddTable(string.Format("{0} Constraints Overview", template.Name), lHeaders.ToArray());

            TableRow templateRow = new TableRow(
                new TableCell(
                    new TableCellProperties(
                        new GridSpan()
            {
                Val = new Int32Value(includeCategoryHeader ? 7 : 6)
            }),
                    new Paragraph(
                        new ParagraphProperties(
                            new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TableContentStyle
            }),
                        DocHelper.CreateRun(templateXpath))));

            t.Append(templateRow);

            SimpleSchema schema = template.ImplementationGuideType.GetSimpleSchema();

            schema = schema.GetSchemaFromContext(template.PrimaryContextType);

            // Start out creating the first set of rows with root (top-level) constraints (constraints that don't have children)
            foreach (TemplateConstraint cConstraint in rootConstraints.OrderBy(y => y.Order))
            {
                if (this.HasSelectedCategories && !string.IsNullOrEmpty(cConstraint.Category) && !this.selectedCategories.Contains(cConstraint.Category))
                {
                    continue;
                }

                var schemaObject = schema.Children.SingleOrDefault(y => y.Name == cConstraint.Context);

                this.AddTemplateTableConstraint(template, t, cConstraint, 1, includeCategoryHeader, schemaObject);
            }
        }
        /// <summary>
        /// Adds a context table for the template. The context table lists all templates that are used by the current template, as
        /// well as all templates that this current template uses. Templates that use this template also indicate whether they are
        /// required or optional, depending on the conformance of the constraint that uses this template.
        /// </summary>
        /// <param name="template">The template in question</param>
        /// <param name="allConstraints">All constraints for the current template</param>
        private void AddTemplateContextTable()
        {
            TableRow  newRow        = new TableRow();
            TableCell usedByCell    = new TableCell();
            TableCell containedCell = new TableCell();

            var usedByTemplates = (from tc in this.tdb.TemplateConstraints
                                   join te in this.tdb.Templates on tc.TemplateId equals te.Id
                                   where tc.ContainedTemplateId == template.Id && tc.TemplateId != template.Id
                                   orderby tc.Conformance, te.Name
                                   select te)
                                  .Distinct().ToList();
            var containedTemplates = (from ac in allConstraints
                                      join ct in this.tdb.Templates on ac.ContainedTemplateId equals ct.Id
                                      where this.exportedTemplates.Exists(y => y.Id == ct.Id) && ac.ContainedTemplateId != null
                                      orderby ct.Name
                                      select ct)
                                     .Distinct().ToList();

            var usedByTemplatesSelectedForExport    = usedByTemplates.Where(e => this.exportedTemplates.Exists(y => y.Id == e.Id)).ToList();
            var containedTemplatesSelectedForExport = containedTemplates.Where(e => this.exportedTemplates.Exists(y => y.Id == e.Id)).ToList();

            int maxRows = containedTemplatesSelectedForExport.Count > usedByTemplatesSelectedForExport.Count ? containedTemplatesSelectedForExport.Count : usedByTemplatesSelectedForExport.Count;

            for (int i = 0; i < maxRows; i++)
            {
                Paragraph usedByPara = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }));
                Paragraph containedPara = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }));

                Template usedByTemplate    = i < usedByTemplatesSelectedForExport.Count ? usedByTemplatesSelectedForExport[i] : null;
                Template containedTemplate = i < containedTemplatesSelectedForExport.Count ? containedTemplatesSelectedForExport[i] : null;

                // Output the used by template
                if (usedByTemplate != null)
                {
                    List <TemplateConstraint> usedByConstraints = this.tdb.TemplateConstraints.Where(y =>
                                                                                                     y.TemplateId == usedByTemplate.Id &&
                                                                                                     y.ContainedTemplateId == template.Id).ToList();
                    bool isRequired = AreConstraintsRequiredByParents(usedByConstraints);

                    // Output a hyperlink if it is included in this doc, otherwise plain text
                    if (this.exportedTemplates.Exists(y => y.Id == usedByTemplate.Id))
                    {
                        usedByPara.Append(
                            DocHelper.CreateAnchorHyperlink(usedByTemplate.Name, usedByTemplate.Bookmark, Properties.Settings.Default.TableLinkStyle),
                            DocHelper.CreateRun(isRequired ? " (required)" : " (optional)"));
                    }
                    else
                    {
                        usedByPara.Append(
                            DocHelper.CreateRun(usedByTemplate.Name),
                            DocHelper.CreateRun(isRequired ? " (required)" : " (optional)"));
                    }

                    usedByCell.Append(usedByPara);
                }

                // Output the contained template
                if (containedTemplate != null)
                {
                    // Output a hyperlink if it is included in this doc, otherwise plain text
                    if (this.exportedTemplates.Exists(y => y.Id == containedTemplate.Id))
                    {
                        containedPara.Append(
                            DocHelper.CreateAnchorHyperlink(containedTemplate.Name, containedTemplate.Bookmark, Properties.Settings.Default.TableLinkStyle));
                    }
                    else
                    {
                        containedPara.Append(
                            DocHelper.CreateRun(containedTemplate.Name));
                    }

                    containedCell.Append(containedPara);
                }
            }

            // Make sure the cells have at least one paragraph in them
            if (containedCell.ChildElements.Count == 0)
            {
                containedCell.AppendChild(new Paragraph());
            }

            if (usedByCell.ChildElements.Count == 0)
            {
                usedByCell.AppendChild(new Paragraph());
            }

            // Only add the table to the document if there are conatined or used-by relationships
            if (maxRows > 0)
            {
                string[] headers = new string[] { TEMPLATE_CONTEXT_TABLE_USED_BY, TEMPLATE_CONTEXT_TABLE_CONTAINS };
                Table    t       = this.tables.AddTable(string.Format("{0} Contexts", template.Name), headers);

                t.Append(
                    new TableRow(usedByCell, containedCell));
            }
        }
예제 #5
0
        private void AddValueSetDetailTable(ValueSet valueSet, DateTime bindingDate)
        {
            string bookmarkId             = this.GetValueSetBookmark(valueSet);
            List <ValueSetMember> members = valueSet.GetActiveMembers(bindingDate);

            if (members == null || members.Count == 0)
            {
                return;
            }

            TableCell headingCell = new TableCell(
                new TableCellProperties()
            {
                GridSpan = new GridSpan()
                {
                    Val = 4
                }
            },
                new Paragraph(
                    new ParagraphProperties(new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TableContentStyle
            }),
                    DocHelper.CreateRun(
                        string.Format("Value Set: {0} {1}", valueSet.Name, valueSet.Oid))));

            if (!string.IsNullOrEmpty(valueSet.Description))
            {
                headingCell.Append(
                    new Paragraph(
                        new ParagraphProperties(new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                        DocHelper.CreateRun(valueSet.Description)));
            }

            if (!string.IsNullOrEmpty(valueSet.Source))
            {
                headingCell.Append(
                    new Paragraph(
                        new ParagraphProperties(new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                        DocHelper.CreateRun("Value Set Source: "),
                        DocHelper.CreateUrlHyperlink(this.mainPart, valueSet.Source, valueSet.Source, Properties.Settings.Default.LinkStyle)));
            }

            Table t = DocHelper.CreateTable(
                new TableRow(headingCell),
                DocHelper.CreateTableHeader("Code", "Code System", "Code System OID", "Print Name"));

            int maximumMembers = this.defaultMaxMembers;

            if (this.valueSetMaximumMembers != null && this.valueSetMaximumMembers.ContainsKey(valueSet.Oid))
            {
                maximumMembers = this.valueSetMaximumMembers[valueSet.Oid];
            }

            int count = 0;

            foreach (ValueSetMember currentMember in members)
            {
                if (count >= maximumMembers)
                {
                    break;
                }

                TableRow memberRow = new TableRow(
                    new TableCell(
                        new Paragraph(
                            new ParagraphProperties(
                                new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                            DocHelper.CreateRun(currentMember.Code))),
                    new TableCell(
                        new Paragraph(
                            new ParagraphProperties(
                                new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                            DocHelper.CreateRun(currentMember.CodeSystem.Name))),
                    new TableCell(
                        new Paragraph(
                            new ParagraphProperties(
                                new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                            DocHelper.CreateRun(currentMember.CodeSystem.Oid))),
                    new TableCell(
                        new Paragraph(
                            new ParagraphProperties(
                                new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                            DocHelper.CreateRun(currentMember.DisplayName)))
                    );

                t.Append(memberRow);
                count++;
            }

            if (count <= members.Count - 1 || valueSet.IsIncomplete)
            {
                TableRow moreMembersRow = new TableRow(
                    new TableCell(
                        new TableCellProperties()
                {
                    GridSpan = new GridSpan()
                    {
                        Val = 4
                    }
                },
                        new Paragraph(
                            new ParagraphProperties(
                                new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TableContentStyle
                }),
                            DocHelper.CreateRun("..."))));
                t.Append(moreMembersRow);
            }

            this.tables.AddTable(valueSet.Name, t, bookmarkId);
        }
예제 #6
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 status = "Draft";

            if (_exportSettings.IncludeTemplateStatus || !lDirectlyOwnedTemplate || !lStatusMatches || template.Status == PublishStatus.GetDeprecatedStatus(this._tdb))
            {
                status = template.Status != null ? template.Status.Status : status;
            }

            string lTemplateTitle = lTitleBuilder.ToString();

            // Output the title of the template
            Paragraph pHeading = new Paragraph(
                new ParagraphProperties(
                    new ParagraphStyleId()
            {
                Val = headingLevel
            }),
                new Run(
                    new Text(template.Name.Substring(0, 1))),
                new Run(
                    new RunProperties(
                        new BookmarkStart()
            {
                Id = bookmarkId, Name = bookmarkId
            },
                        new BookmarkEnd()
            {
                Id = bookmarkId
            }),
                    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
            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.tables, this._document.MainDocumentPart.Document.Body, template, this._templates);
            }

            // Output the template's description
            if (!string.IsNullOrEmpty(template.Description))
            {
                this.wikiParser.ParseAndAppend(template.Description, this._document.MainDocumentPart.Document.Body);
            }

            // If we were told to generate tables for the template...
            if (_exportSettings.GenerateTemplateConstraintTable)
            {
                this.constraintTableGenerator.AddTemplateConstraintTable(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)DocHelper.CreateAnchorHyperlink(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._settings,
                this._document.MainDocumentPart.Document.Body,
                this._commentManager,
                this.figures,
                this.wikiParser,
                _exportSettings.IncludeXmlSamples,
                _tdb,
                rootConstraints,
                templateConstraints,
                template,
                this._templates,
                Properties.Settings.Default.ConstraintHeadingStyle,
                _exportSettings.SelectedCategories);

            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);
        }
예제 #7
0
        private void LoadDifferencesAsAppendix(string aIgName, List <IGDifferenceViewModel> aDifferences)
        {
            // Create the heading for the appendix
            Paragraph heading = new Paragraph(
                new ParagraphProperties(
                    new ParagraphStyleId()
            {
                Val = Properties.Settings.Default.TemplateTypeHeadingStyle
            }),
                new Run(
                    new Text("Changes from Previous Version")));

            this._document.MainDocumentPart.Document.Body.AppendChild(heading);

            foreach (IGDifferenceViewModel lDifference in aDifferences)
            {
                Paragraph changeHeadingPara = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = Properties.Settings.Default.TemplateHeaderStyle
                }),
                    DocHelper.CreateRun(lDifference.TemplateName));
                this._document.MainDocumentPart.Document.Body.AppendChild(changeHeadingPara);

                Paragraph changeLinkPara = new Paragraph(
                    new ParagraphProperties(new KeepNext()),
                    DocHelper.CreateAnchorHyperlink(
                        string.Format("{0} ({1})", lDifference.TemplateName, lDifference.TemplateOid), lDifference.TemplateBookmark, Properties.Settings.Default.LinkStyle),
                    new Break());
                this._document.MainDocumentPart.Document.Body.AppendChild(changeLinkPara);

                Table t = this.tables.AddTable(null, new string[] { "Change", "Old", "New" });

                // Show template field changes first
                foreach (ComparisonFieldResult lResult in lDifference.Difference.ChangedFields)
                {
                    TableRow memberRow = new TableRow(
                        new TableCell(
                            new Paragraph(
                                new ParagraphProperties(
                                    new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TableContentStyle
                    }),
                                DocHelper.CreateRun(lResult.Name))),
                        new TableCell(
                            new Paragraph(
                                new ParagraphProperties(
                                    new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TableContentStyle
                    }),
                                DocHelper.CreateRun(lResult.Old))),
                        new TableCell(
                            new Paragraph(
                                new ParagraphProperties(
                                    new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TableContentStyle
                    }),
                                DocHelper.CreateRun(lResult.New)))
                        );

                    t.Append(memberRow);
                }

                // Show constraint changes second
                foreach (ComparisonConstraintResult lConstraintChange in lDifference.Difference.ChangedConstraints)
                {
                    if (lConstraintChange.Type == CompareStatuses.Unchanged)
                    {
                        continue;
                    }

                    TableRow memberRow = new TableRow(
                        new TableCell(
                            new Paragraph(
                                new ParagraphProperties(
                                    new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TableContentStyle
                    }),
                                DocHelper.CreateRun(string.Format("CONF #: {0} {1}", lConstraintChange.Number, lConstraintChange.Type)))),
                        new TableCell(
                            new Paragraph(
                                new ParagraphProperties(
                                    new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TableContentStyle
                    }),
                                DocHelper.CreateRun(lConstraintChange.OldNarrative))),
                        new TableCell(
                            new Paragraph(
                                new ParagraphProperties(
                                    new ParagraphStyleId()
                    {
                        Val = Properties.Settings.Default.TableContentStyle
                    }),
                                DocHelper.CreateRun(lConstraintChange.NewNarrative)))
                        );

                    t.Append(memberRow);
                }
            }
        }