private void Save(XmlWriter writer, Form mainForm)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("options");

            this.SaveOption(writer, "HidePathsRoot", _hidePathsRoot);
            //this.SaveOption(writer, "WebSuitePath", _webSuitePath);
            //this.SaveOption(writer, "LocalSuitePath", this.GetPath(_localSuitePath));
            this.SaveOption(writer, "SelectedValuePath", _selectedValuePath);
            this.SaveOption(writer, "Theme", _theme);

            if (_testSuites != null && _testSuites.Count != 0)
            {
                var selectedSuite = SvgTestSuite.GetSelected(_testSuites);
                if (selectedSuite != null)
                {
                    selectedSuite.LocalSuitePath = _localSuitePath;
                    selectedSuite.WebSuitePath   = _webSuitePath;
                }

                writer.WriteStartElement("testSuites");

                foreach (var testSuite in _testSuites)
                {
                    testSuite.WriteXml(writer);
                }

                writer.WriteEndElement();
            }

            try
            {
                _winPosition = new WindowPosition();
                if (mainForm != null)
                {
                    _winPosition.Location    = mainForm.Location;
                    _winPosition.Size        = mainForm.Size;
                    _winPosition.WindowState = mainForm.WindowState;
                    foreach (Screen screen in Screen.AllScreens)
                    {
                        _winPosition.WorkingAreas.Add(screen.WorkingArea);
                    }
                }

                this.SaveWindowPosition(writer);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
示例#2
0
        public static SvgTestSuite GetDefault(IList <SvgTestSuite> testSuites)
        {
            SvgTestSuite defaultTestSuite = null;

            if (testSuites != null && testSuites.Count != 0)
            {
                foreach (var testSuite in testSuites)
                {
                    if (testSuite.IsDefault)
                    {
                        defaultTestSuite = testSuite;
                        break;
                    }
                }
            }
            return(defaultTestSuite);
        }
示例#3
0
        public SvgTestSuite(SvgTestSuite source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), "The source parameter cannot be null or Nothing.");
            }

            _isDefault      = source._isDefault;
            _isSelected     = source._isSelected;
            _version        = source._version;
            _description    = source._description;
            _suiteName      = source._suiteName;
            _suiteDirName   = source._suiteDirName;
            _webSuitePath   = source._webSuitePath;
            _localSuitePath = source._localSuitePath;
            _testFileName   = source._testFileName;
            _resultFileName = source._resultFileName;
        }
示例#4
0
        public SvgTestSuite Clone()
        {
            SvgTestSuite clonedSuite = new SvgTestSuite(this);

            if (_version != null)
            {
                clonedSuite._version = new string(_version.ToCharArray());
            }
            if (_description != null)
            {
                clonedSuite._description = new string(_description.ToCharArray());
            }

            if (_suiteName != null)
            {
                clonedSuite._suiteName = new string(_suiteName.ToCharArray());
            }
            if (_suiteDirName != null)
            {
                clonedSuite._suiteDirName = new string(_suiteDirName.ToCharArray());
            }

            if (_testFileName != null)
            {
                clonedSuite._testFileName = new string(_testFileName.ToCharArray());
            }
            if (_resultFileName != null)
            {
                clonedSuite._resultFileName = new string(_resultFileName.ToCharArray());
            }

            if (_webSuitePath != null)
            {
                clonedSuite._webSuitePath = new string(_webSuitePath.ToCharArray());
            }
            if (_localSuitePath != null)
            {
                clonedSuite._localSuitePath = new string(_localSuitePath.ToCharArray());
            }

            return(clonedSuite);
        }
示例#5
0
        public SvgTestSuite Clone()
        {
            SvgTestSuite clonedSuite = new SvgTestSuite(this);

            if (_version != null)
            {
                clonedSuite._version = string.Copy(_version);
            }
            if (_description != null)
            {
                clonedSuite._description = string.Copy(_description);
            }

            if (_suiteName != null)
            {
                clonedSuite._suiteName = string.Copy(_suiteName);
            }
            if (_suiteDirName != null)
            {
                clonedSuite._suiteDirName = string.Copy(_suiteDirName);
            }

            if (_testFileName != null)
            {
                clonedSuite._testFileName = string.Copy(_testFileName);
            }
            if (_resultFileName != null)
            {
                clonedSuite._resultFileName = string.Copy(_resultFileName);
            }

            if (_webSuitePath != null)
            {
                clonedSuite._webSuitePath = string.Copy(_webSuitePath);
            }
            if (_localSuitePath != null)
            {
                clonedSuite._localSuitePath = string.Copy(_localSuitePath);
            }

            return(clonedSuite);
        }
        public OptionSettings(string testPath)
        {
            _localSuitePath = testPath;

            _testSuites = SvgTestSuite.Create();

            // For the start the default is selected
            var selectedSuite = SvgTestSuite.GetDefault(_testSuites);

            if (selectedSuite != null)
            {
                if (string.IsNullOrWhiteSpace(testPath))
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                }
                _webSuitePath = selectedSuite.WebSuitePath;
            }

            if (!Directory.Exists(_localSuitePath))
            {
                Directory.CreateDirectory(_localSuitePath);
            }
            _theme = DockingTheme.LightTheme;
        }
