예제 #1
0
        private void btnDiff_Click(object sender, RoutedEventArgs e)
        {
            markerOne.ClearMarks();
            markerTwo.ClearMarks();
            if ((string.IsNullOrEmpty(edtXmlFile1.Text) && chkCurrentDocument.IsChecked == false) ||
                (string.IsNullOrEmpty(edtXmlFile2.Text) && chkClipboard.IsChecked == false))
            {
                MessageBox.Show(Application.Current.MainWindow, "Please choose two XML files to diff",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                edtResult.Text = "";
                return;
            }

            try
            {
                string firstXml;
                if (chkCurrentDocument.IsChecked == true)
                {
                    firstXml = _ef.XmlEditor.Text;
                }
                else
                {
                    firstXml = File.ReadAllText(edtXmlFile1.Text);
                }

                string secondXml;
                if (chkClipboard.IsChecked == true)
                {
                    secondXml = Clipboard.GetText();
                }
                else
                {
                    secondXml = File.ReadAllText(edtXmlFile2.Text);
                }

                edtResult.Text = diffWithDiffy(firstXml, secondXml);
                diffWithDiffplex(firstXml, secondXml);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Application.Current.MainWindow, "Error while diffing: " + ex.Message,
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
        void validationUpdateTimer_Tick(object sender, EventArgs e)
        {
            Debug.Assert(_editor != null);

            _lstErrors.Items.Clear();
            _errorMarker.ClearMarks();

            try
            {
                if (_validationData.DoNotValidate)
                {
                    var i1 = new ValidationIssue(ValidationIssue.Type.Information, 0, 0, "Validation is turned off.\nTo activate, click in ribbon on 'Validation' tab and select 'Check wellformedness' or 'Validate against schema'.");
                    _lstErrors.Items.Add(i1);
                }

                else if (_validationData.CheckWellformedness)
                {
                    try
                    {
                        XmlDocument xmlDoc = _editor.XmlEditor.Text.ToXmlDocument();  //TODO make async
                        var         i      = new ValidationIssue(ValidationIssue.Type.Information, 0, 0, "XML is wellformed");
                        _lstErrors.Items.Add(i);
                    }
                    catch (XmlException ex)
                    {
                        var i = new ValidationIssue(ValidationIssue.Type.Error, ex.LineNumber, ex.LinePosition,
                                                    ex.Message);
                        _lstErrors.Items.Add(i);
                    }
                }

                else if (_validationData.CheckXsd)
                {
                    string xsdFile = _validationData.Xsd;
                    if (!FileHelper.FileExists(xsdFile))
                    {
                        var i = new ValidationIssue(ValidationIssue.Type.Warning, 0, 0,
                                                    $"The file '{xsdFile}' does not exist, or the path is invalid");
                        _lstErrors.Items.Add(i);
                        return;
                    }

                    XsdValidationResult result = XsdValidationHelper.Instance.ValidateInstance(
                        xsdFile, _editor.XmlEditor.Text);
                    if (result.Results.Count == 0)
                    {
                        var i = new ValidationIssue(ValidationIssue.Type.Information, 0, 0, "XML is valid");
                        _lstErrors.Items.Add(i);
                    }
                    else
                    {
                        foreach (var x in result.Results)
                        {
                            _lstErrors.Items.Add(x);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var i = new ValidationIssue(ValidationIssue.Type.Error, 0, 0, "Error while validating file: " + ex.Message);
                _lstErrors.Items.Add(i);
            }

            foreach (var item in _lstErrors.Items)
            {
                var error = item as ValidationIssue;
                if (error != null)
                {
                    if (error.IssueType != ValidationIssue.Type.Information)
                    {
                        int offset = error.Line == 0 ? 0 : _editor.XmlEditor.Document.GetOffset(error.Line, error.Column);
                        _errorMarker.AddOffsetToMark(new MarkBackgroundRenderer.Mark
                        {
                            Offset = offset,
                            Length = 1,
                            Brush  = new SolidColorBrush(Color.FromArgb(0x40, 0xFF, 0, 0))
                        });
                    }
                }
            }
        }