Exemplo n.º 1
0
        /// <summary>
        /// View a specific Content Version
        /// </summary>
        /// <returns></returns>
        public ActionResult Version(int? contentId)
        {
            var version = _entities.ContentVersions.FirstOrDefault(v => v.Id == contentId);

            if (version == null)
            {
                return RedirectToRoute("ContentIndex");
            }

            var previousVersion = _entities.ContentVersions
                .Where(v => v.Version < version.Version && v.ContentId == version.ContentId)
                .OrderByDescending(v => v.Version)
                .FirstOrDefault();

            var model = new ContentVersionViewModel
            {
                CurrentVersion = version,
                PreviousVersion = previousVersion
            };

            if (previousVersion != null)
            {
                var dmp = new diff_match_patch();
                var diffsContent = dmp.diff_main(previousVersion.UnparsedContent, version.UnparsedContent);
                var diffsStylesheet = dmp.diff_main(previousVersion.StylesheetCode, version.StylesheetCode);

                model.ContentDiff = dmp.diff_prettyHtml(diffsContent);
                model.StylesheetDiff = dmp.diff_prettyHtml(diffsStylesheet);
            }

            return View("~/Areas/mitarbeit/Views/Content/Version.cshtml", model);
        }
        public string GeneratePrettyHtmlDiff(string source, string target)
        {
            var dmp   = new diff_match_patch();
            var diffs = dmp.diff_main(source, target);

            return(dmp.diff_prettyHtml(diffs));
        }
Exemplo n.º 3
0
        private void getDiffInfo(FileHistoryDTO fileHistory, string newContent, string oldContent)
        {
            var dmp  = new diff_match_patch();
            var diff = dmp.diff_main(newContent, oldContent);

            dmp.diff_cleanupSemantic(diff);
            dmp.diff_prettyHtml(diff);

            var htmlContent    = new StringBuilder("");
            var linesIncreased = 0;
            var linesDecreased = 0;

            for (int i = 0; i < diff.Count; i++)
            {
                htmlContent.Append(diff[i]);
                if (diff[i].operation == Operation.DELETE)
                {
                    linesDecreased++;
                }
                if (diff[i].operation == Operation.INSERT)
                {
                    linesIncreased++;
                }
            }
            fileHistory.ContentDiffHtml = htmlContent.ToString();
            fileHistory.LinesDecreased  = linesDecreased;
            fileHistory.LinesIncreased  = linesIncreased;
            fileHistory.SizeDiff        = newContent.Length - oldContent.Length;
        }
Exemplo n.º 4
0
        private static void ComparePDF(string source_file1, string source_file2, string destination_file)
        {
            //convert source files to plain text
            string source_file1_text = PDF2String(source_file1);
            string source_file2_text = PDF2String(source_file2);

            //backup
            if (source_file1_text == "")
            {
                source_file1_text = "This is a dog. Hint: your PDF file source 1 was not converted into text.....";
            }

            if (source_file2_text == "")
            {
                source_file2_text = "This is a cat. Hint: your PDF file source 2 was not converted into text.....";
            }

            //set up compare objects and perform compare
            diff_match_patch dmp  = new diff_match_patch();
            List <Diff>      diff = dmp.diff_main(source_file1_text, source_file2_text);

            //convert compare to HTML and output this file (saving) as HMTL file
            string _HTMLString = dmp.diff_prettyHtml(diff);

            _HTMLString = CleanUpHTMLstring(_HTMLString);



            ////write HTML file to disk
            //WriteHTMLFile(_HTMLString);

            WriteHTMLtoPDF(_HTMLString, destination_file);
        }
Exemplo n.º 5
0
 private static void Diff()
 {
     //var res = DiffUtiles.DiffText("abcbasdf sdfasdfasd", "abcdcb", true, true, false);
     var d    = new diff_match_patch();
     var res  = d.diff_main("abcabxyz bbb", "abcabxyz a bbb");
     var res2 = d.diff_prettyHtml(res);
 }
Exemplo n.º 6
0
        public void EvalDiffHtml(RCRunner runner, RCClosure closure, RCString left, RCString right)
        {
            diff_match_patch dmp    = new diff_match_patch();
            List <Diff>      diffs  = dmp.diff_main(left[0], right[0]);
            string           result = dmp.diff_prettyHtml(diffs);

            runner.Yield(closure, new RCString(result));
        }
