public Results(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double seconds) { InitializeComponent(); this.Text = string.Format("Results: {0} secs.",seconds.ToString("#0.00")); ListViewItem lviS; ListViewItem lviD; int cnt = 1; int i; foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.Red; lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line); lviD.BackColor = Color.LightGray; lviD.SubItems.Add(""); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.White; lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex+i)).Line); lviD.BackColor = Color.White; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex+i)).Line); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.LightGray; lviS.SubItems.Add(""); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex+i)).Line); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { lviS = new ListViewItem(cnt.ToString("00000")); lviD = new ListViewItem(cnt.ToString("00000")); lviS.BackColor = Color.Red; lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex+i)).Line); lviD.BackColor = Color.LightGreen; lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex+i)).Line); lvSource.Items.Add(lviS); lvDestination.Items.Add(lviD); cnt++; } break; } } }
/// <summary> /// Gets the text diff for table /// </summary> /// <param name="tableName"></param> /// <returns></returns> public void GetTableDiffReport(string tableName, out DiffList_TextFile sLF, out DiffList_TextFile dLF, out ArrayList rep) { TableCollection leftDataBaseTables = Global.Serv1.Databases[Global.SelectedDB].Tables; TableCollection rightDataBaseTables = Global.Serv1.Databases[_rightDataBase.Name].Tables; Table tableRight = rightDataBaseTables[tableName]; Table tableLeft = leftDataBaseTables[tableName]; ScriptingOptions scriptingOptions = new ScriptingOptions(); scriptingOptions.Add(ScriptOption.NoCollation); scriptingOptions.Add(ScriptOption.NoFileGroup); scriptingOptions.Add(ScriptOption.NoExecuteAs); StringCollection scriptLeft = tableLeft.Script(scriptingOptions); StringCollection scriptRight = tableRight.Script(scriptingOptions); string leftSql = scriptLeft[scriptLeft.Count-1].Replace("\r", "").Replace("\t", "").ToLower(); string rightSql = scriptRight[scriptRight.Count-1].Replace("\r", "").Replace("\t", "").ToLower(); sLF = new DiffList_TextFile(leftSql); dLF = new DiffList_TextFile(rightSql); rep = TextDiff(sLF, dLF); }
/// <summary> /// Use DifferenceEngine to calculate Differences /// </summary> /// <param name="sFile"></param> /// <param name="dFile"></param> private ArrayList TextDiff(DiffList_TextFile sLF, DiffList_TextFile dLF) { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, DifferenceEngine.DiffEngineLevel.SlowPerfect); ArrayList rep = de.DiffReport(); return rep; }
private void TextDiff(string sFile, string dFile) { this.Cursor = Cursors.WaitCursor; DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(ex.Message,"File Error"); return; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF,dLF,_level); ArrayList rep = de.DiffReport(); Results dlg = new Results(sLF,dLF,rep,time); dlg.TopMost = true; dlg.ShowDialog(); dlg.Dispose(); dlg.TopMost = false; } catch (Exception ex) { this.Cursor = Cursors.Default; string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(tmp,"Compare Error"); return; } this.Cursor = Cursors.Default; }
public void BindData(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines) { DataTable dt = XmlHelper.GetBindTable(); int cnt = 1; int i; foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: for (i = 0; i < drs.Length; i++) { DataRow dr = dt.NewRow(); dr["OldKey"] = cnt.ToString("00000"); dr["NewKey"] = cnt.ToString("00000"); dr["OldValue"] = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; dr["NewValue"] = ""; dr["CombinKey"] = cnt.ToString("00000"); dr["CombinValue"] = this.DeleteCheckBox.Checked ? "":((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; dr["Status"] = "Delete"; dt.Rows.Add(dr); cnt++; } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { DataRow dr = dt.NewRow(); dr["OldKey"] = cnt.ToString("00000"); dr["NewKey"] = cnt.ToString("00000"); dr["OldValue"] = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; dr["NewValue"] = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; dr["Status"] = "Unchanged"; dr["CombinKey"] = cnt.ToString("00000"); dr["CombinValue"] = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; dt.Rows.Add(dr); cnt++; } break; case DiffResultSpanStatus.AddDestination: for (i = 0; i < drs.Length; i++) { DataRow dr = dt.NewRow(); dr["OldKey"] = cnt.ToString("00000"); dr["NewKey"] = cnt.ToString("00000"); dr["OldValue"] = ""; dr["NewValue"] = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line; dr["Status"] = "Add"; dr["CombinKey"] = cnt.ToString("00000"); dr["CombinValue"] = this.GetNewCheckBox.Checked ? ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line: ""; dt.Rows.Add(dr); } break; case DiffResultSpanStatus.Replace: for (i = 0; i < drs.Length; i++) { DataRow dr = dt.NewRow(); dr["OldKey"] = cnt.ToString("00000"); dr["NewKey"] = cnt.ToString("00000"); dr["OldValue"] = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line; dr["NewValue"] = ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line; dr["Status"] = "Modify"; dr["CombinKey"] = cnt.ToString("00000"); dr["CombinValue"] = this.ModifyCheckBox.Checked ? ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line : ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line; dt.Rows.Add(dr); cnt++; } break; } } GridControl.AddButtonColumn(this.WsdlGrid, this.IsAddButtonWsdlColumn); this.WsdlGrid.DataSource = dt; this.IsAddButtonWsdlColumn = true; GridControl.SetGridDifferBackColor(this.WsdlGrid); GridControl.HideRow(this.WsdlGrid, this.UnchangedCheckBox, this.NoContainModifyCheckBox); GridControl.SetWsdlGridColumnWidth(this.WsdlGrid); if (this.WsdlGrid.CurrentCell != null) { this.ShowOldTextBox.Text = dt.Rows[this.WsdlGrid.CurrentCell.RowIndex]["OldValue"].ToString(); this.ShowNewTextBox.Text = dt.Rows[this.WsdlGrid.CurrentCell.RowIndex]["NewValue"].ToString(); } }
private void CompareFrom_Click(object sender, EventArgs e) { int typeIndex = this.FileTypeComBox.SelectedIndex; if (typeIndex != 3 && typeIndex != 4) { MessageBox.Show("请选择要对比文件类型", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string parentFileName = PathManager.GetParentFolderName(typeIndex); string compareFileName = PathManager.GetCompareFileName(typeIndex); string sFile = this.OldServiceWsdCmb.Text.Trim(); string dFile = this.NewServiceWsdCmb.Text.Trim(); if (sFile.Contains("{0}")) { sFile = string.Format(this.OldServiceWsdCmb.Text, this.ChangeSetTextBox.Text, this.CompanyComBox.Text, parentFileName, compareFileName); } if (dFile.Contains("{0}")) { dFile = string.Format(this.NewServiceWsdCmb.Text, parentFileName, parentFileName, compareFileName); } if (!PathManager.ValidFileExist(sFile) || !PathManager.ValidFileExist(dFile)) return; this.Cursor = Cursors.WaitCursor; DiffList_TextFile sLF = null; DiffList_TextFile dLF = null; try { sLF = new DiffList_TextFile(sFile); dLF = new DiffList_TextFile(dFile); } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(ex.Message, "File Error"); return; } try { double time = 0; DiffEngine de = new DiffEngine(); time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.FastImperfect); ArrayList rep = de.DiffReport(); Results dlg = new Results(sLF, dLF, rep); dlg.ShowDialog(); dlg.Dispose(); //this.BindData(sLF, dLF, rep); } catch (Exception ex) { this.Cursor = Cursors.Default; string tmp = string.Format("{0}{1}{1}***STACK***{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace); MessageBox.Show(tmp, "Compare Error"); return; } this.Cursor = Cursors.Default; }