コード例 #1
0
        private void OnTreeViewItemUnselected(object sender, RoutedEventArgs e)
        {
            // Prompt for any un-applied modifications to avoid lost.
            if (_isTreeChangedPending)
            {
                TreeViewItem treeItem = e.OriginalSource as TreeViewItem;
                if (treeItem == null)
                {
                    return;
                }

                if (treeItem != null && treeItem.Tag != null)
                {
                    SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;
                    if (testInfo != null)
                    {
                        MessageBoxResult boxResult = MessageBox.Show(
                            "The previously selected test item was modified.\nDo you want to apply the current modifications?",
                            "Svg Test Suite",
                            MessageBoxButton.YesNo, MessageBoxImage.Warning);

                        if (boxResult == MessageBoxResult.Yes || boxResult == MessageBoxResult.OK)
                        {
                            this.OnApplyTestState(treeItem);
                        }
                    }
                }

                _isTreeChangedPending = false;
            }
        }
コード例 #2
0
        public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo = null)
        {
            this.UnloadDocument();

            if (textEditor == null || string.IsNullOrWhiteSpace(documentFilePath))
            {
                return(false);
            }
            string fileExt = Path.GetExtension(documentFilePath);

            if (string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase))
            {
                using (FileStream fileStream = File.OpenRead(documentFilePath))
                {
                    using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        // Text Editor does not work with this stream, so we read the data to memory stream...
                        MemoryStream memoryStream = new MemoryStream();
                        // Use this method is used to read all bytes from a stream.
                        int    totalCount = 0;
                        int    bufferSize = 512;
                        byte[] buffer     = new byte[bufferSize];
                        while (true)
                        {
                            int bytesRead = zipStream.Read(buffer, 0, bufferSize);
                            if (bytesRead == 0)
                            {
                                break;
                            }

                            memoryStream.Write(buffer, 0, bytesRead);
                            totalCount += bytesRead;
                        }

                        if (totalCount > 0)
                        {
                            memoryStream.Position = 0;
                        }

                        textEditor.Load(memoryStream);

                        memoryStream.Close();
                    }
                }
            }
            else
            {
                textEditor.Load(documentFilePath);
            }

            if (_foldingManager == null || _foldingStrategy == null)
            {
                _foldingManager  = FoldingManager.Install(textEditor.TextArea);
                _foldingStrategy = new XmlFoldingStrategy();
            }
            _foldingStrategy.UpdateFoldings(_foldingManager, textEditor.Document);

            return(true);
        }
コード例 #3
0
        private void SaveTreeViewCategory(XmlWriter writer, TreeViewItem categoryItem, SvgTestCategory testCategory)
        {
            int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0;

            writer.WriteStartElement("category");

            writer.WriteAttributeString("label", testCategory.Label);

            ItemCollection treeItems = categoryItem.Items;

            for (int j = 0; j < treeItems.Count; j++)
            {
                TreeViewItem treeItem = treeItems[j] as TreeViewItem;
                if (treeItem != null)
                {
                    SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;
                    if (testInfo != null)
                    {
                        testInfo.WriteXml(writer);

                        total++;
                        SvgTestState testState = testInfo.State;

                        switch (testState)
                        {
                        case SvgTestState.Unknown:
                            unknowns++;
                            break;

                        case SvgTestState.Failure:
                            failures++;
                            break;

                        case SvgTestState.Success:
                            successes++;
                            break;

                        case SvgTestState.Partial:
                            partials++;
                            break;
                        }
                    }
                }
            }

            writer.WriteEndElement();

            testCategory.SetValues(total, unknowns, failures, successes, partials);
        }
コード例 #4
0
        private void OnApplyTestState(TreeViewItem treeItem)
        {
            SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;

            if (testInfo == null)
            {
                return;
            }

            BulletDecorator header = treeItem.Header as BulletDecorator;

            if (header == null)
            {
                return;
            }
            int selIndex = stateComboBox.SelectedIndex;

            if (selIndex < 0)
            {
                return;
            }

            testInfo.State   = (SvgTestState)selIndex;
            testInfo.Comment = testComment.Text;

            Ellipse bullet = header.Bullet as Ellipse;

            if (bullet != null)
            {
                bullet.Fill = testInfo.StateBrush;
            }
            if (!_isTreeModified)
            {
                this.Title = this.Title + " *";

                _isTreeModified = true;
            }

            _isTreeChangedPending = false;
            testApply.IsEnabled   = false;
        }
