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))); } }
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 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); } } }
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); } } }