public override void Execute(Diff diff) { foreach (var file in diff.Files) { Console.WriteLine("---------------------"); Console.WriteLine(file.FileName); Console.WriteLine("---------------------"); foreach (var section in file.FileSections) { Console.WriteLine(section.Description); if (file.FileChangeType == FileChangeType.Deleted) { if (!ShowDeletedFileContents) { Console.WriteLine("[File Deleted]"); continue; } } if (file.FileChangeType == FileChangeType.Created) { if (!ShowCreatedFileContents) { Console.WriteLine("[New File]"); continue; } } foreach (var line in section.Lines) { switch (line.LineChangeType) { case LineChangeType.Add: Console.Write("++++ "); break; case LineChangeType.Delete: Console.Write("---- "); break; default: Console.Write(" "); break; } Console.WriteLine(line.Text); } } Console.WriteLine(); } }
public Diff Read() { using (var stream = File.OpenText(FilePath)) { var diff = new Diff(); string line; while ((line = stream.ReadLine()) != null) { // process each line into the word doc diff.ProcessLine(line); } return diff; } }
public override void Execute(Diff diff) { var doc = DocX.Create(_outputPath); doc.PageLayout.Orientation = Orientation.Landscape; // TODO: set margins smaller than defaults var needPageBreak = false; if (!String.IsNullOrEmpty(Title)) { doc.InsertParagraph(Title).Bold().FontSize(24); } if (!String.IsNullOrEmpty(Summary)) { doc.InsertParagraph(Summary).FontSize(12); needPageBreak = true; } if (needPageBreak) { PageBreakOrLineBreak(doc); } foreach (var file in diff.Files) { var paragraph = doc.InsertParagraph(file.FileName); paragraph.Bold().FontSize(16); if (file.FileChangeType == FileChangeType.Deleted) { paragraph.Color(Color.DarkRed); if (!ShowDeletedFileContents) { doc.InsertParagraph("[File Deleted]").FontSize(14).Bold().Color(Color.DarkRed); PageBreakOrLineBreak(doc); continue; } } if (file.FileChangeType == FileChangeType.Created) { paragraph.Color(Color.DarkGreen); if (!ShowCreatedFileContents) { doc.InsertParagraph("[New File]").FontSize(14).Bold().Color(Color.DarkGreen); PageBreakOrLineBreak(doc); continue; } } var table = doc.InsertTable(1, 3); table.AutoFit = AutoFit.Window; table.SetBorder(TableBorderType.Top, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); table.SetBorder(TableBorderType.Bottom, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); var i = 0; foreach (var section in file.FileSections) { var row = i == 0 ? table.Rows[0] : table.InsertRow(); row.Cells[0].Width = 2.0; row.Cells[1].Width = 2.0; row.Cells[2].Width = 96.0; row.Cells[0].Paragraphs[0].Append("...").FontSize(11).Color(Color.DarkGray); row.Cells[1].Paragraphs[0].Append("...").FontSize(11).Color(Color.DarkGray); row.Cells[2].Paragraphs[0].Append(section.Description).FontSize(11).Color(Color.DarkGray); row.Cells[0].FillColor = Color.LightGray; row.Cells[1].FillColor = Color.LightGray; row.Cells[2].FillColor = Color.LightGray; row.Cells[0].SetBorder(TableCellBorderType.Left, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); row.Cells[0].SetBorder(TableCellBorderType.Right, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); row.Cells[1].SetBorder(TableCellBorderType.Right, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); row.Cells[2].SetBorder(TableCellBorderType.Right, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); foreach (var line in section.Lines) { row = table.InsertRow(); row.Cells[0].Width = 2.0; row.Cells[1].Width = 2.0; row.Cells[2].Width = 96.0; var fontColor = Color.FromArgb(1, 20, 20, 20); var backgroundColor = Color.White; var firstChar = " "; switch (line.LineChangeType) { case LineChangeType.Add: fontColor = Color.Black; backgroundColor = Color.LightGreen; firstChar = "+"; break; case LineChangeType.Delete: fontColor = Color.DarkRed; backgroundColor = Color.LightPink; firstChar = "-"; break; } row.Cells[0].Paragraphs[0].Append(line.OldLineNumber.ToString()).FontSize(11).Color(Color.DarkGray); row.Cells[1].Paragraphs[0].Append(line.NewLineNumber.ToString()).FontSize(11).Color(Color.DarkGray); row.Cells[2].Paragraphs[0].Append(firstChar + line.Text).FontSize(11).Color(fontColor); row.Cells[0].FillColor = backgroundColor; row.Cells[1].FillColor = backgroundColor; row.Cells[2].FillColor = backgroundColor; row.Cells[0].SetBorder(TableCellBorderType.Left, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); row.Cells[0].SetBorder(TableCellBorderType.Right, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); row.Cells[1].SetBorder(TableCellBorderType.Right, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); row.Cells[2].SetBorder(TableCellBorderType.Right, new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.LightGray)); } i++; } PageBreakOrLineBreak(doc); } doc.Save(); }
public override void Execute(Diff diff) { var html = new StringBuilder(); html.AppendLine("<html>"); html.AppendLine("<head>"); html.AppendLine(" <style>"); html.AppendLine(" .created { color: #006400; }"); html.AppendLine(" .deleted { color: #8B0000; }"); html.AppendLine(" table { border: 1px solid #D3D3D3; border-collapse:collapse; }"); html.AppendLine(" td { border-left: 1px solid #D3D3D3; border-right: 1px solid #D3D3D3; }"); html.AppendLine(" tr { color: #141414; }"); html.AppendLine(" tr.section { color: #A9A9A9; background-color: #D3D3D3; }"); html.AppendLine(" tr.addition { color: #000000; background-color: #90EE90; }"); html.AppendLine(" tr.deletion { color: #8B0000; background-color: #FFB6C1; }"); html.AppendLine(" td.lineNumber { color: #A9A9A9; }"); html.AppendLine(" </style>"); html.AppendLine("</head>"); html.AppendLine("<body>"); if (!String.IsNullOrEmpty(Title)) { html.AppendLine(String.Format("<h1>{0}</h1>", Title)); } if (!String.IsNullOrEmpty(Summary)) { html.AppendLine(String.Format("<div class\"summary\">{0}</div>", Summary)); } foreach (var file in diff.Files) { var className = ""; if (file.FileChangeType == FileChangeType.Deleted) { className = "deleted"; } else if (file.FileChangeType == FileChangeType.Created) { className = "created"; } html.AppendLine(" <h2 class=\"" + className + "\">" + file.FileName + "</h2>"); if (file.FileChangeType == FileChangeType.Deleted) { if (!ShowDeletedFileContents) { html.AppendLine(" <div class=\"" + className + "\">[File Deleted]</div>"); continue; } } if (file.FileChangeType == FileChangeType.Created) { if (!ShowCreatedFileContents) { html.AppendLine(" <div class=\"" + className + "\">[New File]</div>"); continue; } } html.AppendLine(" <table width=\"100%\">"); foreach (var section in file.FileSections) { html.AppendLine(" <tr class=\"section\">"); html.AppendLine(" <td width=\"2%\" class=\"lineNumber\">...</td>"); html.AppendLine(" <td width=\"2%\" class=\"lineNumber\">...</td>"); html.AppendLine(" <td width=\"96%\">" + section.Description + "</td>"); html.AppendLine(" </tr>"); foreach (var line in section.Lines) { className = ""; var firstChar = " "; switch (line.LineChangeType) { case LineChangeType.Add: className = "addition"; firstChar = "+"; break; case LineChangeType.Delete: className = "deletion"; firstChar = "-"; break; } html.AppendLine(" <tr class=\"" + className + "\">"); html.AppendLine(" <td class=\"lineNumber\">" + line.OldLineNumber + "</td>"); html.AppendLine(" <td class=\"lineNumber\">" + line.NewLineNumber + "</td>"); html.AppendLine(" <td >" + firstChar + line.Text + "</td>"); html.AppendLine(" </tr>"); } } html.AppendLine(" </table>"); } html.AppendLine("</body>"); html.AppendLine("</html>"); if (File.Exists(_outputPath)) File.Delete(_outputPath); using (var outputFile = File.CreateText(_outputPath)) outputFile.Write(html.ToString()); }