public Object ProcessWrite(IPostProcessWriter writer) { ISet <Object> substitutedEntities = writer.SubstitutedEntities; if (substitutedEntities.Count == 0) { return(null); } IDisposableCache childCache = CacheFactory.Create(CacheFactoryDirective.NoDCE, "XmlMerge"); IServiceContext mergeContext = BeanContext.CreateService(delegate(IBeanContextFactory childContextFactory) { childContextFactory.RegisterBean(typeof(MergeHandle)).Autowireable <MergeHandle>().PropertyValue("Cache", childCache); }); try { IDictionary <Object, Int32> mutableToIdMap = writer.MutableToIdMap; IObjRefHelper objRefHelper = ObjRefHelper; MergeHandle mergeHandle = mergeContext.GetService <MergeHandle>(); IList <Object> toMerge = new List <Object>(substitutedEntities.Count); foreach (Object entity in substitutedEntities) { toMerge.Add(entity); IObjRef ori = objRefHelper.EntityToObjRef(entity); mergeHandle.objToOriDict.Add(entity, ori); Int32 id = mutableToIdMap[entity]; mutableToIdMap.Add(ori, id); } ICUDResult cudResult = MergeController.MergeDeep(toMerge, mergeHandle); if (cudResult.AllChanges.Count != 0) { return(cudResult); } else { return(null); } } finally { mergeContext.Dispose(); } }
public void Test_DataChange() { TestEntity newTestEntity = EntityFactory.CreateEntity <TestEntity>(); CountDownLatch latch = new CountDownLatch(1); MergeProcess.Process(newTestEntity, null, null, delegate(bool success) { latch.CountDown(); }); latch.Await(); WaitForUI(); newTestEntity.Relation = EntityFactory.CreateEntity <TestEntity2>(); ICacheWalkerResult cwResult = CacheWalker.WalkEntities(newTestEntity); Log.Info(cwResult.ToString()); ICUDResult mergeResult = MergeController.MergeDeep(newTestEntity, new MergeHandle()); latch = new CountDownLatch(1); RevertChangesHelper.RevertChanges(newTestEntity, delegate(bool success) { latch.CountDown(); }); latch.Await(); WaitForUI(); ((IWritableCache)Cache).Put(newTestEntity); latch = new CountDownLatch(1); ((INotifyPropertyChanged)newTestEntity).PropertyChanged += delegate(Object sender, PropertyChangedEventArgs evnt) { latch.CountDown(); }; MergeService.Merge(mergeResult, null); latch.Await(); WaitForUI(); Assert.AssertNotNull(newTestEntity.Relation); }