Пример #1
0
        public void TestParseAsOpenXML_Bold_then_Italic()
        {
            string testWikiContent = "This *is a bold* test with _italic text as well_";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement body   = parser.ParseAsOpenXML(testWikiContent);

            Assert.AreEqual(1, body.ChildElements.Count);
            Paragraph para = body.ChildElements[0] as Paragraph;

            Assert.IsNotNull(para);

            Assert.AreEqual(5, para.ChildElements.Count);

            Run boldRun = para.ChildElements[2] as Run;

            Assert.IsNotNull(boldRun);
            Assert.IsNotNull(boldRun.RunProperties);
            Assert.IsNotNull(boldRun.RunProperties.Bold);

            Run italicRun = para.ChildElements[4] as Run;

            Assert.IsNotNull(italicRun);
            Assert.IsNotNull(italicRun.RunProperties);
            Assert.IsNotNull(italicRun.RunProperties.Italic);
            AssertOpenXmlValid(body);
        }
Пример #2
0
        public void TestParseAsOpenXML_LinkToURLWithName()
        {
            string testWikiContent = @"This is a test of a [URL:Awesome|http://www.awesome.com]";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement body   = parser.ParseAsOpenXML(testWikiContent);

            Assert.AreEqual(1, body.ChildElements.Count);
            Paragraph para = body.ChildElements[0] as Paragraph;

            Assert.IsNotNull(para);

            Run run = para.ChildElements[1] as Run;

            Assert.IsNotNull(run);
            AssertRunText(run, "This is a test of a ");

            Hyperlink hyperlink = para.ChildElements[2] as Hyperlink;

            Assert.IsNotNull(hyperlink);
            Run hyperlinkRun = hyperlink.LastChild as Run;

            Assert.IsNotNull(hyperlinkRun);
            AssertRunText(hyperlinkRun, "Awesome");

            AssertOpenXmlValid(body);
        }
Пример #3
0
        public void TestParseAsOpenXML_LinkToTemplate()
        {
            string testWikiContent = @"This is a test of a [URL:#" + this.template1.Oid + "]";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement body   = parser.ParseAsOpenXML(testWikiContent);

            Assert.AreEqual(1, body.ChildElements.Count);
            Paragraph para = body.ChildElements[0] as Paragraph;

            Assert.IsNotNull(para);

            Run run = para.ChildElements[1] as Run;

            Assert.IsNotNull(run);
            AssertRunText(run, "This is a test of a ");

            Hyperlink hyperlink = para.ChildElements[2] as Hyperlink;

            Assert.IsNotNull(hyperlink);
            Run hyperlinkRun = hyperlink.LastChild as Run;

            Assert.IsNotNull(hyperlinkRun);
            AssertRunText(hyperlinkRun, "Test Template 1 (1.2.3.4.5)");
            Assert.IsNotNull(hyperlink.Anchor);
            Assert.AreEqual(this.template1.Bookmark, hyperlink.Anchor.Value);

            AssertOpenXmlValid(body);
        }
Пример #4
0
        private ConstraintViewModel BuildConstraint(DB.IObjectRepository tdb, string baseLink,
                                                    IGSettingsManager igSettings, DB.TemplateConstraint dbConstraint, int constraintCount, int?aParentConstraintId = null)
        {
            IFormattedConstraint fc         = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, dbConstraint);
            WIKIParser           wikiParser = new WIKIParser(tdb);

            ConstraintViewModel lGreenViewModel = new ConstraintViewModel()
            {
                constraintLabel    = dbConstraint.Label,
                headingDescription = dbConstraint.HeadingDescription,
                id            = dbConstraint.Id,
                order         = dbConstraint.Order,
                isHeading     = dbConstraint.IsHeading,
                isPrimitive   = dbConstraint.IsPrimitive,
                primitiveText = dbConstraint.PrimitiveText,
                templateId    = dbConstraint.TemplateId,
                number        = dbConstraint.Number,
                text          = fc.GetPlainText(false, false, false),
                conformance   = dbConstraint.Conformance,
                value         = dbConstraint.Value
            };

            lGreenViewModel.constraintDescription = GetConstraintDescription(dbConstraint);

            DB.GreenConstraint lGreenConstraint = dbConstraint.GreenConstraints.DefaultIfEmpty(null).FirstOrDefault();

            if (lGreenConstraint != null)
            {
                lGreenViewModel.Use(c =>
                {
                    c.businessName       = lGreenConstraint.Description;
                    c.elementName        = lGreenConstraint.Name;
                    c.xPath              = lGreenConstraint.RootXpath;
                    c.greenConstraintId  = lGreenConstraint.Id;
                    c.hasGreenConstraint = true;

                    if (lGreenConstraint.ImplementationGuideTypeDataTypeId.HasValue)
                    {
                        c.datatype   = lGreenConstraint.ImplementationGuideTypeDataType.DataTypeName;
                        c.datatypeId = lGreenConstraint.ImplementationGuideTypeDataType.Id;
                    }
                });
            }

            if (aParentConstraintId.HasValue)
            {
                lGreenViewModel.parentConstraintId = aParentConstraintId.Value;
            }

            int nextConstraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.Where(cc => cc.IsPrimitive == false).OrderBy(y => y.Order))
            {
                ConstraintViewModel nextNewConstraint
                    = BuildConstraint(tdb, baseLink, igSettings, cDbConstraint, ++nextConstraintCount, dbConstraint.Id);
                lGreenViewModel.children.Add(nextNewConstraint);
            }

            return(lGreenViewModel);
        }