示例#7
0
        public static SvgTestSuite GetSelected(IList <SvgTestSuite> testSuites)
        {
            SvgTestSuite selectedTestSuite = null;

            if (testSuites != null && testSuites.Count != 0)
            {
                int selectedCount = 0;
                foreach (var testSuite in testSuites)
                {
                    if (testSuite.IsSelected)
                    {
                        selectedTestSuite = testSuite;
                        selectedCount++;
                    }
                }

                if (selectedCount != 1)
                {
                    return(null);
                }
            }

            return(selectedTestSuite);
        }
示例#8
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);
        }
        private void Load(XmlReader reader, Form mainForm)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            List <SvgTestSuite> testSuites = new List <SvgTestSuite>(SvgTestSuite.TestSuiteCount);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "option", comparer))
                    {
                        string optionName = reader.GetAttribute("name");
                        string optionType = reader.GetAttribute("type");
                        if (string.Equals(optionType, "String", comparer))
                        {
                            string optionValue = reader.ReadElementContentAsString();

                            switch (optionName)
                            {
                            //case "WebSuitePath":
                            //    _webSuitePath = optionValue;
                            //    break;
                            //case "LocalSuitePath":
                            //    if (optionValue.StartsWith(ParentSymbol, comparer))
                            //    {
                            //        var inputPath = string.Copy(_localSuitePath);
                            //        int indexOf = inputPath.IndexOf(SharpVectors, comparer);

                            //        if (indexOf > 0)
                            //        {
                            //            var basePath    = inputPath.Substring(0, indexOf);
                            //            _localSuitePath = Path.Combine(basePath, optionValue.Replace(ParentSymbol, ""));
                            //        }
                            //        else
                            //        {
                            //            _localSuitePath = optionValue;
                            //        }
                            //    }
                            //    else
                            //    {
                            //        _localSuitePath = optionValue;
                            //    }

                            //    // Ignore old test suite directory, if found
                            //    if (string.IsNullOrWhiteSpace(_localSuitePath) ||
                            //        !this.IsLocalSuitePathChanged(Path.GetFullPath(TestsSvg)))
                            //    {
                            //        _localSuitePath = Path.GetFullPath(TestsSvg10);
                            //    }
                            //    break;
                            case "SelectedValuePath":
                                _selectedValuePath = optionValue;
                                break;
                            }
                        }
                        else if (string.Equals(optionType, "Boolean", comparer))
                        {
                            bool optionValue = reader.ReadElementContentAsBoolean();
                            switch (optionName)
                            {
                            case "HidePathsRoot":
                                _hidePathsRoot = optionValue;
                                break;
                            }
                        }
                        else if (string.Equals(optionType, "Other", comparer))
                        {
                            string optionValue = reader.ReadElementContentAsString();
                            switch (optionName)
                            {
                            case "Theme":
                                _theme = (DockingTheme)Enum.Parse(typeof(DockingTheme), optionValue, true);
                                break;
                            }
                        }
                    }
                    else if (string.Equals(reader.Name, "testSuite", comparer))
                    {
                        if (!reader.IsEmptyElement)
                        {
                            SvgTestSuite testSuite = new SvgTestSuite(reader);
                            if (testSuite.IsValid())
                            {
                                testSuites.Add(testSuite);
                            }
                        }
                    }
                    else if (string.Equals(reader.Name, "placements", comparer))
                    {
                        if (reader.IsEmptyElement == false)
                        {
                            if (reader.ReadToFollowing("WindowPosition"))
                            {
                                var xs = new XmlSerializer(typeof(WindowPosition));
                                _winPosition = xs.Deserialize(reader) as WindowPosition;
                            }
                        }
                    }
                }
            }

            if (testSuites.Count == SvgTestSuite.TestSuiteCount)
            {
                var selectedSuite = SvgTestSuite.GetSelected(testSuites);
                if (selectedSuite != null)
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                    _webSuitePath   = selectedSuite.WebSuitePath;

                    _testSuites = testSuites;
                }
            }

            if (mainForm != null && _winPosition != null)
            {
                try
                {
                    switch (_winPosition.WindowState)
                    {
                    case FormWindowState.Maximized:
                        mainForm.Location      = _winPosition.MaximisedPoint;
                        mainForm.StartPosition = FormStartPosition.Manual;
                        break;

                    case FormWindowState.Normal:
                        if (_winPosition.IsIdenticalScreen())
                        {
                            mainForm.Location      = _winPosition.Location;
                            mainForm.Size          = _winPosition.Size;
                            mainForm.StartPosition = FormStartPosition.Manual;
                        }
                        break;

                    case FormWindowState.Minimized:
                        _winPosition.WindowState = FormWindowState.Normal;
                        break;

                    default:
                        break;
                    }
                    mainForm.WindowState = _winPosition.WindowState;
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }