コード例 #1
0
        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
        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());
                }
            }
        }