public void UnloadDocument()
        {
            _svgFilePath = "";

            testTitle.Text      = "";
            testDescrition.Text = "";
            testFilePath.Text   = "";

            _testCase = null;

            btnFilePath.IsEnabled = false;

            testDetailsDoc.Blocks.Clear();

            if (this.NavigationService != null && this.NavigationService.CanGoBack)
            {
                this.NavigationService.GoBack();
                this.NavigationService.RemoveBackEntry();
            }
        }
        private bool LoadFile(Stream stream, SvgTestInfo testInfo)
        {
            Regex rgx = new Regex("\\s+");

            testTitle.Text      = testInfo.Title;
            testDescrition.Text = rgx.Replace(testInfo.Description, " ").Trim();
            testFilePath.Text   = _svgFilePath;

            btnFilePath.IsEnabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace             = false;
            settings.IgnoreComments               = true;
            settings.IgnoreProcessingInstructions = true;
            settings.DtdProcessing = DtdProcessing.Parse;

            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                if (reader.ReadToFollowing("SVGTestCase"))
                {
                    _testCase = new SvgTestCase();

                    while (reader.Read())
                    {
                        string      nodeName = reader.Name;
                        XmlNodeType nodeType = reader.NodeType;
                        if (nodeType == XmlNodeType.Element)
                        {
                            if (string.Equals(nodeName, "OperatorScript", StringComparison.OrdinalIgnoreCase))
                            {
                                string revisionText = reader.GetAttribute("version");
                                if (!string.IsNullOrWhiteSpace(revisionText))
                                {
                                    revisionText       = revisionText.Replace("$", "");
                                    _testCase.Revision = revisionText.Trim();
                                }
                                string nameText = reader.GetAttribute("testname");
                                if (!string.IsNullOrWhiteSpace(nameText))
                                {
                                    _testCase.Name = nameText.Trim();
                                }
                            }
                            else if (string.Equals(nodeName, "Paragraph", StringComparison.OrdinalIgnoreCase))
                            {
                                string inputText = reader.ReadInnerXml();
                                string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                if (_useConverter)
                                {
                                    StringReader stringReader = new StringReader(xamlText);
                                    XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                    Section nextSection = (Section)XamlReader.Load(xmlReader);

                                    testDetailsDoc.Blocks.Add(nextSection);
                                }
                                else
                                {
                                    Section   pageSession = new Section();
                                    Paragraph nextPara    = new Paragraph();
                                    //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                    string paraText = rgx.Replace(inputText, " ").Trim();
                                    nextPara.Inlines.Add(new Run(paraText));
                                    pageSession.Blocks.Add(nextPara);

                                    testDetailsDoc.Blocks.Add(pageSession);
                                }

                                _testCase.Paragraphs.Add(inputText);
                            }
                        }
                        else if (nodeType == XmlNodeType.EndElement &&
                                 string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                        {
                            break;
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #3
0
        private bool LoadFile(Stream stream, SvgTestInfo testInfo)
        {
            testDetailsDoc.Blocks.Clear();

            Regex rgx = new Regex("\\s+");

            testTitle.Text      = testInfo.Title;
            testDescrition.Text = rgx.Replace(testInfo.Description, " ").Trim();
            testFilePath.Text   = _svgFilePath;

            btnFilePath.IsEnabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace             = false;
            settings.IgnoreComments               = true;
            settings.IgnoreProcessingInstructions = true;
            settings.DtdProcessing = DtdProcessing.Parse;
            settings.XmlResolver   = null;

            SvgTestSuite selectedTestSuite = null;

            if (_optionSettings != null)
            {
                selectedTestSuite = _optionSettings.SelectedTestSuite;
            }
            if (selectedTestSuite == null)
            {
                selectedTestSuite = SvgTestSuite.GetDefault(SvgTestSuite.Create());
            }

            int majorVersion = selectedTestSuite.MajorVersion;
            int minorVersion = selectedTestSuite.MinorVersion;

            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                if (majorVersion == 1 && minorVersion == 1)
                {
                    if (reader.ReadToFollowing("d:SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "d:operatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    Paragraph titlePara = new Paragraph();
                                    titlePara.FontWeight = FontWeights.Bold;
                                    titlePara.FontSize   = 16;
                                    titlePara.Inlines.Add(new Run("Operator Script"));

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(titlePara);
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(titlePara);
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:passCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    Paragraph titlePara = new Paragraph();
                                    titlePara.FontWeight = FontWeights.Bold;
                                    titlePara.FontSize   = 16;
                                    titlePara.Inlines.Add(new Run("Pass Criteria"));

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(titlePara);
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(titlePara);
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:testDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    Paragraph titlePara = new Paragraph();
                                    titlePara.FontWeight = FontWeights.Bold;
                                    titlePara.FontSize   = 16;
                                    titlePara.Inlines.Add(new Run("Test Description"));

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(titlePara);
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(titlePara);
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
                else if (majorVersion == 1 && minorVersion == 2)
                {
                    if (reader.ReadToFollowing("SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "d:OperatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:PassCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:TestDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (reader.ReadToFollowing("SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "OperatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string revisionText = reader.GetAttribute("version");
                                    if (!string.IsNullOrWhiteSpace(revisionText))
                                    {
                                        revisionText       = revisionText.Replace("$", string.Empty);
                                        _testCase.Revision = revisionText.Trim();
                                    }
                                    string nameText = reader.GetAttribute("testname");
                                    if (!string.IsNullOrWhiteSpace(nameText))
                                    {
                                        _testCase.Name = nameText.Trim();
                                    }
                                }
                                else if (string.Equals(nodeName, "Paragraph", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);

                                        testDetailsDoc.Blocks.Add(nextSection);
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            SubscribeToAllHyperlinks();

            return(true);
        }