Exemplo n.º 7
0
        protected override string DoExecute(ITaskContextInternal context)
        {
            if (!File.Exists(_firstFilePathToCompare))
            {
                if (_failOnFileNotFound)
                {
                    throw new TaskExecutionException($"first file not found '{_firstFilePathToCompare}'.", 20);
                }

                context.LogInfo($"first file not found '{_firstFilePathToCompare}'. Skipping compare.");
                return(null);
            }

            if (!File.Exists(_secondFilePathToCompare))
            {
                if (_failOnFileNotFound)
                {
                    throw new TaskExecutionException($"second file not found '{_secondFilePathToCompare}'.", 20);
                }

                context.LogInfo($"second file not found '{_secondFilePathToCompare}'. Skipping compare.");
                return(null);
            }

            string newConfig = File.ReadAllText(_secondFilePathToCompare);

            var oldCOnf          = File.ReadAllText(_firstFilePathToCompare);
            diff_match_patch dmp = new diff_match_patch();

            dmp.Diff_EditCost = 4;
            List <Diff> diff = dmp.diff_main(oldCOnf, newConfig);

            if (diff.Count == 1)
            {
                if (diff[0].operation == Operation.EQUAL)
                {
                    //// Files are the same.
                    return(null);
                }
            }

            dmp.diff_cleanupSemantic(diff);

            var html = dmp.diff_prettyHtml(diff);

            if (!_noExportToFile)
            {
                File.WriteAllText(_htmlReportOutputPath, html);
            }

            if (_failOnDiff)
            {
                throw new TaskExecutionException($"File {_firstFilePathToCompare} and {_secondFilePathToCompare} are not the same", 21);
            }

            return(html);
        }
Exemplo n.º 8
0
        private string GetTextDifferences(string a, string b)
        {
            var diff        = new diff_match_patch();
            var differences = diff.diff_main(a + "", b + "");

            diff.diff_cleanupSemantic(differences);
            //Format as pretty html
            return(diff.diff_prettyHtml(differences));
        }
Exemplo n.º 9
0
        public void cargarDiff(byte[] a, byte[] b)
        {
            string TextoA = System.Text.Encoding.Default.GetString(a);
            string TextoB = System.Text.Encoding.Default.GetString(b);

            diff_match_patch dmp = new diff_match_patch();

            wbDiffViewer.DocumentText = dmp.diff_prettyHtml(dmp.diff_main(TextoA, TextoB));
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var dmp         = new diff_match_patch();
            var differences = dmp.diff_main("Hello World", "Hello orldffffffffffffffffffffff!");
            var diffHtml    = dmp.diff_prettyHtml(differences);

            diffHtml = diffHtml.Replace("background:", "background-color:");
            PdfDocument pdf = PdfGenerator.GeneratePdf("<p><h1 style='background-color: red'>Hello World</h1>" + diffHtml + "</p>", PageSize.A4);

            pdf.Save("C:\\Users\\bmoye\\Documents\\document.pdf");
        }
Exemplo n.º 11
0
        public DiffResultWinsow()
        {
            InitializeComponent();
            var text1 = (new StringBuilder()).AppendLine("This string will be removed").AppendLine("This string will be").ToString();
            var text2 = (new StringBuilder()).AppendLine("This string will be").AppendLine("This string will be added").ToString();
            var d     = new diff_match_patch();
            var res   = d.diff_main(text1, text2, false);
            var res2  = d.diff_prettyHtml(res);

            TxtBrowser.NavigateToString(res2);
        }
Exemplo n.º 12
0
        private async Task Unterschied2(IDialogContext context, IAwaitable <IEnumerable <Attachment> > argument)
        {
            var result = await argument as List <Attachment>;

            context.UserData.SetValue("doc2", result[0]);

            var dmp = new diff_match_patch()
            {
                Diff_EditCost = 10
            };

            var doc1 = context.UserData.GetValue <Attachment>("doc1");
            var doc2 = context.UserData.GetValue <Attachment>("doc2");

            var text1 = "";
            var text2 = "";

            using (HttpClient httpClient = new HttpClient())
            {
                var response1 = await httpClient.GetAsync(doc1.ContentUrl);

                var jobject1 = JObject.Parse(response1.Content.ReadAsStringAsync().Result);
                var token1   = jobject1.SelectToken("data");
                var bytes1   = token1.ToObject <byte[]>();
                text1 = System.Text.Encoding.UTF8.GetString(bytes1);

                var response2 = await httpClient.GetAsync(doc2.ContentUrl);

                var jobject2 = JObject.Parse(response2.Content.ReadAsStringAsync().Result);
                var token2   = jobject2.SelectToken("data");
                var bytes2   = token2.ToObject <byte[]>();
                text2 = System.Text.Encoding.UTF8.GetString(bytes2);
            }

            var diffs = dmp.diff_main(text1, text2);

            dmp.diff_cleanupSemantic(diffs);
            var htmlContent = dmp.diff_prettyHtml(diffs);

            var html = "<div style='border: #181818 solid 1px; width: 550px; margin: 0 auto; margin-top: 100px; padding: 30px; box-shadow: 10px 10px 5px grey;'>";

            html += htmlContent + "</div>";

            StreamWriter sw = new StreamWriter(diffFile, false);

            sw.Write(html);
            sw.Flush();
            sw.Close();

            await context.PostAsync($"Ich habe {diffs.Count} unterschiedliche Stellen gefunden.\n\n Die Änderungen habe ich dir in die Datei 'differences.html' in dein Verzeichnis gelegt.");

            PromptDialog.Choice(context, Unterschied3, new string[] { "ja", "nein" }, "Willst du die Datei gleich öffnen?", promptStyle: PromptStyle.PerLine, descriptions: new string[] { "Ja, bitte im Browser öffnen", "Nein zurück zur Auswahl" });
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            diff_match_patch dmp = new diff_match_patch();

            // Execute one reverse diff as a warmup.
            var result  = dmp.diff_main("Hello World!123", "Hello World, How are you??");
            var result1 = dmp.diff_prettyHtml(result);

            GC.Collect();
            GC.WaitForPendingFinalizers();


            Console.WriteLine("Hello World!");
        }
