/// <summary> /// Merge lines /// </summary> public void Merge(Lines lines) { var diff = new SimpleDiff <Line>(this, lines); var iLine = -1; diff.LineUpdate += (o, e) => { if (e.DiffType == DiffType.Inserted) { if (this[iLine].SubLines == null) { this[iLine].SubLines = new Lines(); } e.LineValue.State = DiffType.Inserted; this[iLine].SubLines.Add(e.LineValue); } else { iLine++; this[iLine].State = e.DiffType; if (iLine > 0 && this[iLine - 1].State == DiffType.Deleted && this[iLine - 1].SubLines == null && e.DiffType == DiffType.None) { this[iLine - 1].SubLines = new Lines(); } } }; //запускаем алгоритм нахождения максимальной подпоследовательности (LCS) diff.RunDiff(); }
/// <summary> /// Merge lines /// </summary> public void Merge(Lines lines) { SimpleDiff <Line> diff = new SimpleDiff <Line>(this, lines); int iLine = -1; diff.LineUpdate += (o, e) => { if (e.DiffType == DiffType.Inserted) { if (this[iLine].subLines == null) { this[iLine].subLines = new Lines(); } e.LineValue.state = DiffType.Inserted; this[iLine].subLines.Add(e.LineValue); } else { iLine++; this[iLine].state = e.DiffType; if (iLine > 0 && this[iLine - 1].state == DiffType.Deleted && this[iLine - 1].subLines == null && e.DiffType == DiffType.None) { this[iLine - 1].subLines = new Lines(); } } }; diff.RunDiff(); }
/// <summary> /// 文書の末尾に操作の情報を出力する. /// </summary> private void outputMethod(ref Document document, MethodVO changedMethod) { // パラグラフを追加 document.Content.Paragraphs.Add(); addAttributeText(ref document, WdColorIndex.wdBlack, "■操作: " + changedMethod.name + "[" + changedMethod.alias + "]" + "\r\n"); addAttributeText_detail(ref document, WdColorIndex.wdBlack, "ID: " + changedMethod.guid + "\r\n"); addAttributeText_detail(ref document, WdColorIndex.wdBlack, changedMethod.notes + "\r\n"); this.diffBuffer = new StringBuilder(); string leftText, rightText; leftText = changedMethod.srcMethod.behavior; rightText = changedMethod.destMethod.behavior; var simpleDiff = new SimpleDiff <string>(leftText.Split('\n'), rightText.Split('\n')); simpleDiff.LineUpdate += new EventHandler <DiffEventArgs <string> > (BehaviorDiff_LineUpdate); simpleDiff.RunDiff(); // パラグラフを追加 document.Content.Paragraphs.Add(); addAttributeText(ref document, WdColorIndex.wdBlack, "[ふるまい]------------------" + "\r\n"); outputTextWithDiffMarked(ref document, diffBuffer.ToString().Split('\n')); addAttributeText(ref document, WdColorIndex.wdBlack, "------------------" + "\r\n"); }
private void CheckOutput(string expectedResultPath, Stream outputStream) { Assert.IsNotNull(outputStream, "Template did not produce output"); using (var reader = new StreamReader(outputStream)) { var result = reader.ReadToEnd(); if (File.Exists(expectedResultPath)) { using (var expectedResultReader = File.OpenText(expectedResultPath)) { var expectedResult = expectedResultReader.ReadToEnd(); string[] expectedResultLines = expectedResult.Split('\n'); string[] resultLines = result.Split('\n'); var simpleDiff = new SimpleDiff <string>(expectedResultLines, resultLines); StringBuilder message = new StringBuilder(); int differences = 0; simpleDiff.LineUpdate += (s, e) => { string indicator = ""; switch (e.DiffType) { case DiffType.Add: indicator = "++"; differences++; break; case DiffType.Subtract: indicator = "--"; differences++; break; case DiffType.None: indicator = "=="; break; } message.AppendLine($"{indicator}{e.LineValue.Replace("\r", "")}"); }; simpleDiff.RunDiff(); if (message.Length > 0) { Assert.AreEqual(0, differences, "\n" + message.ToString()); } } } else { using (var expectedResultWriter = File.OpenWrite(expectedResultPath)) { using (var writer = new StreamWriter(expectedResultWriter)) { writer.Write(result); } } Assert.Inconclusive($"\"{expectedResultPath}\" was not found... creating file based on current result."); } } }
private void addTaggedValueBox(int rowIndex, ArtifactXmlReader reader, TaggedValueVO tgv) { int longerLine; TaggedValueVO leftTgv = tgv; TaggedValueVO rightTgv = tgv; string leftText = ""; string rightText = ""; ListBox listL = makeNewListBox(); ListBox listR = makeNewListBox(); switch (tgv.changed) { case 'U': leftTgv = reader.readTaggedValueDiffDetail(tgv.guid, "L"); rightTgv = reader.readTaggedValueDiffDetail(tgv.guid, "R"); DiffPresenter.getDisagreedTaggedValueDesc(leftTgv, rightTgv, ref leftText, ref rightText); leftDiffBuffer = new StringBuilder(); rightDiffBuffer = new StringBuilder(); var simpleDiff = new SimpleDiff <string>(leftText.Split('\n'), rightText.Split('\n')); simpleDiff.LineUpdate += new EventHandler <DiffEventArgs <string> >(ElementDiff_LineUpdate); simpleDiff.RunDiff(); leftText = leftDiffBuffer.ToString(); rightText = rightDiffBuffer.ToString(); selectedTag = rightTgv; leftDiffBuffer.Clear(); rightDiffBuffer.Clear(); break; case 'C': rightTgv = reader.readTaggedValueDiffDetail(tgv.guid, "R"); DiffPresenter.getMonoTaggedValueDesc(rightTgv, ref rightText); selectedTag = rightTgv; break; case 'D': leftTgv = reader.readTaggedValueDiffDetail(tgv.guid, "L"); DiffPresenter.getMonoTaggedValueDesc(leftTgv, ref leftText); selectedTag = leftTgv; break; default: break; } longerLine = getLongerLine(leftText, rightText); setListItems(listL, leftText); setListItems(listR, rightText); setListBoxSize(listL, leftText, longerLine); setListBoxSize(listR, rightText, longerLine); if (tgv.changed == 'D' || tgv.changed == 'U') { listL.Tag = leftTgv; listL.ContextMenuStrip = contextMenuStrip1; listL.Click += new System.EventHandler(this.TaggedValueListClick); // listL.Click += new System.EventHandler(this.MethodTextClick); } if (tgv.changed == 'C' || tgv.changed == 'U') { listR.Tag = rightTgv; listR.ContextMenuStrip = contextMenuStrip1; listR.Click += new System.EventHandler(this.TaggedValueListClick); // listR.Click += new System.EventHandler(this.MethodTextClick); } tableLayoutPanel1.Controls.Add(listL, 0, rowIndex); tableLayoutPanel1.Controls.Add(listR, 1, rowIndex); return; }
/// <summary> /// 操作の表示項目を追加する /// </summary> /// <param name="mergedElem"></param> /// <param name="leftElem"></param> /// <param name="rightElem"></param> /// <param name="rowIndex"></param> void addItemMethods(ElementVO mergedElem, ref int rowIndex) { MethodVO leftMth, rightMth; string leftText, rightText; int longerLine; // マージ済要素のメソッド(何か内容に差異のあったメソッド)分ループ foreach (MethodVO m in mergedElem.methods) { leftMth = m; rightMth = m; ListBox listL = new ListBox(); listL.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listL.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); ListBox listR = new ListBox(); listR.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listR.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); // メソッドVOのchangedの値にしたがって左右のテキストの内容を設定する leftText = ""; rightText = ""; switch (m.changed) { case 'U': leftMth = m.srcMethod; rightMth = m.destMethod; getDisagreedMethodDesc(leftMth, rightMth, ref leftText, ref rightText); leftDiffBuffer = new StringBuilder(); rightDiffBuffer = new StringBuilder(); var simpleDiff = new SimpleDiff <string>(leftText.Split('\n'), rightText.Split('\n')); simpleDiff.LineUpdate += new EventHandler <DiffEventArgs <string> > (ElementDiff_LineUpdate); simpleDiff.RunDiff(); leftText = leftDiffBuffer.ToString(); rightText = rightDiffBuffer.ToString(); break; case 'C': // rightMth = searchMethodByGuid(rightElement.methods, m.guid); getMonoMethodDesc(rightMth, ref rightText); break; case 'D': // leftMth = searchMethodByGuid(leftElement.methods, m.guid); getMonoMethodDesc(leftMth, ref leftText); break; default: break; } longerLine = getLongerLine(leftText, rightText); setListItems(listL, leftText); setListItems(listR, rightText); setListBoxSize(listL, leftText, longerLine); setListBoxSize(listR, rightText, longerLine); if (m.changed == 'D' || m.changed == 'U') { listL.ContextMenuStrip = contextMenuStrip1; } if (m.changed == 'C' || m.changed == 'U') { listR.ContextMenuStrip = contextMenuStrip1; } tableLayoutPanel1.Controls.Add(listL, 0, rowIndex); tableLayoutPanel1.Controls.Add(listR, 1, rowIndex); rowIndex++; } }
/// <summary> /// 属性の表示項目を追加する /// </summary> /// <param name="mergedElem"></param> /// <param name="rowIndex"></param> void addItemAttributes(ElementVO mergedElem, ref int rowIndex) { AttributeVO leftAttr, rightAttr; string leftText, rightText; int longerLine; // マージ済要素のメソッド(何か内容に差異のあったメソッド)分ループ foreach (AttributeVO att in mergedElem.attributes) { leftAttr = att; rightAttr = att; ListBox listL = new ListBox(); listL.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listL.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); ListBox listR = new ListBox(); listR.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listR.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); // メソッドVOのchangedの値にしたがって左右のテキストの内容を設定する leftText = ""; rightText = ""; switch (att.changed) { case 'U': leftAttr = att.srcAttribute; rightAttr = att.destAttribute; getDisagreedAttributeDesc(leftAttr, rightAttr, ref leftText, ref rightText); leftDiffBuffer = new StringBuilder(); rightDiffBuffer = new StringBuilder(); var simpleDiff = new SimpleDiff <string>(leftText.Split('\n'), rightText.Split('\n')); simpleDiff.LineUpdate += new EventHandler <DiffEventArgs <string> >(ElementDiff_LineUpdate); simpleDiff.RunDiff(); leftText = leftDiffBuffer.ToString(); rightText = rightDiffBuffer.ToString(); break; case 'C': getMonoAttributeDesc(rightAttr, ref rightText); break; case 'D': getMonoAttributeDesc(leftAttr, ref leftText); break; default: break; } longerLine = getLongerLine(leftText, rightText); setListItems(listL, leftText); setListItems(listR, rightText); setListBoxSize(listL, leftText, longerLine); setListBoxSize(listR, rightText, longerLine); if (att.changed == 'D' || att.changed == 'U') { listL.ContextMenuStrip = contextMenuStrip1; } if (att.changed == 'C' || att.changed == 'U') { listR.ContextMenuStrip = contextMenuStrip1; } tableLayoutPanel1.Controls.Add(listL, 0, rowIndex); tableLayoutPanel1.Controls.Add(listR, 1, rowIndex); rowIndex++; } }
private void addElementLabels(ElementVO elem) { int rowIndex = 0; string leftText, rightText; int longerLine; AttributeVO leftAttr, rightAttr; MethodVO leftMth, rightMth; string artifactsDir = ProjectSetting.getVO().projectPath + "\\" + ProjectSetting.getVO().artifactsPath; ArtifactXmlReader reader = new ArtifactXmlReader(artifactsDir); tableLayoutPanel1.RowCount = elem.attributes.Count + elem.methods.Count; foreach (AttributeVO a in elem.attributes) { leftAttr = a; rightAttr = a; leftText = ""; rightText = ""; // TextBox txtL = new TextBox(); // txtL.BackColor = Color.LightCyan; // // TextBox txtR = new TextBox(); // txtR.BackColor = Color.LightYellow; ListBox listL = new ListBox(); listL.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listL.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); ListBox listR = new ListBox(); listR.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listR.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); switch (a.changed) { case 'U': leftAttr = reader.readAttributeDiffDetail(a.guid, "L"); rightAttr = reader.readAttributeDiffDetail(a.guid, "R"); getDisagreedAttributeDesc(leftAttr, rightAttr, ref leftText, ref rightText); break; case 'C': rightAttr = reader.readAttributeDiffDetail(a.guid, "R"); getMonoAttributeDesc(rightAttr, ref rightText); break; case 'D': leftAttr = reader.readAttributeDiffDetail(a.guid, "L"); getMonoAttributeDesc(leftAttr, ref leftText); break; default: break; } longerLine = getLongerLine(leftText, rightText); setListItems(listL, leftText); setListItems(listR, rightText); setListBoxSize(listL, leftText, longerLine); setListBoxSize(listR, rightText, longerLine); // txtR.Text = rightText; // txtL.Text = leftText; // setTextBoxSize(txtL, leftText, longerLine); // setTextBoxSize(txtR, rightText, longerLine); if (a.changed == 'D' || a.changed == 'U') { listL.Tag = leftAttr; listL.ContextMenuStrip = contextMenuStrip1; listL.Click += new System.EventHandler(this.AttributeListClick); // listL.Click += new System.EventHandler(this.AttributeTextClick); } if (a.changed == 'C' || a.changed == 'U') { listR.Tag = rightAttr; listR.ContextMenuStrip = contextMenuStrip1; listR.Click += new System.EventHandler(this.AttributeListClick); // listR.Click += new System.EventHandler(this.AttributeTextClick); } tableLayoutPanel1.Controls.Add(listL, 0, rowIndex); tableLayoutPanel1.Controls.Add(listR, 1, rowIndex); rowIndex++; } foreach (MethodVO m in elem.methods) { leftMth = m; rightMth = m; leftText = ""; rightText = ""; // TextBox txtL = new TextBox(); // txtL.BackColor = Color.White; // // TextBox txtR = new TextBox(); // txtR.BackColor = Color.White; ListBox listL = new ListBox(); listL.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listL.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); ListBox listR = new ListBox(); listR.DrawMode = DrawMode.OwnerDrawFixed; // EventHandlerの追加 listR.DrawItem += new DrawItemEventHandler(ListBox_DrawItem); switch (m.changed) { case 'U': leftMth = reader.readMethodDiffDetail(m.guid, "L"); rightMth = reader.readMethodDiffDetail(m.guid, "R"); getDisagreedMethodDesc(leftMth, rightMth, ref leftText, ref rightText); leftDiffBuffer = new StringBuilder(); rightDiffBuffer = new StringBuilder(); var simpleDiff = new SimpleDiff <string>(leftText.Split('\n'), rightText.Split('\n')); simpleDiff.LineUpdate += new EventHandler <DiffEventArgs <string> > (ElementDiff_LineUpdate); simpleDiff.RunDiff(); leftText = leftDiffBuffer.ToString(); rightText = rightDiffBuffer.ToString(); leftDiffBuffer.Clear(); rightDiffBuffer.Clear(); break; case 'C': rightMth = reader.readMethodDiffDetail(m.guid, "R"); getMonoMethodDesc(rightMth, ref rightText); break; case 'D': leftMth = reader.readMethodDiffDetail(m.guid, "L"); getMonoMethodDesc(leftMth, ref leftText); break; default: break; } longerLine = getLongerLine(leftText, rightText); setListItems(listL, leftText); setListItems(listR, rightText); setListBoxSize(listL, leftText, longerLine); setListBoxSize(listR, rightText, longerLine); // txtL.Text = leftText; // txtR.Text = rightText; // setTextBoxSize(txtL, leftText, longerLine); // setTextBoxSize(txtR, rightText, longerLine); if (m.changed == 'D' || m.changed == 'U') { listL.Tag = leftMth; listL.ContextMenuStrip = contextMenuStrip1; listL.Click += new System.EventHandler(this.MethodListClick); // listL.Click += new System.EventHandler(this.MethodTextClick); } if (m.changed == 'C' || m.changed == 'U') { listR.Tag = rightMth; listR.ContextMenuStrip = contextMenuStrip1; listR.Click += new System.EventHandler(this.MethodListClick); // listR.Click += new System.EventHandler(this.MethodTextClick); } tableLayoutPanel1.Controls.Add(listL, 0, rowIndex); tableLayoutPanel1.Controls.Add(listR, 1, rowIndex); rowIndex++; } }