Esempio n. 1
0
 public DiffState GetByIndex(int index)
 {
     DiffState retval = array[index];
     if (retval == null)
     {
         retval = new DiffState();
         array[index] = retval;
     }
     return retval;
 }
        /// <summary>
        /// The get by index.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// The <see cref="DiffState"/>.
        /// </returns>
        public DiffState GetByIndex(int index)
        {
            #if USE_HASH_TABLE
            DiffState retval = (DiffState)_table[index];
            if (retval == null)
            {
                retval = new DiffState();
                _table.Add(index, retval);
            }
            #else
            DiffState retval = this.array[index];
            if (retval == null)
            {
                retval = new DiffState();
                this.array[index] = retval;
            }

            #endif
            return retval;
        }
Esempio n. 3
0
    private void GetLongestSourceMatch(DiffState curItem, int destIndex, int destEnd, int sourceStart, int sourceEnd)
    {
        int maxDestLength = (destEnd - destIndex) + 1;
        int curLength     = 0;
        int curBestLength = 0;
        int curBestIndex  = -1;
        int maxLength     = 0;

        for (int sourceIndex = sourceStart; sourceIndex <= sourceEnd; sourceIndex++)
        {
            maxLength = Math.Min(maxDestLength, (sourceEnd - sourceIndex) + 1);
            if (maxLength <= curBestLength)
            {
                //No chance to find a longer one any more
                break;
            }
            curLength = GetSourceMatchLength(destIndex, sourceIndex, maxLength);
            if (curLength > curBestLength)
            {
                //This is the best match so far
                curBestIndex  = sourceIndex;
                curBestLength = curLength;
            }
            //jump over the match
            sourceIndex += curBestLength;
        }
        //DiffState cur = _stateList.GetByIndex(destIndex);
        if (curBestIndex == -1)
        {
            curItem.SetNoMatch();
        }
        else
        {
            curItem.SetMatch(curBestIndex, curBestLength);
        }
    }
Esempio n. 4
0
        private void ProcessRange(int destStart, int destEnd, int sourceStart, int sourceEnd)
        {
            var       curBestIndex          = -1;
            var       curBestLength         = -1;
            var       maxPossibleDestLength = 0;
            DiffState curItem  = null;
            DiffState bestItem = null;

            for (var destIndex = destStart; destIndex <= destEnd; destIndex++)
            {
                maxPossibleDestLength = destEnd - destIndex + 1;
                if (maxPossibleDestLength <= curBestLength)
                {
                    //we won't find a longer one even if we looked
                    break;
                }
                curItem = stateList.GetByIndex(destIndex);

                if (!curItem.HasValidLength(sourceStart, sourceEnd, maxPossibleDestLength))
                {
                    //recalc new best length since it isn't valid or has never been done.
                    GetLongestSourceMatch(curItem, destIndex, destEnd, sourceStart, sourceEnd);
                }
                if (curItem.Status == DiffStatus.Matched)
                {
                    switch (level)
                    {
                    case DiffEngineLevel.FastImperfect:
                        if (curItem.Length > curBestLength)
                        {
                            //this is longest match so far
                            curBestIndex  = destIndex;
                            curBestLength = curItem.Length;
                            bestItem      = curItem;
                        }

                        //Jump over the match
                        destIndex += curItem.Length - 1;
                        break;

                    case DiffEngineLevel.Medium:
                        if (curItem.Length > curBestLength)
                        {
                            //this is longest match so far
                            curBestIndex  = destIndex;
                            curBestLength = curItem.Length;
                            bestItem      = curItem;

                            //Jump over the match
                            destIndex += curItem.Length - 1;
                        }
                        break;

                    default:
                        if (curItem.Length > curBestLength)
                        {
                            //this is longest match so far
                            curBestIndex  = destIndex;
                            curBestLength = curItem.Length;
                            bestItem      = curItem;
                        }
                        break;
                    }
                }
            }
            if (curBestIndex < 0)
            {
                //we are done - there are no matches in this span
            }
            else
            {
                var sourceIndex = bestItem.StartIndex;
                matchList.Add(DiffResultSpan.CreateNoChange(curBestIndex, sourceIndex, curBestLength));
                if (destStart < curBestIndex)
                {
                    //Still have more lower destination data
                    if (sourceStart < sourceIndex)
                    {
                        //Still have more lower source data
                        // Recursive call to process lower indexes
                        ProcessRange(destStart, curBestIndex - 1, sourceStart, sourceIndex - 1);
                    }
                }
                var upperDestStart   = curBestIndex + curBestLength;
                var upperSourceStart = sourceIndex + curBestLength;
                if (destEnd > upperDestStart)
                {
                    //we still have more upper dest data
                    if (sourceEnd > upperSourceStart)
                    {
                        //set still have more upper source data
                        // Recursive call to process upper indexes
                        ProcessRange(upperDestStart, destEnd, upperSourceStart, sourceEnd);
                    }
                }
            }
        }
 private object GetDiffState(DiffState enumItem)
 {
     switch (enumItem)
     {
         case DiffState.Unknow:
             return Resources.DiffState_Unknow;
         case DiffState.NotChanged:
             return Resources.DiffState_NotChanged;
         case DiffState.Modified:
             return Resources.DiffState_Modified;
         case DiffState.Added:
             return Resources.DiffState_Added;
         case DiffState.Deleted:
             return Resources.DiffState_Deleted;
         default:
             return Resources.DiffState_Unknow;
     }
 }
