예제 #1
0
        private async void BtnCompare_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // First load the html into a document objects we can manipulate
                string html1 = await File.ReadAllTextAsync("Resources/bbc1.html");

                HtmlDocument doc1 = new HtmlDocument();
                doc1.LoadHtml(html1);

                string html2 = await File.ReadAllTextAsync("Resources/bbc2.html");

                HtmlDocument doc2 = new HtmlDocument();
                doc2.LoadHtml(html2);

                // Filter the html to remove parts that are not very interesting
                HtmlFilter filter = new HtmlFilter();
                filter.CleanHtml(doc1.DocumentNode);
                filter.CleanHtml(doc2.DocumentNode);

                // convert the html into lines
                HtmlConverter converter = new HtmlConverter();
                var           lines1    = converter.GetLines(doc1.DocumentNode, ConvertOptions.Default);
                var           lines2    = converter.GetLines(doc2.DocumentNode, ConvertOptions.Default);

                // find the difference between these 2 sets of lines
                LineDiffer differ     = new LineDiffer();
                var        diffResult = differ.GetDiff(lines1, lines2, true);

                // load the original html into a document again
                HtmlDocument originalDoc = new HtmlDocument();
                originalDoc.LoadHtml(html1);

                // highlight the changed parts of the document
                Highlighter.ApplyHighlights(originalDoc, "#FFFF99", diffResult.Added.Select(i => i.Line.XPath));

                string htmlHighlighted = originalDoc.Save();

                webBrowserDiff.NavigateToString(htmlHighlighted);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Runs a test for a pair of input text files
        /// </summary>
        /// <param name="expected">The expected results for the test</param>
        /// <param name="oldText">The reference text to compare to</param>
        /// <param name="newText">The updated text to compare</param>
        private static void Test(LineModificationType[] expected, string oldText, string newText)
        {
            MemoryOwner <LineModificationType> result = LineDiffer.ComputeDiff(oldText, newText, '\r');

            try
            {
                Assert.AreEqual(expected.Length, result.Length);

                if (expected.Length == 0)
                {
                    return;
                }

                Assert.IsTrue(expected.SequenceEqual(result.Span.ToArray()));
            }
            finally
            {
                result.Dispose();
            }
        }
예제 #3
0
        private void UpdateDiffInfo(string text)
        {
            MemoryOwner <LineModificationType> diff = LineDiffer.ComputeDiff(_LoadedText, text, Characters.CarriageReturn);

            ref LineModificationType oldRef = ref _DiffIndicators.DangerousGetReference();