Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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)));
            }
        }
Ejemplo n.º 3
0
 public static void DeleteItems(this CremaDataTable dataTable)
 {
     foreach (var item in dataTable.Rows.ToArray())
     {
         if (DiffUtility.GetDiffState(item) == DiffState.Imaginary)
         {
             item.Delete();
         }
     }
 }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
0
 internal void SetState(DiffState state)
 {
     DiffUtility.SetDiffState(this.Item1, state);
     DiffUtility.SetDiffState(this.Item2, state);
 }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
 public static void SetDiffState(this CremaTemplateColumn templateColumn, DiffState diffState)
 {
     DiffUtility.SetDiffState(templateColumn, diffState);
 }
Ejemplo n.º 8
0
 public static void SetDiffState(this CremaDataTypeMember typeMember, DiffState diffState)
 {
     DiffUtility.SetDiffState(typeMember, diffState);
 }
Ejemplo n.º 9
0
 public static void SetDiffState(this CremaDataType dataType, DiffState diffState)
 {
     DiffUtility.SetDiffState(dataType, diffState);
 }