Ejemplo n.º 1
0
 // Methods
 internal ObjectChangeConflict(ChangeConflictSession session, TrackedObject trackedObject)
 {
     this.session       = session;
     this.trackedObject = trackedObject;
     original           = trackedObject.CreateDataCopy(trackedObject.Original);
 }
Ejemplo n.º 2
0
 internal ObjectChangeConflict(ChangeConflictSession session, TrackedObject trackedObject, bool isDeleted)
     : this(session, trackedObject)
 {
     this.isDeleted = isDeleted;
 }
Ejemplo n.º 3
0
        public void SubmitChanges(ConflictMode failureMode)
        {
            this.TrackUntrackedObjects();
            this.ApplyInferredDeletions();
            this.BuildEdgeMaps();
            List <TrackedObject> orderedList = this.GetOrderedList();

            //if (this.context.Mapping is DynamicModel)
            //{
            //    var model = (DynamicModel)context.Mapping;
            //    foreach (var item in orderedList)
            //    {
            //        model.UpdateBy(item.Current);
            //    }
            //}

            ValidateAll(orderedList);
            int totalUpdatesAttempted = 0;
            var session       = new ChangeConflictSession(this.context);
            var conflictList  = new List <ObjectChangeConflict>();
            var deletedItems  = new List <TrackedObject>();
            var insertedItems = new List <TrackedObject>();

            foreach (TrackedObject obj2 in orderedList)
            {
                try
                {
                    if (obj2.IsNew)
                    {
                        obj2.SynchDependentData();
                        this.changeDirector.Insert(obj2);
                        insertedItems.Add(obj2);

                        //Set DataContext
                        var entity = obj2.Current;
                        if (entity != null)
                        {
                            var mt = context.Mapping.GetMetaType(entity.GetType());
                            if (mt.HasAnySetDataContextMethod)
                            {
                                context.Services.SendSetDataContext(mt, entity, new object[] { context });
                            }
                        }
                    }
                    else if (obj2.IsDeleted)
                    {
                        totalUpdatesAttempted++;
                        if (changeDirector.Delete(obj2) == 0)
                        {
                            conflictList.Add(new ObjectChangeConflict(session, obj2, false));
                        }
                        else
                        {
                            deletedItems.Add(obj2);
                        }

                        #region Common Set DataContext
                        //Set DataContext
                        //var entity = obj2.Current;
                        //if (entity != null)
                        //{
                        //    var mt = context.Mapping.GetMetaType(entity.GetType());
                        //    if (mt.HasAnySetDataContextMethod)
                        //    {
                        //        context.Services.SendSetDataContext(mt, entity, new object[] { null });
                        //    }
                        //}
                        #endregion
                    }
                    else if (obj2.IsPossiblyModified)
                    {
                        obj2.SynchDependentData();
                        if (obj2.IsModified)
                        {
                            CheckForInvalidChanges(obj2);
                            totalUpdatesAttempted++;
                            if (changeDirector.Update(obj2) <= 0)
                            {
                                conflictList.Add(new ObjectChangeConflict(session, obj2));
                            }
                        }
                    }
                }
                catch (ChangeConflictException)
                {
                    conflictList.Add(new ObjectChangeConflict(session, obj2));
                }
                if ((conflictList.Count > 0) && (failureMode == ConflictMode.FailOnFirstConflict))
                {
                    break;
                }
            }
            if (conflictList.Count > 0)
            {
                this.context.ChangeConflicts.Fill(conflictList);
                //var bf = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod;
                //typeof(ChangeConflictCollection).InvokeMember("Fill", bf, null,
                //                                               context.ChangeConflicts, new object[] { conflictList });
                throw CreateChangeConflictException(totalUpdatesAttempted, conflictList.Count);
            }
            this.PostProcessUpdates(insertedItems, deletedItems);
        }