Esempio n. 6
0
 internal void SetState(DiffState state)
 {
     DiffUtility.SetDiffState(this.Item1, state);
     DiffUtility.SetDiffState(this.Item2, state);
 }
Esempio n. 7
0
 internal static void SetDiffState(object item, DiffState state)
 {
     if (item is DataRowView dataRowView)
     {
         SetDiffState(dataRowView.Row, state);
     }
     else if (item is DataRow dataRow)
     {
         var omitSignatureDate = false;
         var readOnly          = false;
         var table             = dataRow.Table as InternalTableBase;
         if (table != null)
         {
             omitSignatureDate       = table.OmitSignatureDate;
             table.OmitSignatureDate = true;
             readOnly       = table.ReadOnly;
             table.ReadOnly = false;
         }
         var oldField = $"{dataRow[DiffStateKey]}";
         var newField = $"{state}";
         if (oldField != newField)
         {
             dataRow.SetField(DiffStateKey, newField);
         }
         if (table != null)
         {
             table.OmitSignatureDate = omitSignatureDate;
             table.ReadOnly          = readOnly;
         }
     }
     else if (item is DataColumn dataColumn)
     {
         dataColumn.ExtendedProperties[DiffStateKey] = $"{state}";
     }
     else if (item is DataTable dataTable)
     {
         dataTable.ExtendedProperties[DiffStateKey] = $"{state}";
     }
     else if (item is CremaDataRow cremaDataRow)
     {
         SetDiffState(cremaDataRow.InternalObject, state);
     }
     else if (item is CremaDataColumn cremaDataColumn)
     {
         SetDiffState(cremaDataColumn.InternalObject, state);
     }
     else if (item is CremaDataTypeMember cremaTypeMember)
     {
         SetDiffState(cremaTypeMember.InternalObject, state);
     }
     else if (item is CremaDataTable cremaDataTable)
     {
         SetDiffState(cremaDataTable.InternalObject, state);
     }
     else if (item is CremaDataType cremaDataType)
     {
         SetDiffState(cremaDataType.InternalObject, state);
     }
     else if (item is CremaTemplate cremaTemplate)
     {
         SetDiffState(cremaTemplate.InternalObject, state);
     }
     else if (item is CremaTemplateColumn cremaTemplateColumn)
     {
         SetDiffState(cremaTemplateColumn.InternalObject, state);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 8
0
 private void GetLongestSourceMatch(DiffState curItem, int destIndex, int destEnd, int sourceStart, int sourceEnd)
 {
     int maxDestLength = (destEnd - destIndex) + 1;
     int curBestLength = 0;
     int curBestIndex = -1;
     for (int sourceIndex = sourceStart; sourceIndex <= sourceEnd; sourceIndex++)
     {
         int maxLength = Math.Min(maxDestLength, (sourceEnd - sourceIndex) + 1);
         if (maxLength <= curBestLength)
         {
             //No chance to find a longer one any more
             break;
         }
         int curLength = GetSourceMatchLength(destIndex, sourceIndex, maxLength);
         if (curLength > curBestLength)
         {
             //This is the best match so far
             curBestIndex = sourceIndex;
             curBestLength = curLength;
         }
         //jump over the match
         sourceIndex += curBestLength;
     }
     //DiffState cur = _stateList.GetByIndex(destIndex);
     if (curBestIndex == -1)
     {
         curItem.SetNoMatch();
     }
     else
     {
         curItem.SetMatch(curBestIndex, curBestLength);
     }
 }
Esempio n. 9
0
 public DiffData(string text, DiffState state)
 {
     Text  = text;
     State = state;
 }
Esempio n. 10
0
 public static void SetDiffState(this CremaTemplateColumn templateColumn, DiffState diffState)
 {
     DiffUtility.SetDiffState(templateColumn, diffState);
 }
Esempio n. 11
0
 public static void SetDiffState(this CremaDataTypeMember typeMember, DiffState diffState)
 {
     DiffUtility.SetDiffState(typeMember, diffState);
 }
Esempio n. 12
0
 public static void SetDiffState(this CremaDataType dataType, DiffState diffState)
 {
     DiffUtility.SetDiffState(dataType, diffState);
 }
Esempio n. 13
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);
                }
            }
        }