Пример #5
0
        public void TestParseAsOpenXML_Tables()
        {
            string testWikiContent = @"|| Test Header1 || Test Header2
| TestRowCell1 | TestRowCell2
| TestRowCell3 | TestRowCell4";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement table  = parser.ParseAsOpenXML(testWikiContent);

            this.mainPart.Document.Body.Append(table);

            AssertOpenXmlValid(table);
        }
Пример #6
0
        public void TestParseAsOpenXml_LineBreaks()
        {
            string testWikiContent = @"This is a 
test of 
a line break and a url [URL:http://www.seanmcilvenna.com] with 
another line break";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement body   = parser.ParseAsOpenXML(testWikiContent);

            Assert.AreEqual(4, body.ChildElements.Count);

            AssertOpenXmlValid(body);
        }
Пример #7
0
        public void TestParseAsOpenXML_Bullets()
        {
            string testWikiContent = @"* Test bullet 1
* Test bullet 2
** Test sub-bullet 1
* Test bullet 3

This is a non-bulleted test

* Test a new bullet list
* Test a new bullet list ";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement table  = parser.ParseAsOpenXML(testWikiContent);
        }
        public void PrimitiveTextFormattingTest1()
        {
            var repo = new MockObjectRepository();

            TemplateConstraint newConstraint = new TemplateConstraint()
            {
                Number        = 1234,
                IsPrimitive   = true,
                PrimitiveText = "This entry SHALL contain X which SHALL NOT contain Y"
            };

            var formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(repo, new IGSettingsManager(repo), newConstraint);

            WIKIParser wikiParser = new WIKIParser(repo);
            Document   newDoc     = new Document();

            formattedConstraint.AddToDocParagraph(wikiParser, newDoc, 1, 1, "");
        }
Пример #9
0
        public void TestParseAsOpenXml_MultipleRoots()
        {
            string testWikiContent = @"The US Realm Patient Generated Document header template must conform to the Universal Realm Patient Generated Document header template. This template is designed to be used in conjunction with the US C-CDA General Header. It only includes additional conformances which further constrain the US C-CDA General Header.

|| TableHead 1 || Table Head 2
| Table Cell 1 | Table Cell 2
| Table Cell 3 | Table Cell 4

There is more information here: [URL:#2.16.840.1.113883.10.20.29.1] and [URL:here|http://www.lantanagroup.com] and [URL:http://www.lantanagroup.com]";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement body   = parser.ParseAsOpenXML(testWikiContent);

            Assert.AreEqual(3, body.ChildElements.Count);
            Assert.IsInstanceOfType(body.ChildElements[0], typeof(Paragraph));
            Assert.IsInstanceOfType(body.ChildElements[1], typeof(Table));
            Assert.IsInstanceOfType(body.ChildElements[2], typeof(Paragraph));

            AssertOpenXmlValid(body);
        }
Пример #10
0
        public void TestParseAsOpenXml_InvalidContent()
        {
            Assert.Inconclusive("This test used to represent expected failures. The improvements to the WIKI parser make what was previously *not working*, now *working*. So, the test is no longer conclusive. If other examples are found of things that we expect not to convert between WIKI/HTML and OpenXML, this test should be updated");
            string testWikiContent = @"|| Table header 1 || Table header 2
| [URL:http://www.seanmcilvenna.com] | Table Cell 5";

            WIKIParser     parser = new WIKIParser(this.tdb, this.mainPart);
            OpenXmlElement body   = parser.ParseAsOpenXML(testWikiContent);

            Assert.AreEqual(1, body.ChildElements.Count);
            Paragraph para = body.ChildElements[0] as Paragraph;

            Assert.IsNotNull(para);
            Assert.AreEqual(1, para.ChildElements.Count);
            Run run = para.ChildElements[0] as Run;

            Assert.IsNotNull(run);
            AssertRunText(run, testWikiContent);

            AssertOpenXmlValid(body);
        }
Пример #11
0
        public string GetHtml(WIKIParser parser, string linkBase, int constraintCount, bool includeLabel)
        {
            StringBuilder sb = new StringBuilder();

            foreach (ConstraintPart cPart in this.parts)
            {
                switch (cPart.PartType)
                {
                case ConstraintPart.PartTypes.Keyword:
                case ConstraintPart.PartTypes.Context:
                case ConstraintPart.PartTypes.Template:
                case ConstraintPart.PartTypes.Vocabulary:
                case ConstraintPart.PartTypes.Constraint:
                    sb.Append("<b>" + cPart.Text + "</b>");
                    break;

                case ConstraintPart.PartTypes.Link:
                    sb.Append(string.Format("<a href=\"{0}{1}\">{2}</a>", linkBase, cPart.LinkDestination, cPart.Text));
                    break;

                case ConstraintPart.PartTypes.PrimitiveText:
                    sb.Append(parser.ParseAsHtml(cPart.Text));
                    break;

                default:
                    sb.Append(cPart.Text);
                    break;
                }
            }

            if (includeLabel && !string.IsNullOrEmpty(this.Label))
            {
                string additionalLabel = string.Format("<br/>Note: {0}", this.Label);
                sb.Append(additionalLabel);
            }

            return(sb.ToString());
        }
Пример #12
0
        private PublishConstraint BuildConstraint(DB.IObjectRepository tdb, string baseLink,
                                                  IGSettingsManager igSettings, DB.TemplateConstraint dbConstraint, int constraintCount, int?aParentConstraintId = null)
        {
            IFormattedConstraint fc         = FormattedConstraintFactory.NewFormattedConstraint(tdb, igSettings, dbConstraint);
            WIKIParser           wikiParser = new WIKIParser(tdb);

            PublishConstraint newConstraint = new PublishConstraint(dbConstraint, fc);

            foreach (DB.TemplateConstraintSample lSample in dbConstraint.Samples)
            {
                ConstraintSample lSampleView = new ConstraintSample()
                {
                    Id           = lSample.Id,
                    Name         = lSample.Name,
                    SampleText   = lSample.SampleText,
                    ConstraintId = dbConstraint.Id
                };
                newConstraint.Samples.Add(lSampleView);
            }

            if (aParentConstraintId.HasValue)
            {
                newConstraint.ParentConstraintId = aParentConstraintId.Value;
            }

            int nextConstraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint in dbConstraint.ChildConstraints.OrderBy(y => y.Order))
            {
                PublishConstraint nextNewConstraint
                    = BuildConstraint(tdb, baseLink, igSettings, cDbConstraint, ++nextConstraintCount, dbConstraint.Id);
                newConstraint.ChildConstraints.Add(nextNewConstraint);
            }

            return(newConstraint);
        }
Пример #13
0
 internal static string HtmlFormatDescriptiveText(WIKIParser parser, string text)
 {
     return(parser.ParseAsHtml(text));
 }
Пример #14
0
        public Paragraph AddToDocParagraph(WIKIParser wikiParser, OpenXmlElement parent, int level, int id, string headingStyle)
        {
            // Add the heading
            if (this.IsHeading && !string.IsNullOrEmpty(this.Context))
            {
                Paragraph pHeading = new Paragraph(
                    new ParagraphProperties(
                        new ParagraphStyleId()
                {
                    Val = headingStyle
                }),
                    DocHelper.CreateRun(this.Context));
                parent.Append(pHeading);

                if (!string.IsNullOrEmpty(this.HeadingDescription))
                {
                    OpenXmlElement parsedHeadingDescription = wikiParser.ParseAsOpenXML(this.HeadingDescription);

                    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 = wikiParser.ParseAsOpenXML(this.Description);

                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:
                    para.Append(
                        DocHelper.CreateAnchorHyperlink(cPart.Text, cPart.LinkDestination, Properties.Settings.Default.LinkStyle));
                    break;

                case ConstraintPart.PartTypes.Constraint:
                    para.Append(
                        DocHelper.CreateRun(cPart.Text, (cPart.IsAnchor ? "C_" + this.Number : string.Empty)));
                    break;

                case ConstraintPart.PartTypes.PrimitiveText:
                    wikiParser.ParseAndAppend(cPart.Text, para, true);
                    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 Break());
                para.AppendChild(
                    DocHelper.CreateRun(additionalLabel));
            }

            parent.Append(para);

            return(para);
        }