コード例 #5
0
        public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo = null)
        {
            this.UnloadDocument();

            if (string.IsNullOrWhiteSpace(documentFilePath) || testInfo == null)
            {
                return(false);
            }

            _svgFilePath = documentFilePath;

            bool isLoaded = false;

            string fileExt = Path.GetExtension(documentFilePath);

            if (string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase))
            {
                using (FileStream fileStream = File.OpenRead(documentFilePath))
                {
                    using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        // Text Editor does not work with this stream, so we read the data to memory stream...
                        MemoryStream memoryStream = new MemoryStream();
                        // Use this method is used to read all bytes from a stream.
                        int    totalCount = 0;
                        int    bufferSize = 512;
                        byte[] buffer     = new byte[bufferSize];
                        while (true)
                        {
                            int bytesRead = zipStream.Read(buffer, 0, bufferSize);
                            if (bytesRead == 0)
                            {
                                break;
                            }

                            memoryStream.Write(buffer, 0, bytesRead);
                            totalCount += bytesRead;
                        }

                        if (totalCount > 0)
                        {
                            memoryStream.Position = 0;
                        }

                        isLoaded = this.LoadFile(memoryStream, testInfo);

                        memoryStream.Close();
                    }
                }
            }
            else
            {
                using (FileStream stream = File.OpenRead(documentFilePath))
                {
                    isLoaded = this.LoadFile(stream, testInfo);
                }
            }

            btnFilePath.IsEnabled = isLoaded;

            return(isLoaded);
        }
コード例 #6
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.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);
        }
