Beispiel #1
0
        /// <summary>
        /// 根据对比差异分析变动实体
        /// </summary>
        /// <param name="difference"></param>
        /// <returns></returns>
        private ChangeEntry ResolveChangeEntry(Difference difference)
        {
            ChangeEntry change = new ChangeEntry();

            change.Type = this.ResolveChangeType(difference);
            if (change.Type == ChangeEntryType.Addition || change.Type == ChangeEntryType.Remove)
            {
                change.OriginalEntry = difference.Object1;
                change.NewestEntry   = difference.Object2;
            }
            else
            {
                change.OriginalEntry = difference.ParentObject1;
                change.NewestEntry   = difference.ParentObject2;
            }
            change.Navigation = difference.ParentPropertyName;
            return(change);
        }
Beispiel #2
0
 public void AddChanger(ChangeEntry change)
 {
     if (change.Type == ChangeEntryType.Remove)
     {
         this.DeleteEntry.Add(change);
     }
     else
     {
         var c = this.GetChanger(change.NewestEntry);
         if (c != null)
         {
             c = change;
         }
         else
         {
             this.ChangersEntry.Add(change.NewestEntry.GetHashCode(), change);
         }
     }
 }
Beispiel #3
0
        public IChangeManager Create(ComparisonResult comparisonResult)
        {
            changeManager.ClearChanger();
            if (comparisonResult.AreEqual)
            {
                return(changeManager);
            }

            //根据实体与快照的差异进行分析实体的变动
            foreach (var difference in comparisonResult.Differences)
            {
                ChangeEntry change = this.ResolveChangeEntry(difference);
                if (change.Type == ChangeEntryType.Addition || change.Type == ChangeEntryType.Remove)
                {
                    this.changeManager.AddChanger(change);
                    if (change.Type == ChangeEntryType.Addition)
                    {
                        //如果为新增类型,需要进一步分析实体中的值对象
                        var values = this.ResolveChangeObjectValue(change);
                        foreach (var item in values)
                        {
                            this.changeManager.AddChanger(item);
                        }
                    }
                }
                else
                {
                    var change2 = this.changeManager.GetChanger(change.NewestEntry);
                    if (change2 == null)
                    {
                        this.changeManager.AddChanger(change);
                        change2 = change;
                    }


                    //解析修改的字段
                    ChangeEntryPropertys changeProperty = this.ResolveChangeEntryPropertys(difference);
                    change2.ChangePropertys.Add(changeProperty);
                }
            }
            return(changeManager);
        }
Beispiel #4
0
        /// <summary>
        /// 分析变动实体中值对象
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        private List <ChangeEntry> ResolveChangeObjectValue(ChangeEntry entry)
        {
            var objectValues = entry.EntryType.GetProperties()
                               .Where(f => typeof(IValueObject).IsAssignableFrom(f.PropertyType))
                               .ToList();

            List <ChangeEntry> entries = new List <ChangeEntry>();

            foreach (var ov in objectValues)
            {
                var value = ov.GetValue(entry.NewestEntry);
                if (value == null)
                {
                    continue;
                }

                ChangeEntry change = new ChangeEntry();
                change.Type        = ChangeEntryType.Addition;
                change.NewestEntry = value;
                entries.Add(change);
            }
            return(entries);
        }