Esempio n. 1
0
        public void UnloadDocument()
        {
            _svgFilePath = "";

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

            _testCase = null;

            btnFilePath.Enabled = false;

            testDetailsDoc.Text = string.Empty;
        }
Esempio n. 2
0
        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.Enabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

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

            StringBuilder textBuilder = new StringBuilder();

            textBuilder.AppendLine("<html>");
            textBuilder.AppendLine("<head>");
            textBuilder.AppendLine("<title>About Test</title>");
            textBuilder.AppendLine("</head>");
            textBuilder.AppendLine("<body>");
            textBuilder.AppendLine("<div style=\"padding:0px;margin:0px 0px 15px 0px;\">");

            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;

            var paraStyle = new StringBuilder();

            paraStyle.Append("padding:3px;");
            paraStyle.Append("margin:0px;");

            var paraTag = string.Format("<p style=\"{0}\">", paraStyle);

            var tableStyle = new StringBuilder();

            tableStyle.Append("border:1px solid gray;");
            tableStyle.AppendFormat("margin:{0}px {1}px {2}px {3}px;", 16, 16, 16, 16);
//            tableStyle.Append("width:75%;");
            var tableTag = string.Format("<table style=\"{0}\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">", tableStyle);

            tableStyle.Length = 0;
            //            tableStyle.Append("border:1px solid gray;");
            tableStyle.Append("font-weight:bold;");
            tableStyle.Append("font-size:16px;");
            tableStyle.Append("text-align:center;");
            var cellTag = string.Format("<td style=\"{0}\">", tableStyle);

            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                if (majorVersion == 1 && minorVersion == 1)
                {
                    var titleStyle = new StringBuilder();
                    titleStyle.Append("font-weight:bold;");
                    titleStyle.Append("font-size:14px;");
                    titleStyle.Append("padding:10px 0px 10px 0px;");
                    titleStyle.Append("margin:0px;");

                    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().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(string.Format("<p style=\"{0}\">Operator Script</p>", titleStyle));
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:passCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(string.Format("<p style=\"{0}\">Pass Criteria</p>", titleStyle));
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:testDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(string.Format("<p style=\"{0}\">Test Description</p>", titleStyle));
                                    textBuilder.AppendLine(inputText);

                                    _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().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:PassCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:TestDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(inputText);

                                    _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("$", "");
                                        _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().Replace(NamespaceText, string.Empty);

                                    string paraText = rgx.Replace(inputText, " ").Trim();

                                    textBuilder.AppendLine("<p>" + paraText + "</p>");
                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            textBuilder.AppendLine("</div>");
            textBuilder.AppendLine("</body>");
            textBuilder.AppendLine("</html>");
            testDetailsDoc.Text = textBuilder.ToString();

            return(true);
        }
Esempio n. 3
0
        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.Enabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

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

            StringBuilder textBuilder = new StringBuilder();

            textBuilder.AppendLine("<html>");
            textBuilder.AppendLine("<head>");
            textBuilder.AppendLine("<title>About Test</title>");
            textBuilder.AppendLine("</head>");
            textBuilder.AppendLine("<body>");
            textBuilder.AppendLine("<div style=\"padding:0px;margin:0px 0px 15px 0px;\">");

            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 paraText = rgx.Replace(inputText, " ").Trim();

                                textBuilder.AppendLine("<p>" + paraText + "</p>");
                                _testCase.Paragraphs.Add(inputText);
                            }
                        }
                        else if (nodeType == XmlNodeType.EndElement &&
                                 string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                        {
                            break;
                        }
                    }
                }
            }

            textBuilder.AppendLine("</div>");
            textBuilder.AppendLine("</body>");
            textBuilder.AppendLine("</html>");
            testDetailsDoc.Text = textBuilder.ToString();

            return(true);
        }