コード例 #7
0
        private void OnTreeViewItemSelected(object sender, RoutedEventArgs e)
        {
            _currentDrawing = null;

            TreeViewItem selItem = treeView.SelectedItem as TreeViewItem;

            if (selItem == null || selItem.Tag == null)
            {
                EnableTestPanel(false);
                return;
            }

            SvgTestInfo testItem = selItem.Tag as SvgTestInfo;

            if (testItem == null)
            {
                EnableTestPanel(false);
                return;
            }

            if (!_isSuiteAvailable)
            {
                EnableTestPanel(false);
                return;
            }

            string svgFilePath = IoPath.Combine(_suitePath, "svg\\" + testItem.FileName);

            if (!File.Exists(svgFilePath))
            {
                EnableTestPanel(false);
                return;
            }
            string pngFilePath = IoPath.Combine(_suitePath,
                                                "png\\full-" + IoPath.ChangeExtension(testItem.FileName, ".png"));

            if (!File.Exists(pngFilePath))
            {
                EnableTestPanel(false);
                return;
            }

            this.Cursor = Cursors.Wait;

            try
            {
                if (_svgPage != null)
                {
                    _svgPage.LoadDocument(svgFilePath, testItem, null);
                }
            }
            catch (Exception ex)
            {
                _isTreeChangedPending = false;
                this.Cursor           = Cursors.Arrow;

                MessageBox.Show(ex.ToString(), AppErrorTitle,
                                MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            try
            {
                DrawingGroup drawing = _fileReader.Read(svgFilePath, _directoryInfo);
                if (drawing == null)
                {
                    return;
                }

                if (_drawingPage != null)
                {
                    _drawingPage.LoadDocument(pngFilePath, testItem, drawing);
                }

                if (_xamlPage != null && !string.IsNullOrWhiteSpace(_drawingDir))
                {
                    string xamlFilePath = IoPath.Combine(_drawingDir,
                                                         IoPath.ChangeExtension(testItem.FileName, ".xaml"));

                    if (File.Exists(xamlFilePath))
                    {
                        _xamlPage.LoadDocument(xamlFilePath, testItem, null);

                        // Delete the file after loading it...
                        File.Delete(xamlFilePath);
                    }
                }

                if (frameAbout != null)
                {
                    if (frameAbout.CanGoBack)
                    {
                        frameAbout.GoBack();
                        var entry = frameAbout.RemoveBackEntry();
                        while (entry != null)
                        {
                            entry = frameAbout.RemoveBackEntry();
                        }
                    }
                    frameAbout.NavigationUIVisibility = NavigationUIVisibility.Hidden;
                }

                if (_aboutPage != null)
                {
                    _aboutPage.LoadDocument(svgFilePath, testItem, null);
                }

                if (_browserPage != null)
                {
                    _browserPage.LoadDocument(svgFilePath, testItem, drawing);
                }

                testFilePath.Text = svgFilePath;

                testDescrition.Text = testItem.Description;

                stateComboBox.SelectedIndex = (int)testItem.State;
                testComment.Text            = testItem.Comment;

                _isTreeChangedPending = false;
                testApply.IsEnabled   = false;
                EnableTestPanel(true);

                _currentDrawing = drawing;
            }
            catch (Exception ex)
            {
                _currentDrawing = null;

                //EnableTestPanel(false);
                _isTreeChangedPending = false;

                MessageBox.Show(ex.ToString(), AppErrorTitle,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
コード例 #8
0
        private void LoadTreeViewCategory(XmlReader reader, TreeViewItem categoryItem, SvgTestCategory testCategory)
        {
            int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0;

            int itemCount = 0;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "test", StringComparison.OrdinalIgnoreCase))
                    {
                        SvgTestInfo testInfo = new SvgTestInfo(reader);
                        if (!testInfo.IsEmpty)
                        {
                            TextBlock headerText = new TextBlock();
                            headerText.Text   = string.Format("({0:D3}) - {1}", itemCount, testInfo.Title);
                            headerText.Margin = new Thickness(3, 0, 0, 0);

                            Ellipse bullet = new Ellipse();
                            bullet.Height          = 16;
                            bullet.Width           = 16;
                            bullet.Fill            = testInfo.StateBrush;
                            bullet.Stroke          = Brushes.DarkGray;
                            bullet.StrokeThickness = 1;

                            BulletDecorator decorator = new BulletDecorator();
                            decorator.Bullet = bullet;
                            decorator.Margin = new Thickness(0, 0, 10, 0);
                            decorator.Child  = headerText;

                            TreeViewItem treeItem = new TreeViewItem();
                            treeItem.Header     = decorator;
                            treeItem.Padding    = new Thickness(3);
                            treeItem.FontSize   = 12;
                            treeItem.FontWeight = FontWeights.Normal;
                            treeItem.Tag        = testInfo;

                            categoryItem.Items.Add(treeItem);

                            itemCount++;

                            total++;
                            SvgTestState testState = testInfo.State;

                            switch (testState)
                            {
                            case SvgTestState.Unknown:
                                unknowns++;
                                break;

                            case SvgTestState.Failure:
                                failures++;
                                break;

                            case SvgTestState.Success:
                                successes++;
                                break;

                            case SvgTestState.Partial:
                                partials++;
                                break;
                            }
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }

            testCategory.SetValues(total, unknowns, failures, successes, partials);
        }
コード例 #9
0
        public bool LoadDocument(string svgFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            this.UnloadDocument();

            if (extraInfo == null)
            {
                return(false);
            }
            DrawingGroup drawing = extraInfo as DrawingGroup;

            if (drawing == null)
            {
                return(false);
            }

            try
            {
                webBrowserBox.Navigate(svgFilePath);
            }
            catch
            {
                throw;
            }

            try
            {
                Rect drawingBounds = drawing.Bounds;

                //if (bitmap != null)
                //{
                //    drawing.ClipGeometry = new RectangleGeometry(
                //        new Rect(0, 0, bitmap.Width, bitmap.Height));
                //}

                //svgDrawing.Source = new DrawingImage(drawing);

                if (_viewBoxWidth == 0 || _viewBoxHeight == 0)
                {
                    _viewBoxWidth  = (int)svgDrawing.ActualHeight;
                    _viewBoxHeight = (int)svgDrawing.ActualHeight;
                }

                svgDrawing.UnloadDiagrams();
                viewBox.Width      = double.NaN;
                viewBox.Height     = double.NaN;
                viewBox.RenderSize = new Size(_viewBoxWidth, _viewBoxHeight);

                svgDrawing.RenderDiagrams(drawing);

                //if (bitmap != null && ((int)drawingBounds.Width < ImageWidth || (int)drawingBounds.Height < ImageHeight))
                //{
                //    //SvgDrawingCanvas drawCanvas = svgDrawing.DrawingCanvas;
                //    viewBox.Width = bitmap.Width;
                //    viewBox.Height = bitmap.Height;
                //    //svgDrawing.Width = bitmap.Width;
                //    //svgDrawing.Height = bitmap.Height;

                //    //SvgZoomableCanvas zoomableCanvas = svgDrawing.ZoomableCanvas;
                //    ////zoomableCanvas.Width = bitmap.Width;
                //    ////zoomableCanvas.Height = bitmap.Height;

                //    //zoomableCanvas.FitWindow(new Size(bitmap.Width, bitmap.Height));
                //}
            }
            catch
            {
                //svgDrawing.Source = null;
                svgDrawing.UnloadDiagrams();

                throw;
            }

            return(true);
        }
コード例 #10
0
ファイル: AboutPage.xaml.cs プロジェクト: zellus/SharpVectors
        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);
        }
コード例 #11
0
        //#region Public Properties

        //public string XamlDrawingDir
        //{
        //    get
        //    {
        //        return _drawingDir;
        //    }
        //    set
        //    {
        //        _drawingDir = value;

        //        if (!string.IsNullOrWhiteSpace(_drawingDir))
        //        {
        //            _directoryInfo = new DirectoryInfo(_drawingDir);

        //            if (_fileReader != null)
        //            {
        //                _fileReader.SaveXaml = Directory.Exists(_drawingDir);
        //            }
        //        }
        //    }
        //}

        //#endregion

        #region Public Methods

        public bool LoadDocument(string pngFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            this.UnloadDocument();

            if (extraInfo == null)
            {
                return(false);
            }
            //string pngFilePath = extraInfo.ToString();
            if (string.IsNullOrWhiteSpace(pngFilePath))
            {
                return(false);
            }
            DrawingGroup drawing = extraInfo as DrawingGroup;

            if (drawing == null)
            {
                return(false);
            }

            BitmapImage bitmap = null;

            try
            {
                bitmap           = new BitmapImage(new Uri(pngFilePath));
                pngResult.Source = bitmap;
            }
            catch
            {
                throw;
            }

            try
            {
                //DrawingGroup drawing = _fileReader.Read(svgFilePath, _directoryInfo);

                Rect drawingBounds = drawing.Bounds;

                //if (bitmap != null)
                //{
                //    drawing.ClipGeometry = new RectangleGeometry(
                //        new Rect(0, 0, bitmap.Width, bitmap.Height));
                //}

                if (_viewBoxWidth == 0 || _viewBoxHeight == 0)
                {
                    _viewBoxWidth  = (int)svgDrawing.ActualHeight;
                    _viewBoxHeight = (int)svgDrawing.ActualHeight;
                }

                svgDrawing.Width      = double.NaN;
                svgDrawing.Height     = double.NaN;
                svgDrawing.RenderSize = new Size(_viewBoxWidth, _viewBoxHeight);

                svgDrawing.Source = new DrawingImage(drawing);

//                svgDrawing.UnloadDiagrams();
//                viewBox.Width = double.NaN;
//                viewBox.Height = double.NaN;
//                viewBox.RenderSize = new Size(_viewBoxWidth, _viewBoxHeight);

//                svgDrawing.RenderDiagrams(drawing);

                if (bitmap != null && ((int)drawingBounds.Width < ImageWidth || (int)drawingBounds.Height < ImageHeight))
                {
                    //SvgDrawingCanvas drawCanvas = svgDrawing.DrawingCanvas;
//                    viewBox.Width  = bitmap.Width;
//                    viewBox.Height = bitmap.Height;
                    svgDrawing.Width  = bitmap.Width;
                    svgDrawing.Height = bitmap.Height;

                    //SvgZoomableCanvas zoomableCanvas = svgDrawing.ZoomableCanvas;
                    ////zoomableCanvas.Width = bitmap.Width;
                    ////zoomableCanvas.Height = bitmap.Height;

                    //zoomableCanvas.FitWindow(new Size(bitmap.Width, bitmap.Height));
                }
            }
            catch
            {
                svgDrawing.Source = null;
//                svgDrawing.UnloadDiagrams();

                throw;
            }

            return(true);
        }
コード例 #12
0
        public bool LoadDocument(string pngFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            this.UnloadDocument();

            if (extraInfo == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(pngFilePath))
            {
                return(false);
            }
            DrawingGroup drawing = extraInfo as DrawingGroup;

            if (drawing == null)
            {
                return(false);
            }

            BitmapSource bitmap = null;

            try
            {
                bitmap = new BitmapImage(new Uri(pngFilePath));
                if (bitmap.DpiY < 96) // Some of the images were not created in right DPI
                {
                    double dpi    = 96;
                    int    width  = bitmap.PixelWidth;
                    int    height = bitmap.PixelHeight;

                    int    stride    = width * 4; // 4 bytes per pixel
                    byte[] pixelData = new byte[stride * height];
                    bitmap.CopyPixels(pixelData, stride, 0);

                    bitmap = BitmapSource.Create(width, height, dpi, dpi,
                                                 PixelFormats.Bgra32, null, pixelData, stride);
                }

                pngResult.Source = bitmap;

                pngCanvas.Width  = bitmap.Width + 10;
                pngCanvas.Height = bitmap.Height + 10;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }

            try
            {
                Rect drawingBounds = drawing.Bounds;

                if (_viewBoxWidth == 0 || _viewBoxHeight == 0)
                {
                    _viewBoxWidth  = (int)svgDrawing.ActualHeight;
                    _viewBoxHeight = (int)svgDrawing.ActualHeight;
                }

                svgDrawing.Width      = double.NaN;
                svgDrawing.Height     = double.NaN;
                svgDrawing.RenderSize = new Size(_viewBoxWidth, _viewBoxHeight);

                svgDrawing.Source = new DrawingImage(drawing);

                if (bitmap != null && ((int)drawingBounds.Width < ImageWidth || (int)drawingBounds.Height < ImageHeight))
                {
                    svgDrawing.Width  = bitmap.Width;
                    svgDrawing.Height = bitmap.Height;
                }

                svgCanvas.Width  = bitmap.Width + 10;
                svgCanvas.Height = bitmap.Height + 10;
            }
            catch (Exception ex)
            {
                svgDrawing.Source = null;
                Trace.TraceError(ex.ToString());
            }

            return(true);
        }