Exemplo n.º 14
0
        public void HtmlOutputNotEqualDelInsTest(string str)
        {
            //Arrange
            var dmp           = new diff_match_patch();
            var anotherString = "String";

            //Act
            var diffs = dmp.diff_main(str, anotherString);
            var html  = dmp.diff_prettyHtml(diffs);

            //Assert
            Assert.Contains("del", html);
            Assert.Contains("ins", html);
        }
Exemplo n.º 15
0
        public void HtmlOutputEqualTest(string str)
        {
            //Arrange
            var dmp           = new diff_match_patch();
            var anotherString = "String";

            //Act
            var diffs = dmp.diff_main(str, anotherString);
            var html  = dmp.diff_prettyHtml(diffs);

            //Assert
            Assert.Contains("span", html);
            Assert.DoesNotContain("del", html);
            Assert.DoesNotContain("ins", html);
            Assert.Equal("<span>String</span>", html);
        }
Exemplo n.º 16
0
        public static string GetHTMLDiff(this List <BackupDetail> list, string id)
        {
            var backupDetail       = list.Get(id);
            var localFileLocation  = Path.Combine(BackupDetails.ServerDir(), backupDetail.BackupDirectory.ToString(), backupDetail.SavedName);
            var remoteFileLocation = Path.Combine(BackupDetails.ServerDir(), "temp", backupDetail.ActualName);

            var localFileContents  = File.ReadAllText(localFileLocation);
            var remoteFileContents = File.ReadAllText(remoteFileLocation);

            diff_match_patch dmp  = new diff_match_patch();
            List <Diff>      diff = dmp.diff_main(localFileContents, remoteFileContents);

            dmp.diff_cleanupSemantic(diff);
            var html = dmp.diff_prettyHtml(diff).Replace("&para;", "");

            return(html);
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            string before = StringData.Before;
            string after  = StringData.After;

            //string before = @$"測試文字123";
            //string after = @$"測試文字456";

            diff_match_patch dmp  = new diff_match_patch();
            List <Diff>      diff = dmp.diff_main(before, after);

            // Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")]
            dmp.diff_cleanupSemantic(diff);
            // Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")]
            for (int i = 0; i < diff.Count; i++)
            {
                switch (diff[i].operation)
                {
                case Operation.EQUAL:     //未修改字段
                    Console.Write(diff[i].text);
                    break;

                case Operation.DELETE:                            //刪除字段
                    Console.BackgroundColor = ConsoleColor.Red;   //紅色背景
                    Console.Write(diff[i].text);
                    Console.BackgroundColor = ConsoleColor.Black; //還原為黑色背景
                    break;

                case Operation.INSERT:                            //新增字段
                    Console.BackgroundColor = ConsoleColor.Green; //綠色背景
                    Console.Write(diff[i].text);
                    Console.BackgroundColor = ConsoleColor.Black; //還原為黑色背景
                    break;

                default:
                    break;
                }
            }

            string html = dmp.diff_prettyHtml(diff);

            Console.WriteLine("Html結果-------------------------------");
            Console.WriteLine(html);
            Console.ReadKey();
        }
