private bool VerifyModified() { if (this.diffSource1.TableName != this.diffSource2.TableName) { return(true); } if (this.diffSource1.Tags != this.diffSource2.Tags) { return(true); } if (this.diffSource1.Comment != this.diffSource2.Comment) { return(true); } foreach (var item in this.diffSource1.Items) { if (DiffUtility.GetDiffState(item) != DiffState.Unchanged) { return(true); } } foreach (var item in this.diffSource2.Items) { if (DiffUtility.GetDiffState(item) != DiffState.Unchanged) { return(true); } } return(false); }
internal DiffTemplate(CremaDataTable diffTable1, CremaDataTable diffTable2, CremaDataTable dataTable1, CremaDataTable dataTable2) { this.diffTable1 = diffTable1.CloneTo(new CremaDataSet()); this.diffTable2 = diffTable2.CloneTo(new CremaDataSet()); foreach (var item in diffTable1.Columns) { var column = this.diffTable1.Columns[item.ColumnName]; DiffUtility.SetDiffState(column, DiffUtility.GetDiffState(item)); } foreach (var item in diffTable2.Columns) { var column = this.diffTable2.Columns[item.ColumnName]; DiffUtility.SetDiffState(column, DiffUtility.GetDiffState(item)); } this.dataTable1 = dataTable1; this.dataTable2 = dataTable2; this.diffSource1 = Create(this.diffTable1); this.diffSource2 = Create(this.diffTable2); this.diffSource1.ExtendedProperties[typeof(DiffTemplate)] = this; this.diffSource2.ExtendedProperties[typeof(DiffTemplate)] = this; this.dummy1 = this.diffSource1.TableName.StartsWith(DiffUtility.DiffDummyKey); this.dummy2 = this.diffSource2.TableName.StartsWith(DiffUtility.DiffDummyKey); this.AttachEventHandler(this.diffSource1, diffTable1); this.AttachEventHandler(this.diffSource2, diffTable2); }
internal static void SyncColumns(CremaDataTable diffTable1, CremaDataTable diffTable2, CremaDataTable dataTable1, CremaDataTable dataTable2) { var inlineBuilder = new SideBySideDiffBuilder(new Differ()); var columnText1 = dataTable1 == null ? string.Empty : GetString(dataTable1.Columns); var columnText2 = dataTable2 == null ? string.Empty : GetString(dataTable2.Columns); var columnDiff = inlineBuilder.BuildDiffModel(columnText1, columnText2); diffTable1.Clear(); diffTable2.Clear(); diffTable1.Columns.Clear(); diffTable2.Columns.Clear(); FillColumns(diffTable1, dataTable1, columnDiff.OldText.Lines); FillColumns(diffTable2, dataTable2, columnDiff.NewText.Lines); if (dataTable1 == null) { foreach (var item in diffTable1.Columns) { DiffUtility.SetDiffState(item, DiffState.Imaginary); } } if (dataTable2 == null) { foreach (var item in diffTable2.Columns) { DiffUtility.SetDiffState(item, DiffState.Imaginary); } } }
private static void FillColumns(CremaDataTable diffTable, CremaDataTable dataTable, List <DiffPiece> lines) { var index = 0; foreach (var item in lines) { var diffColumn = diffTable.Columns.Add(); if (item.Text != null && dataTable != null) { var dataColumn = dataTable.Columns[index]; diffColumn.ColumnName = dataColumn.ColumnName; diffColumn.CopyFrom(dataColumn); index++; } else { diffColumn.ColumnName = GenerateDummyName(); } DiffUtility.SetDiffState(diffColumn, (DiffState)item.Type); } string GenerateDummyName() { return(NameUtility.GenerateNewName(DiffUtility.DiffDummyKey, diffTable.Columns.Select(item => item.ColumnName))); } }
public static void DeleteItems(this CremaDataTable dataTable) { foreach (var item in dataTable.Rows.ToArray()) { if (DiffUtility.GetDiffState(item) == DiffState.Imaginary) { item.Delete(); } } }
private static void Update(DataRow dataRow1, DataRow dataRow2, DiffState defaultState) { if (dataRow2 == null || (bool)dataRow1[DiffUtility.DiffEnabledKey] == false) { DiffUtility.SetDiffFields(dataRow1, null); DiffUtility.SetDiffState(dataRow1, DiffState.Imaginary); } else { var fieldsList = new List <string>(dataRow1.Table.Columns.Count); var diffState = defaultState; foreach (var item in dataRow1.Table.Columns) { if (item is DataColumn column) { if (column.ColumnMapping == MappingType.Hidden) { continue; } var field1 = dataRow1[column.ColumnName]; var field2 = dataRow2[column.ColumnName]; if (object.Equals(field1, field2) == false) { fieldsList.Add(column.ColumnName); } } } if (object.Equals(dataRow1[CremaSchema.ID], dataRow2[CremaSchema.ID]) == true) { if (fieldsList.Any() == true || object.Equals(dataRow1[CremaSchema.Index], dataRow2[CremaSchema.Index]) == false) { diffState = DiffState.Modified; } else { diffState = DiffState.Unchanged; } DiffUtility.SetDiffFields(dataRow1, fieldsList); DiffUtility.SetDiffState(dataRow1, diffState); } else { DiffUtility.SetDiffFields(dataRow1, null); DiffUtility.SetDiffState(dataRow1, diffState); } } }
private void InitializeItems() { this.diffSource1.ColumnChanged -= DiffSource1_ColumnChanged; this.diffSource2.ColumnChanged -= DiffSource2_ColumnChanged; this.diffSource1.ColumnDeleted -= DiffSource1_ColumnDeleted; this.diffSource2.ColumnDeleted -= DiffSource2_ColumnDeleted; this.diffSource1.ReadOnly = false; this.diffSource2.ReadOnly = false; if (this.unresolvedItemList.Any() == false && (this.dataTable1 == null || this.dataTable2 == null)) { FillColumns(this.diffSource1, this.dataTable1 ?? this.dataTable2); FillColumns(this.diffSource2, this.dataTable2 ?? this.dataTable1); } else { FillColumns(this.diffSource1, this.diffTable1); FillColumns(this.diffSource2, this.diffTable2); } this.itemList.Clear(); this.itemList.Capacity = this.diffSource1.Items.Count; for (var i = 0; i < this.diffSource1.Items.Count; i++) { var item = new DiffTemplateColumn(this, i); this.itemList.Add(item); } for (var i = 0; i < this.itemList.Count; i++) { var item = this.itemList[i]; item.Update(); } this.diffSource1.AcceptChanges(); this.diffSource2.AcceptChanges(); this.diffSource1.ColumnChanged += DiffSource1_ColumnChanged; this.diffSource2.ColumnChanged += DiffSource2_ColumnChanged; this.diffSource1.ColumnDeleted += DiffSource1_ColumnDeleted; this.diffSource2.ColumnDeleted += DiffSource2_ColumnDeleted; void FillColumns(CremaTemplate template, CremaDataTable diffTable) { var index = 0; template.Columns.Clear(); foreach (var item in diffTable.Columns) { var templateColumn = template.NewColumn(); templateColumn.TargetColumn = item; if (DiffUtility.GetDiffState(item) != DiffState.Imaginary) { templateColumn.CopyFrom(item); templateColumn.SetAttribute(DiffUtility.DiffIDKey, item.ColumnID); } else { templateColumn.EmptyFields(); templateColumn.SetAttribute(DiffUtility.DiffEnabledKey, false); } templateColumn.Index = index++; template.Columns.Add(templateColumn); var diffState = DiffUtility.GetDiffState(item); templateColumn.SetDiffState(diffState); } } }
internal void SetState(DiffState state) { DiffUtility.SetDiffState(this.Item1, state); DiffUtility.SetDiffState(this.Item2, state); }
public static void SetDiffState(this CremaTemplateColumn templateColumn, DiffState diffState) { DiffUtility.SetDiffState(templateColumn, diffState); }
public static void SetDiffState(this CremaDataTypeMember typeMember, DiffState diffState) { DiffUtility.SetDiffState(typeMember, diffState); }
public static void SetDiffState(this CremaDataType dataType, DiffState diffState) { DiffUtility.SetDiffState(dataType, diffState); }
private static void Update(InternalDataRow dataRow1, InternalDataRow dataRow2, DiffState defaultState, string[] filters) { if (dataRow2 == null || (bool)dataRow1[DiffUtility.DiffEnabledKey] == false) { DiffUtility.SetDiffFields(dataRow1, null); DiffUtility.SetDiffState(dataRow1, DiffState.Imaginary); } else { var fieldsList = new List <string>(dataRow1.Table.Columns.Count); var diffState = defaultState; foreach (var item in dataRow1.Table.Columns) { if (item is InternalDataColumn dataColumn) { if (filters.Contains(dataColumn.ColumnName) == true) { continue; } var field1 = dataRow1[dataColumn.ColumnName]; var dataColumn2 = GetColumn(dataRow2, dataColumn.Index); var field2 = dataRow2[dataColumn2]; if (object.Equals(field1, field2) == false) { fieldsList.Add(dataColumn.ColumnName); } DiffDataTable.Validate((CremaDataRow)dataRow1, (CremaDataColumn)dataColumn); } else if (item is InternalAttribute attribute) { if (attribute.ColumnMapping == MappingType.Hidden || filters.Contains(attribute.AttributeName) == true) { continue; } var field1 = dataRow1[attribute.AttributeName]; var field2 = dataRow2[attribute.AttributeName]; if (object.Equals(field1, field2) == false) { fieldsList.Add(attribute.AttributeName); } } } if (dataRow1.GetColumnsInError().Any()) { dataRow1.RowError = rowError; } else { dataRow1.RowError = string.Empty; } if ((bool)dataRow2[DiffUtility.DiffEnabledKey] == true) { if (fieldsList.Any() == true || object.Equals(dataRow1[CremaSchema.Index], dataRow2[CremaSchema.Index]) == false) { diffState = DiffState.Modified; } else { diffState = DiffState.Unchanged; } DiffUtility.SetDiffFields(dataRow1, fieldsList); DiffUtility.SetDiffState(dataRow1, diffState); } else { DiffUtility.SetDiffFields(dataRow1, null); DiffUtility.SetDiffState(dataRow1, diffState); } } }