Exemplo n.º 18
0
        public static string DiffTwoFiles(string file1, string file2)
        {
            diff_match_patch dmp = new diff_match_patch();

            dmp.Diff_Timeout = 0;

            List <Diff> diffs;

            using (StreamReader r = new StreamReader(File.Open(file1, FileMode.Open)))
                using (StreamReader r2 = new StreamReader(File.Open(file2, FileMode.Open)))
                {
                    diffs = dmp.diff_main(r.ReadToEnd(), r2.ReadToEnd());
                    dmp.diff_cleanupEfficiency(diffs);
                    dmp.diff_cleanupSemantic(diffs);
                }

            return(dmp.diff_prettyHtml(diffs));
        }
        public void Diff(ITaskContext context, string newConfigPath, string oldConfigPath, string htmlExportPath)
        {
            string newConfig = File.ReadAllText(newConfigPath);

            if (Contains(newConfig, "todo", StringComparison.InvariantCultureIgnoreCase) ||
                Contains(newConfig, "tbd", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new TaskExecutionException(
                          $"Config: '{newConfigPath}' contains todo or tbd! Check and fix config.", 99);
            }

            if (!File.Exists(oldConfigPath))
            {
                context.LogInfo($"old config not found '{oldConfigPath}'. Skipping compare.");
                return;
            }

            context.LogInfo($"Comparing {oldConfigPath}, {newConfigPath}");

            var oldCOnf          = File.ReadAllText(oldConfigPath);
            diff_match_patch dmp = new diff_match_patch();

            dmp.Diff_EditCost = 4;
            List <Diff> diff = dmp.diff_main(oldCOnf, newConfig);

            if (diff.Count == 1)
            {
                if (diff[0].operation == Operation.EQUAL)
                {
                    context.LogInfo("Configs are the same");
                    return;
                }
            }

            _anyDiffsInConfigs = true;
            context.LogInfo($"Configs are not the same. Generating report {htmlExportPath}.");

            dmp.diff_cleanupSemantic(diff);
            var html = dmp.diff_prettyHtml(diff);

            File.WriteAllText(htmlExportPath, html);
        }
Exemplo n.º 20
0
        public MemberCompareDisplay(Member MemberA, Member MemberB)
        {
            InitializeComponent();

            this.Text = MemberA.GetLibrary() + "/" + MemberA.GetObject() + "." + MemberA.GetMember() + " -> " + MemberB.GetLibrary() + "/" + MemberB.GetObject() + "." + MemberB.GetMember();

            var    dmp   = new diff_match_patch();
            var    res   = dmp.diff_main(File.ReadAllText(MemberA.GetLocalFile()), File.ReadAllText(MemberB.GetLocalFile()), false);
            string html  = dmp.diff_prettyHtml(res);
            string style = @"<head>
    <meta charset=" + '"' + "utf-8" + '"' + @" />
      <style>
          body {
                font-family: " + '"' + "Lucida Console" + '"' + @", Monaco, monospace
            }
    </style>
</head> ";

            webBrowser1.DocumentText = style + html;
        }
Exemplo n.º 21
0
        private void GenerateDiff(MarkdownPage page, string newPage)
        {
            var diffEngine = new diff_match_patch();

            var a         = diffEngine.diff_linesToChars(page.Content, newPage);
            var text1     = (string)a[0];
            var text2     = (string)a[1];
            var lineArray = (List <string>)a[2];


            var diff = diffEngine.diff_main(text1, text2, false);

            diffEngine.diff_charsToLines(diff, lineArray);

            diffEngine.diff_cleanupSemantic(diff);

            var htmlDiff = diffEngine.diff_prettyHtml(diff);

            Frame.Navigate(typeof(ImportDiffPage), Tuple.Create(diff, Page.Id));
        }
Exemplo n.º 22
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            DiffTextRequest request = await req.Content.ReadAsAsync <DiffTextRequest>();

            diff_match_patch dmp = new diff_match_patch();

            // Execute one reverse diff as a warmup.
            var result = dmp.diff_prettyHtml(dmp.diff_main(request.SourceText, request.DestinationText));

            result = result.Replace("ins", "span").Replace("del", "span").Replace("=\"background:#ffe6e6;\"", "='color: Blue;'").Replace("=\"background:#e6ffe6;\"", "='color: Red;'");

            //result = result.Replace("del", "span").Replace("background:#ffe6e6;", "background:#ffe6e6;text-decoration:line-through");
            GC.Collect();
            GC.WaitForPendingFinalizers();

            return(string.IsNullOrEmpty(result)
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Please check request body")
                : req.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 23
0
 /// <summary>
 /// Creates an html report
 /// </summary>
 /// <param name="dmp">The diff match path utility</param>
 /// <param name="baseFile">The file used as base to compare</param>
 /// <param name="compareFile">The file to compare with</param>
 /// <param name="baseFileHtmlResult">The diff founds in the base file as html encoding</param>
 /// <param name="compareFileHtmlResult">The diff founds in the compare file as html encoding</param>
 public static void CreateHtmlReport(this diff_match_patch dmp, FileInfo baseFile, FileInfo compareFile, out String baseFileHtmlResult, out String compareFileHtmlResult)
 {
     baseFileHtmlResult    = dmp.diff_prettyHtml(dmp.CompareFiles(baseFile.FullName, compareFile.FullName)).Replace("\r&para;", "");
     compareFileHtmlResult = dmp.diff_prettyHtml(dmp.CompareFiles(compareFile.FullName, baseFile.FullName)).Replace("\r&para;", "");
 }